From 26635bde80875aca7bf33f8078251b33dec1fe8b Mon Sep 17 00:00:00 2001 From: matthieu88160 Date: Tue, 28 Feb 2017 15:13:07 +0100 Subject: [PATCH 1/2] Update event_dispatcher.rst for consistency Improve event naming for example consistency with the what appends next. --- 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 439d91e2ac0..ae7a6556089 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -135,7 +135,7 @@ A call to the dispatcher's ``addListener()`` method associates any valid PHP callable to an event:: $listener = new AcmeListener(); - $dispatcher->addListener('acme.action', array($listener, 'onFooAction')); + $dispatcher->addListener('foo.action', array($listener, 'onFooAction')); The ``addListener()`` method takes up to three arguments: From 81d51185dad91f9da474aca0c3bf7b8b4e6ad5b1 Mon Sep 17 00:00:00 2001 From: matthieu88160 Date: Tue, 28 Feb 2017 21:56:46 +0100 Subject: [PATCH 2/2] Rename event_dispatcher.rst events According to comment about the pull request #7547, renaming the events acme.action to acme.foo.action --- components/event_dispatcher.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index ae7a6556089..8f8b86a5140 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -135,7 +135,7 @@ A call to the dispatcher's ``addListener()`` method associates any valid PHP callable to an event:: $listener = new AcmeListener(); - $dispatcher->addListener('foo.action', array($listener, 'onFooAction')); + $dispatcher->addListener('acme.foo.action', array($listener, 'onFooAction')); The ``addListener()`` method takes up to three arguments: @@ -161,12 +161,12 @@ The ``addListener()`` method takes up to three arguments: use Symfony\Component\EventDispatcher\Event; - $dispatcher->addListener('foo.action', function (Event $event) { - // will be executed when the foo.action event is dispatched + $dispatcher->addListener('acme.foo.action', function (Event $event) { + // will be executed when the acme.foo.action event is dispatched }); Once a listener is registered with the dispatcher, it waits until the event -is notified. In the above example, when the ``foo.action`` event is dispatched, +is notified. In the above example, when the ``acme.foo.action`` event is dispatched, the dispatcher calls the ``AcmeListener::onFooAction()`` method and passes the ``Event`` object as the single argument:: @@ -216,7 +216,7 @@ determine which instance is passed. // register your event listener service $listener = new Definition(\AcmeListener::class); $listener->addTag('kernel.event_listener', array( - 'event' => 'foo.action', + 'event' => 'acme.foo.action', 'method' => 'onFooAction', )); $containerBuilder->setDefinition('listener_service_id', $listener);