Skip to content

Commit 3603d53

Browse files
committed
minor #11856 fix the event dispatcher signature (xabbuh)
This PR was merged into the 4.3 branch. Discussion ---------- fix the event dispatcher signature Commits ------- 33e2201 fix the event dispatcher signature
2 parents 3f15a51 + 33e2201 commit 3603d53

File tree

5 files changed

+12
-42
lines changed

5 files changed

+12
-42
lines changed

components/event_dispatcher.rst

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ Dispatch the Event
291291

292292
The :method:`Symfony\\Component\\EventDispatcher\\EventDispatcher::dispatch`
293293
method notifies all listeners of the given event. It takes two arguments:
294-
the name of the event to dispatch and the ``Event`` instance to pass to
295-
each listener of that event::
294+
the ``Event`` instance to pass to each listener of that event and the name
295+
of the event to dispatch and ::
296296

297297
use Acme\Store\Event\OrderPlacedEvent;
298298
use Acme\Store\Order;
@@ -303,7 +303,7 @@ each listener of that event::
303303

304304
// creates the OrderPlacedEvent and dispatches it
305305
$event = new OrderPlacedEvent($order);
306-
$dispatcher->dispatch(OrderPlacedEvent::NAME, $event);
306+
$dispatcher->dispatch($event, OrderPlacedEvent::NAME);
307307

308308
Notice that the special ``OrderPlacedEvent`` object is created and passed to
309309
the ``dispatch()`` method. Now, any listener to the ``order.placed``
@@ -423,7 +423,7 @@ It is possible to detect if an event was stopped by using the
423423
method which returns a boolean value::
424424

425425
// ...
426-
$dispatcher->dispatch('foo.event', $event);
426+
$dispatcher->dispatch($event, 'foo.event');
427427
if ($event->isPropagationStopped()) {
428428
// ...
429429
}
@@ -441,36 +441,6 @@ name and a reference to itself to the listeners. This can lead to some advanced
441441
applications of the ``EventDispatcher`` including dispatching other events inside
442442
listeners, chaining events or even lazy loading listeners into the dispatcher object.
443443

444-
.. index::
445-
single: EventDispatcher; Dispatcher shortcuts
446-
447-
.. _event_dispatcher-shortcuts:
448-
449-
Dispatcher Shortcuts
450-
~~~~~~~~~~~~~~~~~~~~
451-
452-
If you do not need a custom event object, you can rely on a plain
453-
:class:`Symfony\\Contracts\\EventDispatcher\\Event` object. You do not even
454-
need to pass this to the dispatcher as it will create one by default unless you
455-
specifically pass one::
456-
457-
$dispatcher->dispatch('order.placed');
458-
459-
Moreover, the event dispatcher always returns whichever event object that
460-
was dispatched, i.e. either the event that was passed or the event that
461-
was created internally by the dispatcher. This allows for nice shortcuts::
462-
463-
if (!$dispatcher->dispatch('foo.event')->isPropagationStopped()) {
464-
// ...
465-
}
466-
467-
Or::
468-
469-
$event = new OrderPlacedEvent($order);
470-
$order = $dispatcher->dispatch('bar.event', $event)->getOrder();
471-
472-
and so on.
473-
474444
.. index::
475445
single: EventDispatcher; Event name introspection
476446

components/event_dispatcher/generic_event.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Passing a subject::
5353
use Symfony\Component\EventDispatcher\GenericEvent;
5454

5555
$event = new GenericEvent($subject);
56-
$dispatcher->dispatch('foo', $event);
56+
$dispatcher->dispatch($event, 'foo');
5757

5858
class FooListener
5959
{
@@ -74,7 +74,7 @@ access the event arguments::
7474
$subject,
7575
['type' => 'foo', 'counter' => 0]
7676
);
77-
$dispatcher->dispatch('foo', $event);
77+
$dispatcher->dispatch($event, 'foo');
7878

7979
class FooListener
8080
{
@@ -93,7 +93,7 @@ Filtering data::
9393
use Symfony\Component\EventDispatcher\GenericEvent;
9494

9595
$event = new GenericEvent($subject, ['data' => 'Foo']);
96-
$dispatcher->dispatch('foo', $event);
96+
$dispatcher->dispatch($event, 'foo');
9797

9898
class FooListener
9999
{

components/event_dispatcher/traceable_dispatcher.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ to register event listeners and dispatch events::
3838

3939
// dispatches an event
4040
$event = ...;
41-
$traceableEventDispatcher->dispatch('event.the_name', $event);
41+
$traceableEventDispatcher->dispatch($event, 'event.the_name');
4242

4343
After your application has been processed, you can use the
4444
:method:`Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcherInterface::getCalledListeners`

create_framework/event_dispatcher.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ the Response instance::
7676
}
7777

7878
// dispatch a response event
79-
$this->dispatcher->dispatch('response', new ResponseEvent($response, $request));
79+
$this->dispatcher->dispatch(new ResponseEvent($response, $request), 'response');
8080

8181
return $response;
8282
}
@@ -88,9 +88,9 @@ now dispatched::
8888
// example.com/src/Simplex/ResponseEvent.php
8989
namespace Simplex;
9090

91-
use Symfony\Component\EventDispatcher\Event;
9291
use Symfony\Component\HttpFoundation\Request;
9392
use Symfony\Component\HttpFoundation\Response;
93+
use Symfony\Contracts\EventDispatcher\Event;
9494

9595
class ResponseEvent extends Event
9696
{

event_dispatcher/method_behavior.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ method::
1919
{
2020
// dispatch an event before the method
2121
$event = new BeforeSendMailEvent($subject, $message);
22-
$this->dispatcher->dispatch('mailer.pre_send', $event);
22+
$this->dispatcher->dispatch($event, 'mailer.pre_send');
2323

2424
// get $foo and $bar from the event, they may have been modified
2525
$subject = $event->getSubject();
@@ -30,7 +30,7 @@ method::
3030

3131
// do something after the method
3232
$event = new AfterSendMailEvent($returnValue);
33-
$this->dispatcher->dispatch('mailer.post_send', $event);
33+
$this->dispatcher->dispatch($event, 'mailer.post_send');
3434

3535
return $event->getReturnValue();
3636
}

0 commit comments

Comments
 (0)