Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 882bca2

Browse files
Update event_dispatcher.rst
1 parent 7d9e6fe commit 882bca2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

components/event_dispatcher.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,17 @@ of the event to dispatch::
348348
// creates the OrderPlacedEvent and dispatches it
349349
$event = new OrderPlacedEvent($order);
350350
$dispatcher->dispatch($event, OrderPlacedEvent::NAME);
351-
// note that the second argument ``OrderPlacedEvent::NAME`` is optional,
352-
// read more below in the subscriber code part
351+
// or since Symfony 4.3+
352+
$dispatcher->dispatch($event);
353+
354+
.. versionadded:: 4.3
355+
356+
The event name is now optional since Symfony 4.3 in
357+
the :method:`Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch`.
353358

354359
Notice that the special ``OrderPlacedEvent`` object is created and passed to
355-
the ``dispatch()`` method. Now, any listener to the ``order.placed``
360+
the ``dispatch()`` method. Now, any listener to the ``order.placed`` or the
361+
``Acme\Store\Event\OrderPlacedEvent`` (FQCN)
356362
event will receive the ``OrderPlacedEvent``.
357363

358364
.. index::
@@ -392,10 +398,9 @@ Take the following example of a subscriber that subscribes to the
392398
['onKernelResponsePre', 10],
393399
['onKernelResponsePost', -10],
394400
],
401+
// when using two arguments, the event and the event name
395402
OrderPlacedEvent::NAME => 'onStoreOrder',
396-
// you can also subscribe this way if you pass only
397-
// the event object as first argument and omit the second
398-
// of the $dispatcher->dispatch method
403+
// when using only one argument, the event (since Symfony 4.3+)
399404
OrderPlacedEvent::class => 'onStoreOrder',
400405
];
401406
}

0 commit comments

Comments
 (0)