From a5628bdbe2fdb8267242678991f30b37edfd4b69 Mon Sep 17 00:00:00 2001 From: Matthieu Auger Date: Mon, 13 Oct 2014 00:36:35 +0200 Subject: [PATCH] Displays friendly message if the event does not have any registered listeners --- .../Command/EventDispatcherDebugCommand.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php index dff1c3d28fc5..f5cbd96d9eb7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php @@ -58,14 +58,28 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $dispatcher = $this->getEventDispatcher(); + if ($event = $input->getArgument('event')) { + if (!$dispatcher->hasListeners($event)) { + $formatter = $this->getHelperSet()->get('formatter'); + + $formattedBlock = $formatter->formatBlock( + sprintf('[NOTE] The event "%s" does not have any registered listeners.', $event), + 'fg=yellow', + true + ); + + $output->writeln($formattedBlock); + + return; + } + $options = array('event' => $event); } else { $options = array(); } - $dispatcher = $this->getEventDispatcher(); - $helper = new DescriptorHelper(); $options['format'] = $input->getOption('format'); $options['raw_text'] = $input->getOption('raw');