@@ -272,15 +272,6 @@ order. Start by creating this custom event class and documenting it::
272272
273273Each listener now has access to the order via the ``getOrder() `` method.
274274
275- .. note ::
276-
277- If you don't need to pass any additional data to the event listeners, you
278- can also use the default
279- :class: `Symfony\\ Contracts\\ EventDispatcher\\ Event ` class. In such case,
280- you can document the event and its name in a generic ``StoreEvents `` class,
281- similar to the :class: `Symfony\\ Component\\ HttpKernel\\ KernelEvents `
282- class.
283-
284275Dispatch the Event
285276..................
286277
@@ -304,6 +295,32 @@ Notice that the special ``OrderPlacedEvent`` object is created and passed to
304295the ``dispatch() `` method. Now, any listener to the ``OrderPlacedEvent::class ``
305296event will receive the ``OrderPlacedEvent ``.
306297
298+ .. note ::
299+
300+ If you don't need to pass any additional data to the event listeners, you
301+ can also use the default
302+ :class: `Symfony\\ Contracts\\ EventDispatcher\\ Event ` class. In such case,
303+ you can document the event and its name in a generic ``StoreEvents `` class,
304+ similar to the :class: `Symfony\\ Component\\ HttpKernel\\ KernelEvents `
305+ class::
306+
307+ namespace App\Event;
308+
309+ class StoreEvents {
310+
311+ /**
312+ * @Event("Symfony\Contracts\EventDispatcher\Event")
313+ */
314+ public const ORDER_PLACED = 'order.placed';
315+ }
316+
317+ And use the :class: `Symfony\\ Contracts\\ EventDispatcher\\ Event ` class to
318+ dispatch the event::
319+
320+ use Symfony\Contracts\EventDispatcher\Event;
321+
322+ $this->eventDispatcher->dispatch(new Event(), StoreEvents::ORDER_PLACED);
323+
307324.. _event_dispatcher-using-event-subscribers :
308325
309326Using Event Subscribers
0 commit comments