È possibile ottenere event dispatcher dal contenitore e dare un'occhiata agli eventi con getListeners
funzione. Esempio controller
$evd = $this->get('event_dispatcher');
$listeners = $evd->getListeners();
Descrizione
/**
* 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);
Attenzione, la dottrina ha il proprio dispatcher di eventi.
/** @var $em EntityManager */
$em = $this->getDoctrine()->getManager();
$evd = $em->getEventManager();
$listeners = $evd->getListeners();
fonte
2013-08-25 14:50:01
ho trovato abbastanza difficile ottenere le informazioni che volevo dalla matrice che ' getListeners' restituito (sf 2.3). Ho finito per scrivere quanto segue per analizzarlo: '' $ dispatcher = $ this-> get ('event_dispatcher'); foreach ($ dispatcher-> getListeners() come $ ascoltatori) {foreach ($ listener come $ listener); {foreach (listener as $ details) {if (gettype ($ details) == 'string') {echo "($ details)"; echo '
'; } else {echo get_class ($ details); }}}} '' – Sam