1 | <?php |
||
20 | class PHPChunkitApplication |
||
21 | { |
||
22 | /** |
||
23 | * @var Container |
||
24 | */ |
||
25 | private $container; |
||
26 | |||
27 | /** |
||
28 | * @var Application |
||
29 | */ |
||
30 | private $symfonyApplication; |
||
31 | |||
32 | private static $commands = [ |
||
33 | 'phpchunkit.command.setup', |
||
34 | 'phpchunkit.command.build_sandbox', |
||
35 | 'phpchunkit.command.create_databases', |
||
36 | 'phpchunkit.command.test_watcher', |
||
37 | 'phpchunkit.command.run', |
||
38 | 'phpchunkit.command.generate_test', |
||
39 | ]; |
||
40 | |||
41 | 1 | public function __construct(Container $container) |
|
47 | |||
48 | 1 | public function run(InputInterface $input, OutputInterface $output) : int |
|
59 | |||
60 | 1 | public function registerCommand(string $serviceName) |
|
61 | { |
||
62 | 1 | $service = $this->container[$serviceName]; |
|
63 | |||
64 | 1 | $symfonyCommand = $this->register($service->getName()); |
|
65 | |||
66 | 1 | $service->configure($symfonyCommand); |
|
67 | |||
68 | 1 | $symfonyCommand->setCode(function($input, $output) use ($service) { |
|
69 | if (!$service instanceof Command\Setup) { |
||
70 | $configuration = $this->container['phpchunkit.configuration']; |
||
71 | |||
72 | if (!$configuration->isSetup()) { |
||
73 | return $this->symfonyApplication |
||
74 | ->find('setup')->run($input, $output); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | return call_user_func_array([$service, 'execute'], [$input, $output]); |
||
79 | 1 | }); |
|
80 | 1 | } |
|
81 | |||
82 | protected function runSymfonyApplication( |
||
88 | |||
89 | 1 | private function register(string $name) : SymfonyCommand |
|
93 | } |
||
94 |