Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list with every listeners on Symfony2

I would like to get a list with every listeners registered on my applicacion as well as their priority. That list should contain my own listeners and the listeners that Symfony core or other enabled bundles have registered as well.

Is that possible?

Thanks

like image 289
alvaro.rmfg Avatar asked Aug 25 '13 11:08

alvaro.rmfg


2 Answers

If you don't want to write code to display it on your website you can just use CLI:

php app/console debug:event-dispatcher
like image 128
Scott Flack Avatar answered Oct 26 '22 15:10

Scott Flack


You can get event dispatcher from container and take a look at events with getListeners function. Example in 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, doctrine has own event dispatcher.

/** @var $em EntityManager */
$em = $this->getDoctrine()->getManager();
$evd = $em->getEventManager();
$listeners = $evd->getListeners();
like image 31
Alexey B. Avatar answered Oct 26 '22 16:10

Alexey B.