72
72
73
73
When an event is dispatched, it's identified by a unique name (e.g.
74
74
``kernel.response ``), which any number of listeners might be listening to.
75
- An :class: `Symfony\\ Component \\ EventDispatcher\\ Event ` instance is also
75
+ An :class: `Symfony\\ Contracts \\ EventDispatcher\\ Event ` instance is also
76
76
created and passed to all of the listeners. As you'll see later, the ``Event ``
77
77
object itself often contains data about the event being dispatched.
78
78
@@ -161,7 +161,7 @@ The ``addListener()`` method takes up to three arguments:
161
161
So far, you've seen how PHP objects can be registered as listeners.
162
162
You can also register PHP `Closures `_ as event listeners::
163
163
164
- use Symfony\Component \EventDispatcher\Event;
164
+ use Symfony\Contracts \EventDispatcher\Event;
165
165
166
166
$dispatcher->addListener('acme.foo.action', function (Event $event) {
167
167
// will be executed when the acme.foo.action event is dispatched
@@ -172,7 +172,7 @@ is notified. In the above example, when the ``acme.foo.action`` event is dispatc
172
172
the dispatcher calls the ``AcmeListener::onFooAction() `` method and passes
173
173
the ``Event `` object as the single argument::
174
174
175
- use Symfony\Component \EventDispatcher\Event;
175
+ use Symfony\Contracts \EventDispatcher\Event;
176
176
177
177
class AcmeListener
178
178
{
@@ -252,7 +252,7 @@ order. Start by creating this custom event class and documenting it::
252
252
namespace Acme\Store\Event;
253
253
254
254
use Acme\Store\Order;
255
- use Symfony\Component \EventDispatcher\Event;
255
+ use Symfony\Contracts \EventDispatcher\Event;
256
256
257
257
/**
258
258
* The order.placed event is dispatched each time an order is created
@@ -281,7 +281,7 @@ Each listener now has access to the order via the ``getOrder()`` method.
281
281
282
282
If you don't need to pass any additional data to the event listeners, you
283
283
can also use the default
284
- :class: `Symfony\\ Component \\ EventDispatcher\\ Event ` class. In such case,
284
+ :class: `Symfony\\ Contracts \\ EventDispatcher\\ Event ` class. In such case,
285
285
you can document the event and its name in a generic ``StoreEvents `` class,
286
286
similar to the :class: `Symfony\\ Component\\ HttpKernel\\ KernelEvents `
287
287
class.
@@ -419,7 +419,7 @@ Now, any listeners to ``order.placed`` that have not yet been called will
419
419
*not * be called.
420
420
421
421
It is possible to detect if an event was stopped by using the
422
- :method: `Symfony\\ Component \\ EventDispatcher\\ Event::isPropagationStopped `
422
+ :method: `Symfony\\ Contracts \\ EventDispatcher\\ Event::isPropagationStopped `
423
423
method which returns a boolean value::
424
424
425
425
// ...
@@ -450,7 +450,7 @@ Dispatcher Shortcuts
450
450
~~~~~~~~~~~~~~~~~~~~
451
451
452
452
If you do not need a custom event object, you can rely on a plain
453
- :class: `Symfony\\ Component \\ EventDispatcher\\ Event ` object. You do not even
453
+ :class: `Symfony\\ Contracts \\ EventDispatcher\\ Event ` object. You do not even
454
454
need to pass this to the dispatcher as it will create one by default unless you
455
455
specifically pass one::
456
456
@@ -482,8 +482,8 @@ Event Name Introspection
482
482
The ``EventDispatcher `` instance, as well as the name of the event that
483
483
is dispatched, are passed as arguments to the listener::
484
484
485
- use Symfony\Component \EventDispatcher\Event;
486
- use Symfony\Component \EventDispatcher\EventDispatcherInterface;
485
+ use Symfony\Contracts \EventDispatcher\Event;
486
+ use Symfony\Contracts \EventDispatcher\EventDispatcherInterface;
487
487
488
488
class Foo
489
489
{
0 commit comments