fwk / events
Lightweight Event Dispatcher for Happy Developers
v2.0.0
2016-06-15 20:36 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-12-21 13:41:38 UTC
README
Event Dispatcher for PHP 5.4+
Installation
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
Documentation
Adding Listeners
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());
Removing Listeners
/* ... */ // 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"));
Trigger Events
/* ... */ $event = new Fwk\Events\Event("eventName", array( "someData" => "someValue" )); $event->extraData = "extraValue"; // dispatch event $evd->notify($event);
Contributions / Community
- Issues on Github: https://github.com/fwk/Events/issues
- Follow Fwk on Twitter: @phpfwk
Legal
Fwk is licensed under the 3-clauses BSD license. Please read LICENSE for full details.