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 Symfony\Component\Yaml\Yaml;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Core\Style\DrupalStyle;
19 * Class EventDebugCommand
21 * @package Drupal\Console\Command
23 class EventDebugCommand extends Command
27 protected $eventDispatcher;
30 * EventDebugCommand constructor.
32 * @param $eventDispatcher
34 public function __construct($eventDispatcher)
36 $this->eventDispatcher = $eventDispatcher;
37 parent::__construct();
43 protected function configure()
46 ->setName('event:debug')
47 ->setDescription($this->trans('commands.event.debug.description'))
50 InputArgument::OPTIONAL,
51 $this->trans('commands.event.debug.arguments.event'),
54 ->setHelp($this->trans('commands.event.debug.help'));
60 protected function execute(InputInterface $input, OutputInterface $output)
62 $io = new DrupalStyle($input, $output);
64 $events = array_keys($this->eventDispatcher->getListeners());
65 $event = $input->getArgument('event');
68 if (!in_array($event, $events)) {
71 $this->trans('commands.event.debug.messages.no-events'),
77 $dispatcher = $this->eventDispatcher->getListeners($event);
80 foreach ($dispatcher as $key => $value) {
81 $reflection = new \ReflectionClass(get_class($value[0]));
82 $className = $reflection->getName();
84 if (!$reflection->hasMethod('getSubscribedEvents')) {
85 $reflection = new \ReflectionClass($reflection->getParentClass());
88 $eventObject = $reflection->newInstanceWithoutConstructor();
89 $reflectionMethod = new \ReflectionMethod(
90 $reflection->getName(),
94 $subscribedEvents = $reflectionMethod->invoke(
98 if (!is_array($subscribedEvents[$event])) {
99 $subscribedEvents[$event] = [$subscribedEvents[$event]];
102 $subscribedEventData = [];
103 foreach ($subscribedEvents[$event] as $subscribedEvent) {
104 if (!is_array($subscribedEvent)) {
105 $subscribedEvent = [$subscribedEvent, 0];
107 if ($subscribedEvent[0] == $value[1]) {
108 $subscribedEventData = [
109 $subscribedEvent[0] => isset($subscribedEvent[1])?$subscribedEvent[1]:0
115 'class' => $className,
116 'method' => $value[1],
117 'events' => Yaml::dump($subscribedEventData, 4, 2)
122 $this->trans('commands.event.debug.messages.class'),
123 $this->trans('commands.event.debug.messages.method'),
127 foreach ($listeners as $key => $element) {
129 'class' => $element['class'],
130 'events' => $element['events']
134 $io->table($tableHeader, $tableRows);
140 [$this->trans('commands.event.debug.messages.event')],