@@ -291,8 +291,8 @@ Dispatch the Event
291
291
292
292
The :method: `Symfony\\ Component\\ EventDispatcher\\ EventDispatcher::dispatch `
293
293
method 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 ::
296
296
297
297
use Acme\Store\Event\OrderPlacedEvent;
298
298
use Acme\Store\Order;
@@ -303,7 +303,7 @@ each listener of that event::
303
303
304
304
// creates the OrderPlacedEvent and dispatches it
305
305
$event = new OrderPlacedEvent($order);
306
- $dispatcher->dispatch(OrderPlacedEvent::NAME, $event );
306
+ $dispatcher->dispatch($event, OrderPlacedEvent::NAME);
307
307
308
308
Notice that the special ``OrderPlacedEvent `` object is created and passed to
309
309
the ``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
423
423
method which returns a boolean value::
424
424
425
425
// ...
426
- $dispatcher->dispatch('foo.event', $event );
426
+ $dispatcher->dispatch($event, 'foo.event');
427
427
if ($event->isPropagationStopped()) {
428
428
// ...
429
429
}
@@ -441,36 +441,6 @@ name and a reference to itself to the listeners. This can lead to some advanced
441
441
applications of the ``EventDispatcher `` including dispatching other events inside
442
442
listeners, chaining events or even lazy loading listeners into the dispatcher object.
443
443
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
-
474
444
.. index ::
475
445
single: EventDispatcher; Event name introspection
476
446
0 commit comments