Simple event listeners with Closures.
$listeners = new EventListeners();
$listeners->addBefore('save', function ($target) {
// ...
});
$listeners->addAfter('delete', function ($target) {
// ...
});
$listeners->dispatchEvent('save', $target);
$listeners->dispatchEvent('delete', $target);
A very simple manager object that holds all the appropriate events, and allows you to dispatch these events later.
This trait gives you the ability to easily add eventlisteners to another object.
class TestConfig {
use EventListenersTrait;
}
$config = new TestConfig();
$config
->addEventBefore('delete', function () {
// ...
})
->addEventAfter('validate', function () {
});
// Return the EventListeners object
$config->getEventListeners();
Here are all the methods added by this trait.
Method | Description |
---|---|
getEventListeners() | Get the EventListeners object |
addEventBefore($name, $closure) | Add a "before" listener |
addEventAfter($name, $closure) | Add a "after" listener |
Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin
Under BSD-3-Clause license, read LICENSE file.