From 00ac7bc3b9248648284632062ece464803546e6d Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Tue, 24 Nov 2020 17:16:31 +0100 Subject: [PATCH 1/6] Update event_dispatcher.rst --- components/event_dispatcher.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 0344acf4e8e..c04abe4b8a1 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -348,6 +348,7 @@ of the event to dispatch:: // creates the OrderPlacedEvent and dispatches it $event = new OrderPlacedEvent($order); $dispatcher->dispatch($event, OrderPlacedEvent::NAME); + // note that ``OrderPlacedEvent::NAME`` is optional, read below Notice that the special ``OrderPlacedEvent`` object is created and passed to the ``dispatch()`` method. Now, any listener to the ``order.placed`` @@ -391,6 +392,9 @@ Take the following example of a subscriber that subscribes to the ['onKernelResponsePost', -10], ], OrderPlacedEvent::NAME => 'onStoreOrder', + // note that you can also subscribe like this + // when passing only the event + OrderPlacedEvent::class => 'onStoreOrder', ]; } From 95b05f6d0a5c8893b963ba3ffcd2690d0a84abc8 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Sun, 29 Nov 2020 12:38:03 +0100 Subject: [PATCH 2/6] Update event_dispatcher.rst --- components/event_dispatcher.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index c04abe4b8a1..6b0f2694a39 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -348,7 +348,7 @@ of the event to dispatch:: // creates the OrderPlacedEvent and dispatches it $event = new OrderPlacedEvent($order); $dispatcher->dispatch($event, OrderPlacedEvent::NAME); - // note that ``OrderPlacedEvent::NAME`` is optional, read below + // note that ``OrderPlacedEvent::NAME`` is optional, read more below Notice that the special ``OrderPlacedEvent`` object is created and passed to the ``dispatch()`` method. Now, any listener to the ``order.placed`` @@ -392,8 +392,8 @@ Take the following example of a subscriber that subscribes to the ['onKernelResponsePost', -10], ], OrderPlacedEvent::NAME => 'onStoreOrder', - // note that you can also subscribe like this - // when passing only the event + // you can also subscribe this way if you pass only + // the event object OrderPlacedEvent::class => 'onStoreOrder', ]; } From 7d9e6fe4a518319e6c278e9c2183e9531c50b512 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Fri, 18 Dec 2020 17:04:34 +0100 Subject: [PATCH 3/6] Update event_dispatcher.rst --- components/event_dispatcher.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 6b0f2694a39..5e40f526a6d 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -348,7 +348,8 @@ of the event to dispatch:: // creates the OrderPlacedEvent and dispatches it $event = new OrderPlacedEvent($order); $dispatcher->dispatch($event, OrderPlacedEvent::NAME); - // note that ``OrderPlacedEvent::NAME`` is optional, read more below + // note that the second argument ``OrderPlacedEvent::NAME`` is optional, + // read more below in the subscriber code part Notice that the special ``OrderPlacedEvent`` object is created and passed to the ``dispatch()`` method. Now, any listener to the ``order.placed`` @@ -393,7 +394,8 @@ Take the following example of a subscriber that subscribes to the ], OrderPlacedEvent::NAME => 'onStoreOrder', // you can also subscribe this way if you pass only - // the event object + // the event object as first argument and omit the second + // of the $dispatcher->dispatch method OrderPlacedEvent::class => 'onStoreOrder', ]; } From 882bca22cf0efacbdbde8bd0edd6073357b27516 Mon Sep 17 00:00:00 2001 From: noniagriconomie Date: Fri, 12 Mar 2021 09:04:31 +0100 Subject: [PATCH 4/6] Update event_dispatcher.rst --- components/event_dispatcher.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 5e40f526a6d..f6d1fe96b9a 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -348,11 +348,17 @@ of the event to dispatch:: // creates the OrderPlacedEvent and dispatches it $event = new OrderPlacedEvent($order); $dispatcher->dispatch($event, OrderPlacedEvent::NAME); - // note that the second argument ``OrderPlacedEvent::NAME`` is optional, - // read more below in the subscriber code part + // or since Symfony 4.3+ + $dispatcher->dispatch($event); + +.. versionadded:: 4.3 + + The event name is now optional since Symfony 4.3 in + the :method:`Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch`. Notice that the special ``OrderPlacedEvent`` object is created and passed to -the ``dispatch()`` method. Now, any listener to the ``order.placed`` +the ``dispatch()`` method. Now, any listener to the ``order.placed`` or the +``Acme\Store\Event\OrderPlacedEvent`` (FQCN) event will receive the ``OrderPlacedEvent``. .. index:: @@ -392,10 +398,9 @@ Take the following example of a subscriber that subscribes to the ['onKernelResponsePre', 10], ['onKernelResponsePost', -10], ], + // when using two arguments, the event and the event name OrderPlacedEvent::NAME => 'onStoreOrder', - // you can also subscribe this way if you pass only - // the event object as first argument and omit the second - // of the $dispatcher->dispatch method + // when using only one argument, the event (since Symfony 4.3+) OrderPlacedEvent::class => 'onStoreOrder', ]; } From 76a7aa84549cf0cf2451ff17ed5e358792911712 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Thu, 22 Apr 2021 15:05:25 +0200 Subject: [PATCH 5/6] Update components/event_dispatcher.rst Co-authored-by: Oskar Stark --- 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 f6d1fe96b9a..9afb835bf4d 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -348,7 +348,7 @@ of the event to dispatch:: // creates the OrderPlacedEvent and dispatches it $event = new OrderPlacedEvent($order); $dispatcher->dispatch($event, OrderPlacedEvent::NAME); - // or since Symfony 4.3+ + // you can also omit the second argument $dispatcher->dispatch($event); .. versionadded:: 4.3 From 2383ced9170daf52e7c82c545c6c3869fc49b2b2 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Thu, 22 Apr 2021 15:05:31 +0200 Subject: [PATCH 6/6] Update components/event_dispatcher.rst Co-authored-by: Oskar Stark --- components/event_dispatcher.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 9afb835bf4d..e238eec62fc 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -353,8 +353,8 @@ of the event to dispatch:: .. versionadded:: 4.3 - The event name is now optional since Symfony 4.3 in - the :method:`Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch`. + The event name in :method:`Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch` + is optional since Symfony 4.3. Notice that the special ``OrderPlacedEvent`` object is created and passed to the ``dispatch()`` method. Now, any listener to the ``order.placed`` or the