5 * Contains \Drupal\Console\Command\EventDebugCommand.
8 namespace Drupal\Console\Command;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Console\Core\Style\DrupalStyle;
18 * Class EventDebugCommand
20 * @package Drupal\Console\Command
22 class EventDebugCommand extends Command
26 protected $eventDispatcher;
29 * EventDebugCommand constructor.
31 * @param $eventDispatcher
33 public function __construct($eventDispatcher)
35 $this->eventDispatcher = $eventDispatcher;
36 parent::__construct();
42 protected function configure()
45 ->setName('event:debug')
46 ->setDescription($this->trans('commands.event.debug.description'))
49 InputArgument::OPTIONAL,
50 $this->trans('commands.event.debug.arguments.event'),
53 ->setHelp($this->trans('commands.event.debug.help'));
59 protected function execute(InputInterface $input, OutputInterface $output)
61 $io = new DrupalStyle($input, $output);
63 $events = array_keys($this->eventDispatcher->getListeners());
64 $event = $input->getArgument('event');
67 if (!in_array($event, $events)) {
70 $this->trans('commands.event.debug.messages.no-events'),
76 $dispatcher = $this->eventDispatcher->getListeners($event);
79 foreach ($dispatcher as $key => $value) {
80 $reflection = new \ReflectionClass(get_class($value[0]));
81 $listeners[] = [$reflection->getName(), $value[1]];
85 $this->trans('commands.event.debug.messages.class'),
86 $this->trans('commands.event.debug.messages.method'),
91 foreach ($listeners as $key => $element) {
93 'class' => $element['0'],
94 'method' => $element['1']
98 $io->table($tableHeader, $tableRows);
104 [$this->trans('commands.event.debug.messages.event')],