From 474285981d841739d943e7930f3fdcf09f76f2e7 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 16 Sep 2014 22:49:25 +0200 Subject: [PATCH] fix ContainerAwareEventDispatcher definition --- components/event_dispatcher/introduction.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/components/event_dispatcher/introduction.rst b/components/event_dispatcher/introduction.rst index 1b32938c89a..e862af05347 100644 --- a/components/event_dispatcher/introduction.rst +++ b/components/event_dispatcher/introduction.rst @@ -208,6 +208,8 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``:: .. sidebar:: Registering Event Listeners in the Service Container When you are using the + :class:`Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher` + and the :doc:`DependencyInjection component `, you can use the :class:`Symfony\\Component\\HttpKernel\\DependencyInjection\\RegisterListenersPass` @@ -216,16 +218,17 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``:: use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; + use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass; $containerBuilder = new ContainerBuilder(new ParameterBag()); $containerBuilder->addCompilerPass(new RegisterListenersPass()); // register the event dispatcher service - $containerBuilder->register( - 'event_dispatcher', - 'Symfony\Component\EventDispatcher\EventDispatcher' - ); + $containerBuilder->setDefinition('event_dispatcher', new Definition( + 'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher', + array(new Reference('service_container')) + )); // register your event listener service $listener = new Definition('AcmeListener');