@@ -22,7 +22,7 @@ answer.
2222Consider the real-world example where you want to provide a plugin system
2323for your project. A plugin should be able to add methods, or do something
2424before or after a method is executed, without interfering with other plugins.
25- This is not an easy problem to solve with single inheritance, and even if
25+ This is not an easy problem to solve with single inheritance, and even if
2626multiple inheritance was possible with PHP, it comes with its own drawbacks.
2727
2828The Symfony EventDispatcher component implements the `Mediator `_ pattern
@@ -198,7 +198,6 @@ determine which instance is passed.
198198 to tag services as event listeners::
199199
200200 use Symfony\Component\DependencyInjection\ContainerBuilder;
201- use Symfony\Component\DependencyInjection\Definition;
202201 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
203202 use Symfony\Component\DependencyInjection\Reference;
204203 use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
@@ -208,23 +207,19 @@ determine which instance is passed.
208207 $containerBuilder->addCompilerPass(new RegisterListenersPass());
209208
210209 // register the event dispatcher service
211- $containerBuilder->setDefinition('event_dispatcher', new Definition(
212- ContainerAwareEventDispatcher::class,
213- array(new Reference('service_container'))
214- ));
210+ $containerBuilder->register('event_dispatcher', ContainerAwareEventDispatcher::class)
211+ ->addArgument(new Reference('service_container'));
215212
216213 // register your event listener service
217- $listener = new Definition(\AcmeListener::class);
218- $listener->addTag('kernel.event_listener', array(
219- 'event' => 'acme.foo.action',
220- 'method' => 'onFooAction',
221- ));
222- $containerBuilder->setDefinition('listener_service_id', $listener);
214+ $containerBuilder->register('listener_service_id', \AcmeListener::class)
215+ ->addTag('kernel.event_listener', array(
216+ 'event' => 'acme.foo.action',
217+ 'method' => 'onFooAction',
218+ ));
223219
224220 // register an event subscriber
225- $subscriber = new Definition(\AcmeSubscriber::class);
226- $subscriber->addTag('kernel.event_subscriber');
227- $containerBuilder->setDefinition('subscriber_service_id', $subscriber);
221+ $containerBuilder->register('subscriber_service_id', \AcmeSubscriber::class)
222+ ->addTag('kernel.event_subscriber');
228223
229224 By default, the listeners pass assumes that the event dispatcher's service
230225 id is ``event_dispatcher ``, that event listeners are tagged with the
@@ -441,7 +436,7 @@ EventDispatcher Aware Events and Listeners
441436~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442437
443438The ``EventDispatcher `` always passes the dispatched event, the event's
444- name and a reference to itself to the listeners. This can lead to some advanced
439+ name and a reference to itself to the listeners. This can lead to some advanced
445440applications of the ``EventDispatcher `` including dispatching other events inside
446441listeners, chaining events or even lazy loading listeners into the dispatcher object.
447442
0 commit comments