Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 350b805

Browse filesBrowse files
committed
feature #3916 [Component][EventDispatcher] documentation for the TraceableEventDispatcher (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Component][EventDispatcher] documentation for the TraceableEventDispatcher | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | 2.3, 2.4 | Fixed tickets | #3879 After this has been merged, the document has to be updated for Symfony 2.5 and higher to reflect that the ``TraceableEventDispatcher`` is now part of the EventDispatcher component. Commits ------- 1160f7c add documentation for the TraceableEventDispatcher class
2 parents 351b2cf + 1160f7c commit 350b805
Copy full SHA for 350b805

File tree

Expand file treeCollapse file tree

3 files changed

+48
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+48
-0
lines changed

‎components/event_dispatcher/index.rst

Copy file name to clipboardExpand all lines: components/event_dispatcher/index.rst
+1Lines 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
+46Lines 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

Copy file name to clipboardExpand all lines: components/map.rst.inc
+1Lines changed: 1 addition & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.