Skip to content

Commit

Permalink
add documentation for the TraceableEventDispatcher class
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jun 7, 2014
1 parent b00573c commit 1160f7c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/event_dispatcher/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ EventDispatcher
container_aware_dispatcher
generic_event
immutable_dispatcher
traceable_dispatcher
46 changes: 46 additions & 0 deletions components/event_dispatcher/traceable_dispatcher.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.. index::
single: EventDispatcher; Debug
single: EventDispatcher; Traceable

The Traceable Event Dispatcher
==============================

The :class:`Symfony\\Component\\HttpKernel\\Debug\\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
:class:`Symfony\\Component\\Stopwatch\\Stopwatch` to its constructor::

use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
use Symfony\Component\Stopwatch\Stopwatch;

// the event dispatcher to debug
$eventDispatcher = ...;

$traceableEventDispatcher = new TraceableEventDispatcher($eventDispatcher, new Stopwatch());

Now, the ``TraceableEventDispatcher`` can be used like any other event dispatcher
to register event listeners and dispatch events::

// ...

// register an event listener
$eventListener = ...;
$priority = ...;
$traceableEventDispatcher->addListener('the-event-name', $eventListener, $priority);

// dispatch an event
$event = ...;
$traceableEventDispatcher->dispatch('the-event-name', $event);

After your application has been processed, you can use the
:method:`Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcherInterface::getCalledListeners`
method to retrieve an array of event listeners that have been called in your
application. Similarly, the
:method:`Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcherInterface::getNotCalledListeners`
method returns an array of event listeners that have not been called::

// ...

$calledListeners = $traceableEventDispatcher->getCalledListeners();
$notCalledListeners = $traceableEventDispatcher->getNotCalledListeners();
1 change: 1 addition & 0 deletions components/map.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* :doc:`/components/event_dispatcher/container_aware_dispatcher`
* :doc:`/components/event_dispatcher/generic_event`
* :doc:`/components/event_dispatcher/immutable_dispatcher`
* :doc:`/components/event_dispatcher/traceable_dispatcher`

* **Filesystem**

Expand Down

0 comments on commit 1160f7c

Please sign in to comment.