From 0831e4f14830abd78b395f603c098647782cd609 Mon Sep 17 00:00:00 2001 From: Drak Date: Sat, 6 Apr 2013 20:38:09 +0100 Subject: [PATCH 1/2] Update documentation for EventDispatcherAwareEvent documentation. --- components/event_dispatcher/introduction.rst | 22 +++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/components/event_dispatcher/introduction.rst b/components/event_dispatcher/introduction.rst index 5cd4fe3af21..3d58e551300 100644 --- a/components/event_dispatcher/introduction.rst +++ b/components/event_dispatcher/introduction.rst @@ -442,11 +442,17 @@ EventDispatcher aware Events and Listeners .. versionadded:: 2.1 The ``Event`` object contains a reference to the invoking dispatcher since Symfony 2.1 + This was removed in Symfony 2.3 -The ``EventDispatcher`` always injects a reference to itself in the passed event -object. This means that all listeners have direct access to the -``EventDispatcher`` object that notified the listener via the passed ``Event`` -object's :method:`Symfony\\Component\\EventDispatcher\\Event::getDispatcher` +.. versionadded:: 2.3 + The ``EventDispactherAwareEvent`` object contains a reference to the invoking dispatcher since Symfony 2.3 + +The ``EventDispatcher`` will inject a reference to itself in the passed event +object if that event object is an instance of +:class:`Symfony\\Component\\EventDispatcher\\EventDispatcherAwareEvent`. +This means that all listeners have direct access to the +``EventDispatcher`` object that notified the listener via the +:method:`Symfony\\Component\\EventDispatcher\\EventDispatcherAwareEvent::getDispatcher` method. This can lead to some advanced applications of the ``EventDispatcher`` including @@ -455,14 +461,14 @@ more listeners into the dispatcher object. Examples follow: Lazy loading listeners:: - use Symfony\Component\EventDispatcher\Event; + use Symfony\Component\EventDispatcher\EventDispatcherAwareEvent; use Acme\StoreBundle\Event\StoreSubscriber; class Foo { private $started = false; - public function myLazyListener(Event $event) + public function myLazyListener(EventDispatcherAwareEvent $event) { if (false === $this->started) { $subscriber = new StoreSubscriber(); @@ -477,11 +483,11 @@ Lazy loading listeners:: Dispatching another event from within a listener:: - use Symfony\Component\EventDispatcher\Event; + use Symfony\Component\EventDispatcher\EventDispatcherAwareEvent; class Foo { - public function myFooListener(Event $event) + public function myFooListener(EventDispatcherAwareEvent $event) { $event->getDispatcher()->dispatch('log', $event); From 7bed1ccf25aa97fc28295b0aabd8a67bdc789bba Mon Sep 17 00:00:00 2001 From: Drak Date: Sat, 6 Apr 2013 22:14:14 +0100 Subject: [PATCH 2/2] Wrap line --- components/event_dispatcher/introduction.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/event_dispatcher/introduction.rst b/components/event_dispatcher/introduction.rst index 3d58e551300..4816e9ac3ad 100644 --- a/components/event_dispatcher/introduction.rst +++ b/components/event_dispatcher/introduction.rst @@ -445,7 +445,8 @@ EventDispatcher aware Events and Listeners This was removed in Symfony 2.3 .. versionadded:: 2.3 - The ``EventDispactherAwareEvent`` object contains a reference to the invoking dispatcher since Symfony 2.3 + The ``EventDispactherAwareEvent`` object contains a reference to the invoking dispatcher + since Symfony 2.3 The ``EventDispatcher`` will inject a reference to itself in the passed event object if that event object is an instance of @@ -544,7 +545,7 @@ Dispatcher Shortcuts .. versionadded:: 2.1 ``EventDispatcher::dispatch()`` method returns the event since Symfony 2.1. -The :method:`EventDispatcher::dispatch` +The :method:`EventDispatcher::dispatch