@@ -272,15 +272,6 @@ order. Start by creating this custom event class and documenting it::
272
272
273
273
Each listener now has access to the order via the ``getOrder() `` method.
274
274
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
-
284
275
Dispatch the Event
285
276
..................
286
277
@@ -304,6 +295,32 @@ Notice that the special ``OrderPlacedEvent`` object is created and passed to
304
295
the ``dispatch() `` method. Now, any listener to the ``OrderPlacedEvent::class ``
305
296
event will receive the ``OrderPlacedEvent ``.
306
297
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
+
307
324
.. _event_dispatcher-using-event-subscribers :
308
325
309
326
Using Event Subscribers
0 commit comments