Skip to content

Commit 082755d

Browse files
committed
bug #4240 [Components][EventDispatcher] fix ContainerAwareEventDispatcher 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
2 parents 1d56da4 + 4742859 commit 082755d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

components/event_dispatcher/introduction.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``::
208208
.. sidebar:: Registering Event Listeners in the Service Container
209209

210210
When you are using the
211+
:class:`Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher`
212+
and the
211213
:doc:`DependencyInjection component </components/dependency_injection/introduction>`,
212214
you can use the
213215
:class:`Symfony\\Component\\HttpKernel\\DependencyInjection\\RegisterListenersPass`
@@ -216,16 +218,17 @@ instance of ``Symfony\Component\HttpKernel\Event\FilterResponseEvent``::
216218
use Symfony\Component\DependencyInjection\ContainerBuilder;
217219
use Symfony\Component\DependencyInjection\Definition;
218220
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
221+
use Symfony\Component\DependencyInjection\Reference;
219222
use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass;
220223

221224
$containerBuilder = new ContainerBuilder(new ParameterBag());
222225
$containerBuilder->addCompilerPass(new RegisterListenersPass());
223226

224227
// register the event dispatcher service
225-
$containerBuilder->register(
226-
'event_dispatcher',
227-
'Symfony\Component\EventDispatcher\EventDispatcher'
228-
);
228+
$containerBuilder->setDefinition('event_dispatcher', new Definition(
229+
'Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher',
230+
array(new Reference('service_container'))
231+
));
229232

230233
// register your event listener service
231234
$listener = new Definition('AcmeListener');

0 commit comments

Comments
 (0)