Download the PHP package tobento/service-event without Composer
On this page you can find all versions of the php package tobento/service-event. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/service-event
More information about tobento/service-event
Files in tobento/service-event
Package service-event
Short Description A PSR-14 event dispatcher with autowiring support.
License MIT
Homepage https://www.tobento.ch
Informations about the package service-event
Event Service
A PSR-14 event dispatcher with autowiring support.
Table of Contents
- Getting started
- Requirements
- Highlights
- Simple Example
- Documentation
- Listeners
- Create Listeners
- Defining And Add Listener
- Retrieve Listeners
- Dispatcher
- Create Dispatcher
- Dispachting Events
- Events
- Create Events
- Add Listeners
- Dispatch Events
- Supporting Events
- Listeners
- Credits
Getting started
Add the latest version of the event service running this command.
Requirements
- PHP 8.0 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
- Autowiring support
Simple Example
Here is a simple example of how to use the Event service.
Using Events
Documentation
Listeners
The listeners class uses reflection to scan listeners for its events.
Create Listeners
Using Autowiring
You might want to use autowiring for creating your listeners.
Defining And Add Listener
As the listeners class uses reflection to scan listeners for its events named $event, there is no need to define its event(s) when adding a listener. But you might do so if you have multiple events in your listener and want only to listen for the specific events.
Class using invoke
Class defining multiple events to listen
Using closure
Prioritize
You might prioritize listeners by the following way:
Add a custom listener
You might add a custom listener by implementing the following interface:
Retrieve Listeners
Dispatcher
Create Dispatcher
Using Autowire
You might set a container for autowiring events methods. This will break PSR-14 definition although.
Dispatching Events
Events
Create Events
Using the events factory
Using the autowiring events factory
Add Listeners
Using listen method
Using listeners method
For more detail see Defining And Add Listener
Dispatch Events
Supporting Events
You might use the HasEvents trait with the EventsAware interface for any classes supporting events.
Credits
- Tobias Strub
- All Contributors
All versions of service-event with dependencies
psr/event-dispatcher Version ^1.0
psr/container Version ^2.0
tobento/service-autowire Version ^1.0