Skip to content

Commit 1160f7c

Browse files
committed
add documentation for the TraceableEventDispatcher class
1 parent b00573c commit 1160f7c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

components/event_dispatcher/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ EventDispatcher
88
container_aware_dispatcher
99
generic_event
1010
immutable_dispatcher
11+
traceable_dispatcher
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.. index::
2+
single: EventDispatcher; Debug
3+
single: EventDispatcher; Traceable
4+
5+
The Traceable Event Dispatcher
6+
==============================
7+
8+
The :class:`Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher`
9+
is an event dispatcher that wraps any other event dispatcher and can then
10+
be used to determine which event listeners have been called by the dispatcher.
11+
Pass the event dispatcher to be wrapped and an instance of the
12+
:class:`Symfony\\Component\\Stopwatch\\Stopwatch` to its constructor::
13+
14+
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
15+
use Symfony\Component\Stopwatch\Stopwatch;
16+
17+
// the event dispatcher to debug
18+
$eventDispatcher = ...;
19+
20+
$traceableEventDispatcher = new TraceableEventDispatcher($eventDispatcher, new Stopwatch());
21+
22+
Now, the ``TraceableEventDispatcher`` can be used like any other event dispatcher
23+
to register event listeners and dispatch events::
24+
25+
// ...
26+
27+
// register an event listener
28+
$eventListener = ...;
29+
$priority = ...;
30+
$traceableEventDispatcher->addListener('the-event-name', $eventListener, $priority);
31+
32+
// dispatch an event
33+
$event = ...;
34+
$traceableEventDispatcher->dispatch('the-event-name', $event);
35+
36+
After your application has been processed, you can use the
37+
:method:`Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcherInterface::getCalledListeners`
38+
method to retrieve an array of event listeners that have been called in your
39+
application. Similarly, the
40+
:method:`Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcherInterface::getNotCalledListeners`
41+
method returns an array of event listeners that have not been called::
42+
43+
// ...
44+
45+
$calledListeners = $traceableEventDispatcher->getCalledListeners();
46+
$notCalledListeners = $traceableEventDispatcher->getNotCalledListeners();

components/map.rst.inc

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* :doc:`/components/event_dispatcher/container_aware_dispatcher`
5757
* :doc:`/components/event_dispatcher/generic_event`
5858
* :doc:`/components/event_dispatcher/immutable_dispatcher`
59+
* :doc:`/components/event_dispatcher/traceable_dispatcher`
5960

6061
* **Filesystem**
6162

0 commit comments

Comments
 (0)