Skip to content

Commit 6629db8

Browse files
committed
Merge branch '2.4' into 2.5
2 parents e19fd2a + 95a6b74 commit 6629db8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

components/event_dispatcher/index.rst

Lines changed: 1 addition & 0 deletions
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
Lines changed: 46 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
* :doc:`/components/event_dispatcher/container_aware_dispatcher`
6161
* :doc:`/components/event_dispatcher/generic_event`
6262
* :doc:`/components/event_dispatcher/immutable_dispatcher`
63+
* :doc:`/components/event_dispatcher/traceable_dispatcher`
6364

6465
* :doc:`/components/expression_language/index`
6566

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy