-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[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
Changes from 4 commits
00ac7bc
95b05f6
7d9e6fe
882bca2
76a7aa8
2383ced
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -348,9 +348,17 @@ of the event to dispatch:: | |
// creates the OrderPlacedEvent and dispatches it | ||
$event = new OrderPlacedEvent($order); | ||
$dispatcher->dispatch($event, OrderPlacedEvent::NAME); | ||
// or since Symfony 4.3+ | ||
$dispatcher->dispatch($event); | ||
|
||
.. versionadded:: 4.3 | ||
|
||
The event name is now optional since Symfony 4.3 in | ||
the :method:`Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch`. | ||
noniagriconomie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Notice that the special ``OrderPlacedEvent`` object is created and passed to | ||
the ``dispatch()`` method. Now, any listener to the ``order.placed`` | ||
the ``dispatch()`` method. Now, any listener to the ``order.placed`` or the | ||
``Acme\Store\Event\OrderPlacedEvent`` (FQCN) | ||
event will receive the ``OrderPlacedEvent``. | ||
|
||
.. index:: | ||
|
@@ -390,7 +398,10 @@ Take the following example of a subscriber that subscribes to the | |
['onKernelResponsePre', 10], | ||
['onKernelResponsePost', -10], | ||
], | ||
// when using two arguments, the event and the event name | ||
OrderPlacedEvent::NAME => 'onStoreOrder', | ||
// when using only one argument, the event (since Symfony 4.3+) | ||
OrderPlacedEvent::class => 'onStoreOrder', | ||
Comment on lines
+401
to
+404
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds a bit confusing to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OskarStark I agree, but I do not know how I can document both in the same code snippet, or should I duplicate this code block? each one having one of the possible code behaviour? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. friendly ping @OskarStark @javiereguiluz do you have an idea on the way to document both in this code example? |
||
]; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.