|
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\InputDefinition; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Zalas\Toolbox\Cli\Command\InstallCommand; |
|
14
|
|
|
use Zalas\Toolbox\Cli\Command\ListCommand; |
|
15
|
|
|
use Zalas\Toolbox\Cli\Command\TestCommand; |
|
16
|
|
|
|
|
17
|
|
|
final class Application extends CliApplication |
|
18
|
|
|
{ |
|
19
|
|
|
private ServiceContainer $serviceContainer; |
|
20
|
|
|
|
|
21
|
36 |
|
public function __construct(string $version, ServiceContainer $serviceContainer) |
|
22
|
|
|
{ |
|
23
|
36 |
|
parent::__construct('toolbox', $version); |
|
24
|
|
|
|
|
25
|
36 |
|
$this->serviceContainer = $serviceContainer; |
|
26
|
|
|
|
|
27
|
36 |
|
$this->setCommandLoader($this->createCommandLoader($serviceContainer)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @throws \Throwable |
|
32
|
|
|
*/ |
|
33
|
2 |
|
public function doRun(InputInterface $input, OutputInterface $output): int |
|
34
|
|
|
{ |
|
35
|
2 |
|
$this->serviceContainer->set(InputInterface::class, $input); |
|
36
|
2 |
|
$this->serviceContainer->set(OutputInterface::class, $output); |
|
37
|
|
|
|
|
38
|
2 |
|
return parent::doRun($input, $output); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
13 |
|
protected function getDefaultInputDefinition(): InputDefinition |
|
42
|
|
|
{ |
|
43
|
13 |
|
$definition = parent::getDefaultInputDefinition(); |
|
44
|
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())); |
|
45
|
|
|
|
|
46
|
13 |
|
return $definition; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
13 |
|
private function toolsJsonDefault(): array |
|
50
|
|
|
{ |
|
51
|
13 |
|
return \getenv('TOOLBOX_JSON') |
|
52
|
2 |
|
? \array_map('trim', \explode(',', \getenv('TOOLBOX_JSON'))) |
|
53
|
13 |
|
: [ |
|
54
|
13 |
|
__DIR__.'/../../resources/pre-installation.json', |
|
55
|
13 |
|
__DIR__.'/../../resources/architecture.json', |
|
56
|
13 |
|
__DIR__.'/../../resources/checkstyle.json', |
|
57
|
13 |
|
__DIR__.'/../../resources/compatibility.json', |
|
58
|
13 |
|
__DIR__.'/../../resources/composer.json', |
|
59
|
13 |
|
__DIR__.'/../../resources/deprecation.json', |
|
60
|
13 |
|
__DIR__.'/../../resources/documentation.json', |
|
61
|
13 |
|
__DIR__.'/../../resources/linting.json', |
|
62
|
13 |
|
__DIR__.'/../../resources/metrics.json', |
|
63
|
13 |
|
__DIR__.'/../../resources/phpcs.json', |
|
64
|
13 |
|
__DIR__.'/../../resources/phpstan.json', |
|
65
|
13 |
|
__DIR__.'/../../resources/psalm.json', |
|
66
|
13 |
|
__DIR__.'/../../resources/refactoring.json', |
|
67
|
13 |
|
__DIR__.'/../../resources/security.json', |
|
68
|
13 |
|
__DIR__.'/../../resources/test.json', |
|
69
|
13 |
|
__DIR__.'/../../resources/tools.json', |
|
70
|
13 |
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
36 |
|
private function createCommandLoader(ContainerInterface $container): CommandLoaderInterface |
|
74
|
|
|
{ |
|
75
|
36 |
|
return new ContainerCommandLoader( |
|
76
|
36 |
|
$container, |
|
77
|
36 |
|
[ |
|
78
|
36 |
|
InstallCommand::NAME => InstallCommand::class, |
|
79
|
36 |
|
ListCommand::NAME => ListCommand::class, |
|
80
|
36 |
|
TestCommand::NAME => TestCommand::class, |
|
81
|
36 |
|
] |
|
82
|
36 |
|
); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|