-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCliProvider.php
More file actions
79 lines (68 loc) · 3.36 KB
/
Copy pathCliProvider.php
File metadata and controls
79 lines (68 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php declare(strict_types=1);
namespace StellarWP\Foundation\Cli;
use lucatume\DI52\Container;
use StellarWP\Foundation\Cli\Commands\Make\WPCliCommand;
use StellarWP\Foundation\Cli\Commands\Package\Contracts\PackageRepositoryCreator;
use StellarWP\Foundation\Cli\Commands\Package\CreateCommand;
use StellarWP\Foundation\Cli\Commands\Package\GitHubPackageRepositoryCreator;
use StellarWP\Foundation\Cli\Commands\Package\PackageFilesValidator;
use StellarWP\Foundation\Cli\Commands\Package\PackageRepositoryPlanFactory;
use StellarWP\Foundation\Cli\Commands\Package\PackageResolver;
use StellarWP\Foundation\Cli\Commands\Package\PackageScaffolder;
use StellarWP\Foundation\Cli\Generation\ComposerAutoloadResolver;
use StellarWP\Foundation\Cli\Generation\GeneratedFileWriter;
use StellarWP\Foundation\Cli\Generation\StubRenderer;
use StellarWP\Foundation\Cli\Generation\StubResolver;
use StellarWP\Foundation\Cli\Generation\WordPressClassNameResolver;
use StellarWP\Foundation\Cli\Process\Contracts\ProcessRunner;
use StellarWP\Foundation\Cli\Process\ShellProcessRunner;
use StellarWP\Foundation\Container\Contracts\Provider;
/**
* Registers the default Foundation CLI application and command dependencies.
*
* Include this provider when booting the `foundation` executable so command
* slices can be autowired through the Foundation container.
*/
final class CliProvider extends Provider
{
public const string ROOT_PATH = 'foundation.cli.root_path';
public function register(): void {
$this->container->singleton(self::ROOT_PATH, getcwd() ?: dirname(__DIR__, 2));
$this->container->when(PackageResolver::class)
->needs('$rootPath')
->give(static fn (Container $c): string => $c->get(self::ROOT_PATH));
$this->container->when(PackageScaffolder::class)
->needs('$rootPath')
->give(static fn (Container $c): string => $c->get(self::ROOT_PATH));
$this->container->when(ComposerAutoloadResolver::class)
->needs('$rootPath')
->give(static fn (Container $c): string => $c->get(self::ROOT_PATH));
$this->container->when(StubResolver::class)
->needs('$rootPath')
->give(static fn (Container $c): string => $c->get(self::ROOT_PATH));
$this->container->when(WPCliCommand::class)
->needs('$rootPath')
->give(static fn (Container $c): string => $c->get(self::ROOT_PATH));
$this->container->when(Application::class)
->needs('$commands')
->give(static fn (Container $c): array => [
$c->get(CreateCommand::class),
$c->get(WPCliCommand::class),
]);
$this->container->singleton(PackageResolver::class);
$this->container->singleton(PackageScaffolder::class);
$this->container->singleton(PackageFilesValidator::class);
$this->container->singleton(PackageRepositoryPlanFactory::class);
$this->container->singleton(ShellProcessRunner::class);
$this->container->bind(ProcessRunner::class, ShellProcessRunner::class);
$this->container->bind(PackageRepositoryCreator::class, GitHubPackageRepositoryCreator::class);
$this->container->singleton(CreateCommand::class);
$this->container->singleton(WordPressClassNameResolver::class);
$this->container->singleton(ComposerAutoloadResolver::class);
$this->container->singleton(GeneratedFileWriter::class);
$this->container->singleton(StubRenderer::class);
$this->container->singleton(StubResolver::class);
$this->container->singleton(WPCliCommand::class);
$this->container->singleton(Application::class);
}
}