5 * Contains \Drupal\Console\Core\EventSubscriber\CallCommandListener.
8 namespace Drupal\Console\Core\EventSubscriber;
10 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11 use Symfony\Component\Console\Event\ConsoleTerminateEvent;
12 use Symfony\Component\Console\Input\ArrayInput;
13 use Symfony\Component\Console\ConsoleEvents;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Utils\ChainQueue;
16 use Drupal\Console\Core\Style\DrupalStyle;
19 * Class CallCommandListener
21 * @package Drupal\Console\Core\EventSubscriber
23 class CallCommandListener implements EventSubscriberInterface
28 protected $chainQueue;
31 * CallCommandListener constructor.
33 * @param ChainQueue $chainQueue
35 public function __construct(ChainQueue $chainQueue)
37 $this->chainQueue = $chainQueue;
41 * @param ConsoleTerminateEvent $event
43 public function callCommands(ConsoleTerminateEvent $event)
45 $command = $event->getCommand();
47 /* @var DrupalStyle $io */
48 $io = new DrupalStyle($event->getInput(), $event->getOutput());
50 if (!$command instanceof Command) {
54 $application = $command->getApplication();
55 $commands = $this->chainQueue->getCommands();
61 foreach ($commands as $chainedCommand) {
62 $callCommand = $application->find($chainedCommand['name']);
68 $input = new ArrayInput($chainedCommand['inputs']);
69 if (!is_null($chainedCommand['interactive'])) {
70 $input->setInteractive($chainedCommand['interactive']);
73 $io->text($chainedCommand['name']);
74 $allowFailure = array_key_exists('allow_failure', $chainedCommand)?$chainedCommand['allow_failure']:false;
76 $callCommand->run($input, $io);
77 } catch (\Exception $e) {
79 $io->error($e->getMessage());
89 public static function getSubscribedEvents()
91 return [ConsoleEvents::TERMINATE => 'callCommands'];