Warning: You are browsing the documentation for Symfony 2.5, which is no longer maintained.
Read the updated version of this page for Symfony 6.0 (the current stable version).
New in version 2.5
TraceableEventDispatcher class was moved to the EventDispatcher
component in Symfony 2.5. Before, it was located in the HttpKernel component.
The TraceableEventDispatcher is an event dispatcher that wraps any other event dispatcher and can then be used to determine which event listeners have been called by the dispatcher. Pass the event dispatcher to be wrapped and an instance of the Stopwatch to its constructor:
1 2 3 4 5 6 7 8 9 10
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; use Symfony\Component\Stopwatch\Stopwatch; // the event dispatcher to debug $eventDispatcher = ...; $traceableEventDispatcher = new TraceableEventDispatcher( $eventDispatcher, new Stopwatch() );
TraceableEventDispatcher can be used like any other event dispatcher
to register event listeners and dispatch events:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// ... // register an event listener $eventListener = ...; $priority = ...; $traceableEventDispatcher->addListener( 'event.the_name', $eventListener, $priority ); // dispatch an event $event = ...; $traceableEventDispatcher->dispatch('event.the_name', $event);
After your application has been processed, you can use the getCalledListeners() method to retrieve an array of event listeners that have been called in your application. Similarly, the getNotCalledListeners() method returns an array of event listeners that have not been called:
1 2 3 4
// ... $calledListeners = $traceableEventDispatcher->getCalledListeners(); $notCalledListeners = $traceableEventDispatcher->getNotCalledListeners();