diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index 0344acf4e8e..e238eec62fc 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -348,9 +348,17 @@ of the event to dispatch:: // creates the OrderPlacedEvent and dispatches it $event = new OrderPlacedEvent($order); $dispatcher->dispatch($event, OrderPlacedEvent::NAME); + // you can also omit the second argument + $dispatcher->dispatch($event); + +.. versionadded:: 4.3 + + 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`` +the ``dispatch()`` method. Now, any listener to the ``order.placed`` or the +``Acme\Store\Event\OrderPlacedEvent`` (FQCN) event will receive the ``OrderPlacedEvent``. .. index:: @@ -390,7 +398,10 @@ 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', + // when using only one argument, the event (since Symfony 4.3+) + OrderPlacedEvent::class => 'onStoreOrder', ]; }