diff --git a/src/Command/ListEventsCommand.php b/src/Command/ListEventsCommand.php new file mode 100644 index 0000000000..66d4336b38 --- /dev/null +++ b/src/Command/ListEventsCommand.php @@ -0,0 +1,53 @@ +dispatcher = $dispatcher; + } + + protected function configure() + { + $this->setDefinition([new InputArgument('pattern', + InputArgument::OPTIONAL, + 'An event pattern to look for')]) + ->setDescription('Search for an event'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $options = []; + $patterm = $input->getArgument('pattern') ?? 'GNUsocial.*'; + $listeners = $this->dispatcher->getListeners(); + $listeners = F\select($listeners, + function ($_, $key, $__) use ($patterm) { + return preg_match('/' . $patterm . '/', $key); + }); + + foreach ($listeners as $event => $listener) { + echo 'Event \'' . $event . "\\' handled by:\n"; + foreach ($listener as $c) { + $r = new \ReflectionFunction($c); + echo ' ' . get_class($r->getStaticVariables()['handler'][0]) . "\n"; + } + } + return 0; + } +}