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 = [
53 private $skipArguments = [
59 * ShowGenerateChainListener constructor.
61 * @param TranslatorManagerInterface $translator
63 public function __construct(
64 TranslatorManagerInterface $translator
66 $this->translator = $translator;
70 * @param ConsoleTerminateEvent $event
72 public function showGenerateChain(ConsoleTerminateEvent $event)
74 if ($event->getExitCode() != 0) {
78 /* @var Command $command */
79 $command = $event->getCommand();
80 /* @var DrupalStyle $io */
81 $io = new DrupalStyle($event->getInput(), $event->getOutput());
83 $command_name = $command->getName();
85 $this->skipArguments[] = $command_name;
87 if (in_array($command->getName(), $this->skipCommands)) {
91 $input = $event->getInput();
93 if ($input->getOption('generate-chain')) {
94 $options = array_filter($input->getOptions());
95 foreach ($this->skipOptions as $remove_option) {
96 unset($options[$remove_option]);
99 $arguments = array_filter($input->getArguments());
100 foreach ($this->skipArguments as $remove_argument) {
101 unset($arguments[$remove_argument]);
104 $commandData['command'] = $command_name;
107 $commandData['options'] = $options;
111 $commandData['arguments'] = $arguments;
115 $this->translator->trans('application.messages.chain.generated')
118 $dumper = new Dumper();
121 $dumper->dump($commandData, 4)
124 $io->writeln('commands:');
125 $io->table([], [$tableRows], 'compact');
132 public static function getSubscribedEvents()
134 return [ConsoleEvents::TERMINATE => 'showGenerateChain'];