1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Zalas\Toolbox\Cli; |
4
|
|
|
|
5
|
|
|
use Psr\Container\ContainerInterface; |
6
|
|
|
use Symfony\Component\Console\Application as CliApplication; |
7
|
|
|
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; |
8
|
|
|
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Zalas\Toolbox\Cli\Command\InstallCommand; |
13
|
|
|
use Zalas\Toolbox\Cli\Command\ListCommand; |
14
|
|
|
use Zalas\Toolbox\Cli\Command\TestCommand; |
15
|
|
|
|
16
|
|
|
final class Application extends CliApplication |
17
|
|
|
{ |
18
|
|
|
private $serviceContainer; |
19
|
|
|
|
20
|
36 |
|
public function __construct(string $version, ServiceContainer $serviceContainer) |
21
|
|
|
{ |
22
|
36 |
|
parent::__construct('toolbox', $version); |
23
|
|
|
|
24
|
36 |
|
$this->serviceContainer = $serviceContainer; |
25
|
|
|
|
26
|
36 |
|
$this->setCommandLoader($this->createCommandLoader($serviceContainer)); |
27
|
|
|
} |
28
|
|
|
|
29
|
2 |
|
public function doRun(InputInterface $input, OutputInterface $output) |
30
|
|
|
{ |
31
|
2 |
|
$this->serviceContainer->set(InputInterface::class, $input); |
32
|
2 |
|
$this->serviceContainer->set(OutputInterface::class, $output); |
33
|
|
|
|
34
|
2 |
|
return parent::doRun($input, $output); |
35
|
|
|
} |
36
|
|
|
|
37
|
13 |
|
protected function getDefaultInputDefinition() |
38
|
|
|
{ |
39
|
13 |
|
$definition = parent::getDefaultInputDefinition(); |
40
|
13 |
|
$definition->addOption(new InputOption('tools', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Path(s) to the list of tools. Can also be set with TOOLBOX_JSON environment variable.', $this->toolsJsonDefault())); |
41
|
|
|
|
42
|
13 |
|
return $definition; |
43
|
|
|
} |
44
|
|
|
|
45
|
13 |
|
private function toolsJsonDefault(): array |
46
|
|
|
{ |
47
|
13 |
|
return \getenv('TOOLBOX_JSON') |
48
|
2 |
|
? \array_map('trim', \explode(',', \getenv('TOOLBOX_JSON'))) |
49
|
|
|
: [ |
50
|
13 |
|
__DIR__.'/../../resources/pre-installation.json', |
51
|
|
|
__DIR__.'/../../resources/architecture.json', |
52
|
|
|
__DIR__.'/../../resources/checkstyle.json', |
53
|
|
|
__DIR__.'/../../resources/compatibility.json', |
54
|
|
|
__DIR__.'/../../resources/composer.json', |
55
|
|
|
__DIR__.'/../../resources/deprecation.json', |
56
|
|
|
__DIR__.'/../../resources/documentation.json', |
57
|
|
|
__DIR__.'/../../resources/linting.json', |
58
|
|
|
__DIR__.'/../../resources/metrics.json', |
59
|
|
|
__DIR__.'/../../resources/phpcs.json', |
60
|
|
|
__DIR__.'/../../resources/phpstan.json', |
61
|
|
|
__DIR__.'/../../resources/psalm.json', |
62
|
|
|
__DIR__.'/../../resources/refactoring.json', |
63
|
|
|
__DIR__.'/../../resources/security.json', |
64
|
|
|
__DIR__.'/../../resources/test.json', |
65
|
|
|
__DIR__.'/../../resources/tools.json', |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
36 |
|
private function createCommandLoader(ContainerInterface $container): CommandLoaderInterface |
70
|
|
|
{ |
71
|
36 |
|
return new ContainerCommandLoader( |
72
|
36 |
|
$container, |
73
|
|
|
[ |
74
|
36 |
|
InstallCommand::NAME => InstallCommand::class, |
75
|
|
|
ListCommand::NAME => ListCommand::class, |
76
|
|
|
TestCommand::NAME => TestCommand::class, |
77
|
|
|
] |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|