scabbiafw / scabbia2-events
This package is abandoned and no longer maintained.
The author suggests using the eserozvataf/scabbia2-events package instead.
Scabbia2 Events Component
v0.1.2
2015-09-16 02:34 UTC
Requires
- php: >=5.6.0
Requires (Dev)
This package is not auto-updated.
Last update: 2022-02-01 12:51:15 UTC
README
This component is a simple event dispatcher allows registering callbacks to some events and chain execution of them.
Usage
Delegates
use Scabbia\Events\Delegate; $delegate = new Delegate(); $delegate->subscribe(function (...$parameters) { echo 'first subscriber:'; var_dump($parameters); }); $delegate->subscribe(function (...$parameters) { echo 'second subscriber:'; echo count($parameters); }); $delegate->invoke('a', 'b', 'c');
Delegates with priorities
use Scabbia\Events\Delegate; $delegate = new Delegate(); // a subscription with priority = 300 $delegate->subscribe(function (...$parameters) { echo 'first subscriber:'; var_dump($parameters); }, null, 300); // a subscription with priority = 1 (will be executed first) $delegate->subscribe(function (...$parameters) { echo 'second subscriber, but more important:'; echo count($parameters); }, null, 1); $delegate->invoke('a', 'b', 'c');
Delegates with breaking
use Scabbia\Events\Delegate; $delegate = new Delegate(); $delegate->subscribe(function (...$parameters) { echo 'first subscriber:'; var_dump($parameters); // breaks the execution return false; }); $delegate->subscribe(function (...$parameters) { echo 'second subscriber, but not going to be executed:'; echo count($parameters); }); $delegate->invoke('a', 'b', 'c');
Events
use Scabbia\Events\Events; $eventsManager = new Events(); $eventsManager->on('click', function (...$parameters) { echo "clicked on x={$parameters[0]} and y={$parameters[1]}!"; }); $eventsManager->on('double_click', function (...$parameters) { echo 'double clicked!'; }); $eventsManager->dispatch('click', 5, 10);
Links
Contributing
It is publicly open for any contribution. Bugfixes, new features and extra modules are welcome. All contributions should be filed on the eserozvataf/scabbia2-events repository.