Download the PHP package aesonus/events without Composer
On this page you can find all versions of the php package aesonus/events. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package events
Events
A simple Event, Listener,and Dispatcher
Tests
phpunit
How to use
Create a dispatcher
Extend the base event class for each of your events:
Implement listener interface for each of your events and listeners
Implement the handle method in listener to do a specific task:
Attach listeners to event(s) in a queue:
You can assign priorities to listeners as well. The default priority is 0.
You can attach multiple listeners using an array.
Each listener attached will be assigned the given priority:
Note that if the listeners all have the same priority, the queue will start at the first element of the first attached listener(s). Consider the following code:
When this event is dispatched, the first listener to receive the event will be MyListenerA.
You can also override the default priority by passing the listener in a numbered array with the element at index 0 is the listener and the element at index 1 is the priority:
Please note that all priorities must be integers. Priorities provided through the array interface that are not integers will be set to the default priority.
Register events with dispatcher
Dispatch events with class name. This will call the handle method on each listener in the priority queue.
You can also dispatch an event without the help of a dispatcher:
The dispatch queue can be interrupted by an exception and resume where it left off.
The dispatch queue may also be reset to the state it was in just before dispatch() is called:
It is important to note that resuming execution of the event queue will change the cached copy of the queue. Use resumability with care.