Permalink
Browse files

bug #4240 [Components][EventDispatcher] fix ContainerAwareEventDispat…

…cher definition (xabbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

[Components][EventDispatcher] fix ContainerAwareEventDispatcher definition

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | all
| Fixed tickets | #4235

Commits
-------

4742859 fix ContainerAwareEventDispatcher definition
  • Loading branch information...
weaverryan committed Sep 22, 2014
2 parents 1d56da4 + 4742859 commit 082755dac2385250c11a8c6024ca2d74048bd654
Showing with 7 additions and 4 deletions.
  1. +7 −4 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 </components/dependency_injection/introduction>`,
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');

0 comments on commit 082755d

Please sign in to comment.