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
20 * @package Drupal\Console\Core\EventSubscriber
22 class CallCommandListener implements EventSubscriberInterface
27 protected $chainQueue;
30 * CallCommandListener constructor.
31 * @param ChainQueue $chainQueue
33 public function __construct(ChainQueue $chainQueue)
35 $this->chainQueue = $chainQueue;
39 * @param ConsoleTerminateEvent $event
41 public function callCommands(ConsoleTerminateEvent $event)
43 $command = $event->getCommand();
45 /* @var DrupalStyle $io */
46 $io = new DrupalStyle($event->getInput(), $event->getOutput());
48 if (!$command instanceof Command) {
52 $application = $command->getApplication();
53 $commands = $this->chainQueue->getCommands();
59 foreach ($commands as $chainedCommand) {
60 $callCommand = $application->find($chainedCommand['name']);
66 $input = new ArrayInput($chainedCommand['inputs']);
67 if (!is_null($chainedCommand['interactive'])) {
68 $input->setInteractive($chainedCommand['interactive']);
71 $io->text($chainedCommand['name']);
72 $callCommand->run($input, $io);
79 public static function getSubscribedEvents()
81 return [ConsoleEvents::TERMINATE => 'callCommands'];