Event Dispatcher for PHP 5.4+
Via Composer:
{
"require": {
"fwk/events": "dev-master",
}
}
If you don't use Composer, you can still download this repository and add it
to your include_path
PSR-0 compatible
use Fwk\Events\Dispatcher,
Fwk\Events\Event;
$evd = new Dispatcher();
// closures listeners
$evd->on("eventName", function(Fwk\Events\Event $event) {
// do some stuff
});
// Class methods starting by "on[EventCamelCasedName]" can also be added as
// listeners
class MyListener
{
public function onEventName(Fwk\Events\Event $event) {
// do some stuff
}
}
$evd->addListener(new MyListener());
/* ... */
// this removes all listeners for a given event
$evd->removeAllListeners("eventName");
// this removes a listener (callable) for a given event
$evd->removeListener("eventName", array($listener, "onListenerMethod"));
/* ... */
$event = new Fwk\Events\Event("eventName", array(
"someData" => "someValue"
));
$event->extraData = "extraValue";
// dispatch event
$evd->notify($event);
- Issues on Github: https://github.com/fwk/Events/issues
- Follow Fwk on Twitter: @phpfwk
Fwk is licensed under the 3-clauses BSD license. Please read LICENSE for full details.