Listing with all listeners on Symfony2

I would like to receive a list with each listener registered in my application, as well as their priority. This list should contain my own listeners and listeners who also registered the Symfony core or other related packages.

Is it possible?

thanks

+8
php listener symfony
source share
2 answers

You can get the event manager from the container and see the events with the getListeners function. An example in the controller

 $evd = $this->get('event_dispatcher'); $listeners = $evd->getListeners(); 

Description

 /** * Gets the listeners of a specific event or all listeners. * * @param string $eventName The name of the event * * @return array The event listeners for the specified event, or all event listeners by event name */ public function getListeners($eventName = null); 

Be careful, the doctrine has its own event dispatcher.

 /** @var $em EntityManager */ $em = $this->getDoctrine()->getManager(); $evd = $em->getEventManager(); $listeners = $evd->getListeners(); 
+6
source share

If you do not want to write code to display it on your website, you can simply use the CLI:

 php app/console debug:event-dispatcher 
+5
source share

All Articles