5 * Contains \Drupal\Console\Core\EventSubscriber\ShowGenerateChainListener.
8 namespace Drupal\Console\Core\EventSubscriber;
10 use Symfony\Component\Console\ConsoleEvents;
11 use Symfony\Component\Console\Event\ConsoleTerminateEvent;
12 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13 use Symfony\Component\Yaml\Dumper;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Utils\TranslatorManagerInterface;
16 use Drupal\Console\Core\Style\DrupalStyle;
19 * Class ShowGenerateChainListener
21 * @package Drupal\Console\Core\EventSubscriber
23 class ShowGenerateChainListener implements EventSubscriberInterface
26 * @var TranslatorManagerInterface
28 protected $translator;
33 private $skipCommands = [
43 private $skipOptions = [
52 private $skipArguments = [
58 * ShowGenerateChainListener constructor.
60 * @param TranslatorManagerInterface $translator
62 public function __construct(
63 TranslatorManagerInterface $translator
65 $this->translator = $translator;
69 * @param ConsoleTerminateEvent $event
71 public function showGenerateChain(ConsoleTerminateEvent $event)
73 if ($event->getExitCode() != 0) {
77 /* @var Command $command */
78 $command = $event->getCommand();
79 /* @var DrupalStyle $io */
80 $io = new DrupalStyle($event->getInput(), $event->getOutput());
82 $command_name = $command->getName();
84 $this->skipArguments[] = $command_name;
86 if (in_array($command->getName(), $this->skipCommands)) {
90 $input = $event->getInput();
92 if ($input->getOption('generate-chain')) {
93 $options = array_filter($input->getOptions());
94 foreach ($this->skipOptions as $remove_option) {
95 unset($options[$remove_option]);
98 $arguments = array_filter($input->getArguments());
99 foreach ($this->skipArguments as $remove_argument) {
100 unset($arguments[$remove_argument]);
103 $commandData['command'] = $command_name;
106 $commandData['options'] = $options;
110 $commandData['arguments'] = $arguments;
114 $this->translator->trans('application.messages.chain.generated')
117 $dumper = new Dumper();
120 $dumper->dump($commandData, 4)
123 $io->writeln('commands:');
124 $io->table([], [$tableRows], 'compact');
131 public static function getSubscribedEvents()
133 return [ConsoleEvents::TERMINATE => 'showGenerateChain'];