@@ -291,8 +291,8 @@ Dispatch the Event
291291
292292The :method: `Symfony\\ Component\\ EventDispatcher\\ EventDispatcher::dispatch `
293293method notifies all listeners of the given event. It takes two arguments:
294- the name of the event to dispatch and the ``Event `` instance to pass to
295- each listener of that event::
294+ the ``Event `` instance to pass to each listener of that event and the name
295+ of the event to dispatch and ::
296296
297297 use Acme\Store\Event\OrderPlacedEvent;
298298 use Acme\Store\Order;
@@ -303,7 +303,7 @@ each listener of that event::
303303
304304 // creates the OrderPlacedEvent and dispatches it
305305 $event = new OrderPlacedEvent($order);
306- $dispatcher->dispatch(OrderPlacedEvent::NAME, $event );
306+ $dispatcher->dispatch($event, OrderPlacedEvent::NAME);
307307
308308Notice that the special ``OrderPlacedEvent `` object is created and passed to
309309the ``dispatch() `` method. Now, any listener to the ``order.placed ``
@@ -423,7 +423,7 @@ It is possible to detect if an event was stopped by using the
423423method which returns a boolean value::
424424
425425 // ...
426- $dispatcher->dispatch('foo.event', $event );
426+ $dispatcher->dispatch($event, 'foo.event');
427427 if ($event->isPropagationStopped()) {
428428 // ...
429429 }
@@ -441,36 +441,6 @@ name and a reference to itself to the listeners. This can lead to some advanced
441441applications of the ``EventDispatcher `` including dispatching other events inside
442442listeners, chaining events or even lazy loading listeners into the dispatcher object.
443443
444- .. index ::
445- single: EventDispatcher; Dispatcher shortcuts
446-
447- .. _event_dispatcher-shortcuts :
448-
449- Dispatcher Shortcuts
450- ~~~~~~~~~~~~~~~~~~~~
451-
452- If you do not need a custom event object, you can rely on a plain
453- :class: `Symfony\\ Contracts\\ EventDispatcher\\ Event ` object. You do not even
454- need to pass this to the dispatcher as it will create one by default unless you
455- specifically pass one::
456-
457- $dispatcher->dispatch('order.placed');
458-
459- Moreover, the event dispatcher always returns whichever event object that
460- was dispatched, i.e. either the event that was passed or the event that
461- was created internally by the dispatcher. This allows for nice shortcuts::
462-
463- if (!$dispatcher->dispatch('foo.event')->isPropagationStopped()) {
464- // ...
465- }
466-
467- Or::
468-
469- $event = new OrderPlacedEvent($order);
470- $order = $dispatcher->dispatch('bar.event', $event)->getOrder();
471-
472- and so on.
473-
474444.. index ::
475445 single: EventDispatcher; Event name introspection
476446
0 commit comments