Download the PHP package aatis/event-dispatcher without Composer
On this page you can find all versions of the php package aatis/event-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package event-dispatcher
Aatis ED
Advertisement
This package is a part of Aatis
and can't be used without the following packages :
aatis/dependency-injection
(https://github.com/BatMaxou/aatis-DI)
Installation
Usage
Requirements
Add the EventDispatcher
service to the Container
:
Event
This package provides an abstract Event
class that can be extended to create custom events like the following :
StoppableEvent
This package provides also an abstract StoppableEvent
class that can be extended to create custom stoppable events like the following :
This class implements a custom StoppableEventInterface
that extends the Psr\EventDispatcher\StoppableEventInterface
.
So, with this class, you can access 2 specific methods :
isPropagationStopped
that returns a boolean to know if the event propagation is stoppedstopPropagation
that set the propagation tofalse
, it must be called into a listener or a subscriber method
Priority
The EventDispatcher
service can dispatch events with a priority amount that is an integer. The higher the priority, the earlier the event will be dispatched.
If two listeners have the same priority for the same event, the order of execution is for this two listeners is random.
By default, the priority is set to 0
.
EventListener
A listener is a class that can be called when an event is dispatched. It must contains a __invoke
method with only one parameter that must be the event listened.
Example of a listener targeting the ExampleEvent
:
You can specify the priority of a listener by attaching a EventListener
attribute to the class with a priority
parameter :
Finally, you must inform the container that this class is a listener by adding the event-listener
tag to the service :
EventSubscriber
A subscriber is a class that contains multiple listener methods and subscibe to several events.
It must provide a getSubscribedEvents
method that returns the array of the events to which the service subscribes and their associated listener method.
Example of a subscriber :
You can also specify multiple listeners for the same event by passing an array instead :
For the priority, you can also pass an array with the listener method and the priority as an integer :
All versions of event-dispatcher with dependencies
php Version >=8.2
aatis/dependency-injection Version ^1.5