Skip to content

[EventDispatcher] Document dispatch() with one argument as a FQCN #14606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/event_dispatcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ of the event to dispatch::
// creates the OrderPlacedEvent and dispatches it
$event = new OrderPlacedEvent($order);
$dispatcher->dispatch($event, OrderPlacedEvent::NAME);
// note that the second argument ``OrderPlacedEvent::NAME`` is optional,
// read more below in the subscriber code part

Notice that the special ``OrderPlacedEvent`` object is created and passed to
the ``dispatch()`` method. Now, any listener to the ``order.placed``
Expand Down Expand Up @@ -391,6 +393,10 @@ Take the following example of a subscriber that subscribes to the
['onKernelResponsePost', -10],
],
OrderPlacedEvent::NAME => 'onStoreOrder',
// you can also subscribe this way if you pass only
// the event object as first argument and omit the second
// of the $dispatcher->dispatch method
OrderPlacedEvent::class => 'onStoreOrder',
];
}

Expand Down