A simple but efficient way to deal with events.
[?] Why do we need events?
[!] EDP(http://en.wikipedia.org/wiki/Event-driven_programming)- it's an must be in parralel computations, but also a good way to add callbacks to any system/kernel thing we have to deal with.
The PHP most important changes are already here: closures and traits helps us to make impossible things.
This small event library is intendet to offer an KIS-y and cleany way to handle all your events using advanced PHP 5.4 and higher features
Each event should be first registered, ex.:
$eventsFactory = new Events\Factory::getInstance();
$event = $eventsFactory->getEvent('test');
Now you can add event handlers. Basicaly every event is an object that holds all it's handlers, data and state.
In any time you can stop the event propagnation by calling $event->stopPropagnation(). It's an efficient way to stop propagnation
while PHP works in blocking mode. Observers are stored in an priority queue(used \SplPriorityQueue container).
Observer can be also provided without any priority and it will be called in an logic way by the object fire method.
Store an observer:
$event->addObserver($callback); // first event registered in this way has priority 0, each after an decremented one[see __getMinDecrementValueBasedOnIniPrecision()]
// or with priority
The event is fired very simple:
// or even so
Event object can hold any property while they are generated by the Propertable trait methods(basicaly get|set used).
Initial provided data is stored in $data property of the event object.