vakata / events
A minimal PHP event dispatcher
1.0.1
2023-12-05 11:01 UTC
Requires
- php: >=8.0
README
A minimal PHP event dispatcher.
Install
Via Composer
$ composer require vakata/events
Usage
// create a dispatcher $dispatcher = new \vakata\events\Dispatcher(); // listen for various events and/or namespaces $dispatcher->listen('eventName', function () { }) $dispatcher->listen('eventName.namespace', function () { }); $dispatcher->listen('*.namespace', function () { }); $dispatcher->listen('*', function (EventInterface $event) { $event->stopPropagation(); var_dump( $event->getName(), $event->getNamespaces(), $event->getPayload(), $event->isPropagationStopped() ); }); // create an event $event = new \vakata\events\Event("eventName", [ 'pay' => 'load' ]); // dispatch the event (listeners are called immediately) $dispatcher->dispatch($event); // the event can also be dispatched in a lazy fashion (listeners are called after `run`) $dispatcher->dispatch($event, true); // dispatch lazy events $dispatcher->run();
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email github@vakata.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.