Download the PHP package yiisoft/event-dispatcher without Composer
On this page you can find all versions of the php package yiisoft/event-dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yiisoft/event-dispatcher
More information about yiisoft/event-dispatcher
Files in yiisoft/event-dispatcher
Package event-dispatcher
Short Description Yii Event Dispatcher
License BSD-3-Clause
Homepage https://www.yiiframework.com/
Informations about the package event-dispatcher
Yii Event Dispatcher
PSR-14 compatible event dispatcher provides an ability to dispatch events and listen to events dispatched.
Features
- PSR-14 compatible.
- Simple and lightweight.
- Encourages designing event hierarchy.
- Can combine multiple event listener providers.
Requirements
- PHP 8.0 or higher.
Installation
The package could be installed with Composer:
General usage
The library consists of two parts: event dispatcher and event listener provider. Provider's job is to register listeners for a certain event type. Dispatcher's job is to take an event, get listeners for it from a provider and call them sequentially.
The event dispatching may look like:
Stoppable events
Event could be made stoppable by implementing Psr\EventDispatcher\StoppableEventInterface
:
This way we can ensure that only first event listener will be able to handle the event. Another option is to allow stopping propagation in one of the listeners by providing corresponding event method.
Events hierarchy
Events do not have any name or wildcard matching on purpose. Event class names and class/interface hierarchy and composition could be used to achieve great flexibility:
With the interface above listening to all document-related events could be done as:
Combining multiple listener providers
In case you want to combine multiple listener providers, you can use CompositeProvider
:
Register listeners with concrete event names
You may use a more simple listener provider, which allows you to specify which event they can provide.
It can be useful in some specific cases, for instance if one of your listeners does not need the event object passed as a parameter (can happen if the listener only needs to run at a specific stage during runtime, but does not need event data).
In that case, it is advised to use the aggregate (see above) if you need features from both providers included in this library.
Dispatching to multiple dispatchers
There may be a need to dispatch an event via multiple dispatchers at once. It could be achieved like the following:
Documentation
- Internals
If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.
License
The Yii Event Dispatcher is free software. It is released under the terms of the BSD License.
Please see LICENSE
for more information.
Maintained by Yii Software.
Credits
- Larry Garfield (@crell) for initial implementation of deriving callable parameter type.