Skip to content

Commit 88619c3

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: Move note below and add examples
2 parents 2963f3e + 9c67064 commit 88619c3

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

components/event_dispatcher.rst

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,6 @@ order. Start by creating this custom event class and documenting it::
272272

273273
Each 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-
284275
Dispatch the Event
285276
..................
286277

@@ -304,6 +295,32 @@ Notice that the special ``OrderPlacedEvent`` object is created and passed to
304295
the ``dispatch()`` method. Now, any listener to the ``OrderPlacedEvent::class``
305296
event 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

309326
Using Event Subscribers

0 commit comments

Comments
 (0)