1 | <?php |
||
10 | class SymfonyCommandExecutor implements ExecutorInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var Application |
||
14 | */ |
||
15 | private $app; |
||
16 | |||
17 | /** |
||
18 | * @param string $command |
||
19 | * @param OutputInterface|null $output |
||
20 | * |
||
21 | * @return int |
||
22 | */ |
||
23 | 3 | public function execute($command, OutputInterface $output = null) |
|
24 | { |
||
25 | 3 | $input = new StringInput($command); |
|
26 | |||
27 | 3 | $exitCode = $this->app->run($input, $output); |
|
28 | |||
29 | 3 | if ($exitCode != 0) { |
|
30 | 1 | throw new \RuntimeException( |
|
31 | 1 | sprintf('Command `%s` failed.', $command) |
|
32 | ); |
||
33 | } |
||
34 | |||
35 | 3 | return $exitCode; |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param ConsoleCommandEvent $event |
||
40 | */ |
||
41 | 10 | public function onConsoleCommand(ConsoleCommandEvent $event) |
|
42 | { |
||
43 | 10 | $this->app = clone $event->getCommand()->getApplication(); |
|
44 | 10 | $this->app->setAutoExit(false); |
|
45 | 10 | } |
|
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | 4 | public function getName() |
|
54 | } |
||
55 |