@@ -334,7 +334,9 @@ Dispatch the Event
334334..................
335335
336336The :method: `Symfony\\ Component\\ EventDispatcher\\ EventDispatcher::dispatch `
337- method notifies all listeners of the given event. It takes two arguments:
337+ method notifies all listeners of the given event.
338+
339+ It takes two arguments:
338340the ``Event `` instance to pass to each listener of that event and the name
339341of the event to dispatch::
340342
@@ -348,8 +350,16 @@ of the event to dispatch::
348350 // creates the OrderPlacedEvent and dispatches it
349351 $event = new OrderPlacedEvent($order);
350352 $dispatcher->dispatch($event, OrderPlacedEvent::NAME);
351- // note that the second argument ``OrderPlacedEvent::NAME`` is optional,
352- // read more below in the subscriber code part
353+
354+ .. versionadded :: 4.3
355+
356+ Since Symfony 4.3, note that the event name is now optional in the :method: `Symfony\\ Component\\ EventDispatcher\\ EventDispatcher::dispatch ` method,
357+ so you can pass just the event object as first argument::
358+
359+ // ...
360+ // creates the OrderPlacedEvent and dispatches it
361+ $event = new OrderPlacedEvent($order);
362+ $dispatcher->dispatch($event);
353363
354364Notice that the special ``OrderPlacedEvent `` object is created and passed to
355365the ``dispatch() `` method. Now, any listener to the ``order.placed ``
@@ -392,10 +402,9 @@ Take the following example of a subscriber that subscribes to the
392402 ['onKernelResponsePre', 10],
393403 ['onKernelResponsePost', -10],
394404 ],
405+ // when using two arguments, event and event name
395406 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
407+ // when using only one argument, the event (Symfony 4.3+)
399408 OrderPlacedEvent::class => 'onStoreOrder',
400409 ];
401410 }
0 commit comments