Rudra-EventDispatcher | API
composer require rudra/event-dispatcher
use Rudra\EventDispatcher\EventDispatcherFacade as Dispatcher;Dispatcher::addListener('app.listener', [AppListener::class, 'onEvent']);
Dispatcher::addListener('app.closure', function () {
Rudra::config()->set(["closure" => "closure"]);
});
Dispatcher::addListener('before', [new TestController(), 'before']);Dispatcher::dispatch('app.listener', 123);
// For Closure listeners, dispatch returns the Closure itself
$closure = Dispatcher::dispatch('app.closure');
$closure();
Dispatcher::dispatch('before');Dispatcher::attachObserver("before", [TestController::class, "before"]);
Dispatcher::attachObserver("closure", ['closure', function () {
Rudra::config()->set(['closure' => "closure"]);
}]);
$test = new TestController();
Dispatcher::attachObserver("subscriberObject", [$test, "subscriberObject"], 123);Dispatcher::detachObserver("before", TestController::class);Dispatcher::notify("before");
Dispatcher::notify("closure");
Dispatcher::notify("subscriberObject");Dispatcher::getListeners();
Dispatcher::getObservers();This project is licensed under the Mozilla Public License 2.0 (MPL-2.0) — a free, open-source license that:
- Requires preservation of copyright and license notices,
- Allows commercial and non-commercial use,
- Requires that any modifications to the original files remain open under MPL-2.0,
- Permits combining with proprietary code in larger works.
📄 Full license text: LICENSE
🌐 Official MPL-2.0 page: https://mozilla.org/MPL/2.0/