Skip to content

Commit

Permalink
minor #4859 [Components][EventDispatcher] don't explain deprecated `g…
Browse files Browse the repository at this point in the history
…etName()` method (xabbuh)

This PR was merged into the 2.5 branch.

Discussion
----------

[Components][EventDispatcher] don't explain deprecated `getName()` method

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.5+
| Fixed tickets |

Commits
-------

430de15 don't explain deprecated `getName()` method
  • Loading branch information
weaverryan committed Jan 25, 2015
2 parents 62248df + 430de15 commit 33914c9
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions components/event_dispatcher/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -626,22 +626,21 @@ and so on...
Event Name Introspection
~~~~~~~~~~~~~~~~~~~~~~~~

Since the ``EventDispatcher`` already knows the name of the event when dispatching
it, the event name is also injected into the
:class:`Symfony\\Component\\EventDispatcher\\Event` objects, making it available
to event listeners via the :method:`Symfony\\Component\\EventDispatcher\\Event::getName`
method.
.. versionadded:: 2.4
Before Symfony 2.4, the event name and the event dispatcher had to be
requested from the ``Event`` instance. These methods are now deprecated.

The event name, (as with any other data in a custom event object) can be used as
part of the listener's processing logic::
The ``EventDispatcher`` instance, as well as the name of the event that is
dispatched, are passed as arguments to the listener::

use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class Foo
{
public function myEventListener(Event $event)
public function myEventListener(Event $event, $eventName, EventDispatcherInterface $dispatcher)
{
echo $event->getName();
echo $eventName;
}
}

Expand Down

0 comments on commit 33914c9

Please sign in to comment.