Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Component][EventDispatcher] documentation for the TraceableEventDispatcher #3916

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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