From 04b8e2f8c8e2356735e4cb40af9bae94382a79a5 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 16 Jan 2017 09:37:59 +0100 Subject: [PATCH 1/5] Deprecated ContainerAwareEventDispatcher --- components/event_dispatcher.rst | 9 +++++++-- .../event_dispatcher/container_aware_dispatcher.rst | 5 +++++ components/event_dispatcher/immutable_dispatcher.rst | 5 ++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 439d91e2ac0..3605782f8af 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -22,7 +22,7 @@ answer. Consider the real-world example where you want to provide a plugin system for your project. A plugin should be able to add methods, or do something before or after a method is executed, without interfering with other plugins. -This is not an easy problem to solve with single inheritance, and even if +This is not an easy problem to solve with single inheritance, and even if multiple inheritance was possible with PHP, it comes with its own drawbacks. The Symfony EventDispatcher component implements the `Mediator`_ pattern @@ -189,6 +189,11 @@ determine which instance is passed. .. sidebar:: Registering Event Listeners in the Service Container + versionadded:: 3.3 + The ``ContainerAwareEventDispatcher`` class has been deprecated in + Symfony 3.3 and it will be removed in Symfony 4.0. Use ``EventDispatcher`` + with closure-proxy injection instead. + When you are using the :class:`Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher` and the @@ -441,7 +446,7 @@ EventDispatcher Aware Events and Listeners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``EventDispatcher`` always passes the dispatched event, the event's -name and a reference to itself to the listeners. This can lead to some advanced +name and a reference to itself to the listeners. This can lead to some advanced applications of the ``EventDispatcher`` including dispatching other events inside listeners, chaining events or even lazy loading listeners into the dispatcher object. diff --git a/components/event_dispatcher/container_aware_dispatcher.rst b/components/event_dispatcher/container_aware_dispatcher.rst index 245a1f44118..f06d7ef5416 100644 --- a/components/event_dispatcher/container_aware_dispatcher.rst +++ b/components/event_dispatcher/container_aware_dispatcher.rst @@ -4,6 +4,11 @@ The Container Aware Event Dispatcher ==================================== +versionadded:: 3.3 + The ``ContainerAwareEventDispatcher`` class has been deprecated in Symfony 3.3 + and it will be removed in Symfony 4.0. Use ``EventDispatcher`` with + closure-proxy injection instead. + Introduction ------------ diff --git a/components/event_dispatcher/immutable_dispatcher.rst b/components/event_dispatcher/immutable_dispatcher.rst index 905d1db5b01..25940825065 100644 --- a/components/event_dispatcher/immutable_dispatcher.rst +++ b/components/event_dispatcher/immutable_dispatcher.rst @@ -12,9 +12,8 @@ The ``ImmutableEventDispatcher`` takes another event dispatcher with all the listeners and subscribers. The immutable dispatcher is just a proxy of this original dispatcher. -To use it, first create a normal dispatcher (``EventDispatcher`` or -``ContainerAwareEventDispatcher``) and register some listeners or -subscribers:: +To use it, first create a normal ``EventDispatcher`` dispatcher and register +some listeners or subscribers:: use Symfony\Component\EventDispatcher\EventDispatcher; From 5c27b64b1d0ce17ad01bb2278d3c6314303f9a3a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 16 Jan 2017 10:24:29 +0100 Subject: [PATCH 2/5] Fixed a syntax issue --- components/event_dispatcher.rst | 2 +- components/event_dispatcher/container_aware_dispatcher.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 3605782f8af..708cd30b9b0 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -189,7 +189,7 @@ determine which instance is passed. .. sidebar:: Registering Event Listeners in the Service Container - versionadded:: 3.3 + .. versionadded:: 3.3 The ``ContainerAwareEventDispatcher`` class has been deprecated in Symfony 3.3 and it will be removed in Symfony 4.0. Use ``EventDispatcher`` with closure-proxy injection instead. diff --git a/components/event_dispatcher/container_aware_dispatcher.rst b/components/event_dispatcher/container_aware_dispatcher.rst index f06d7ef5416..fd04a73daf3 100644 --- a/components/event_dispatcher/container_aware_dispatcher.rst +++ b/components/event_dispatcher/container_aware_dispatcher.rst @@ -4,7 +4,7 @@ The Container Aware Event Dispatcher ==================================== -versionadded:: 3.3 +.. versionadded:: 3.3 The ``ContainerAwareEventDispatcher`` class has been deprecated in Symfony 3.3 and it will be removed in Symfony 4.0. Use ``EventDispatcher`` with closure-proxy injection instead. From d634471baa1c60783e230a64bca8dcf9269fd753 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 17 Jan 2017 09:41:36 +0100 Subject: [PATCH 3/5] Update an example to remove ContainerAwareEventDispatcher --- components/event_dispatcher.rst | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 708cd30b9b0..866a904cf6b 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -187,38 +187,28 @@ event. In many cases, a special event subclass is passed with extra information. You can check the documentation or implementation of each event to determine which instance is passed. -.. sidebar:: Registering Event Listeners in the Service Container +.. sidebar:: Registering Event Listeners and Subscribers in the Service Container - .. versionadded:: 3.3 - The ``ContainerAwareEventDispatcher`` class has been deprecated in - Symfony 3.3 and it will be removed in Symfony 4.0. Use ``EventDispatcher`` - with closure-proxy injection instead. - - When you are using the - :class:`Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher` - and the - :doc:`DependencyInjection component `, - you can use the - :class:`Symfony\\Component\\EventDispatcher\\DependencyInjection\\RegisterListenersPass` - to tag services as event listeners:: + Registering service definitions and tagging them with the ``kernel.event_listener`` + and ``kernel.event_subscriber`` tags is not enough to enable the event listeners + and event subscribers. You must also register the ``RegisterListenersPass()`` + compiler pass in the container builder:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Reference; - use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; + use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; $containerBuilder = new ContainerBuilder(new ParameterBag()); + // register the compiler pass that handles the 'kernel.event_listener' + // and 'kernel.event_subscriber' service tags $containerBuilder->addCompilerPass(new RegisterListenersPass()); - // register the event dispatcher service - $containerBuilder->setDefinition('event_dispatcher', new Definition( - ContainerAwareEventDispatcher::class, - array(new Reference('service_container')) - )); + $containerBuilder->register('event_dispatcher', EventDispatcher::class); - // register your event listener service + // register an event listener $listener = new Definition(\AcmeListener::class); $listener->addTag('kernel.event_listener', array( 'event' => 'foo.action', From 6deb7af8fbf58e59e7370efd22f891b1da793b57 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 17 Jan 2017 13:03:14 +0100 Subject: [PATCH 4/5] Minor reword --- components/event_dispatcher.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 866a904cf6b..97252c319b3 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -189,10 +189,10 @@ determine which instance is passed. .. sidebar:: Registering Event Listeners and Subscribers in the Service Container - Registering service definitions and tagging them with the ``kernel.event_listener`` - and ``kernel.event_subscriber`` tags is not enough to enable the event listeners - and event subscribers. You must also register the ``RegisterListenersPass()`` - compiler pass in the container builder:: + Registering service definitions and tagging them with the + ``kernel.event_listener`` and ``kernel.event_subscriber`` tags is not enough + to enable the event listeners and event subscribers. You must also register + in the container builder a compiler pass called ``RegisterListenersPass()``:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; From 98ee9d5a91f15b9e90ef9f63a022ba2b02ccbef3 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 17 Jan 2017 13:09:02 +0100 Subject: [PATCH 5/5] Minor reword --- components/event_dispatcher.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 97252c319b3..b05c2b8d5c9 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -192,7 +192,7 @@ determine which instance is passed. Registering service definitions and tagging them with the ``kernel.event_listener`` and ``kernel.event_subscriber`` tags is not enough to enable the event listeners and event subscribers. You must also register - in the container builder a compiler pass called ``RegisterListenersPass()``:: + a compiler pass called ``RegisterListenersPass()`` in the container builder:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition;