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 4 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
13 changes: 12 additions & 1 deletion components/event_dispatcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

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::
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds a bit confusing to me

cc @javiereguiluz

Copy link
Contributor Author

@noniagriconomie noniagriconomie Apr 22, 2021

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?
thanks :)

];
}

Expand Down