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

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

Merged
merged 1 commit into from
Jan 25, 2015
Merged
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
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