kuick / event-dispatcher
Kuick Event is a slim PSR-14 Event Dispatcher implementation
v1.1.2
2025-01-14 20:17 UTC
README
PSR-14 Event Dispatcher lightweight implementation
Key features
- Full PSR-14 compatibility
- Easy to use listener registration
- Listener prioritization
- Support for wildcard listeners (ie. , Prefix)
Examples
- Registering listeners to the listener provider
<?php
use Kuick\Event\EventDispatcher;
use Kuick\Event\ListenerProvider;
$provider = new ListenerProvider();
$provider->registerListener(
'some class name or pattern',
function () {
//handle the event
}
);
$dispatcher = new EventDispatcher($provider);
// $dispatcher->dispatch(new SomeEvent());
- Listener prioritization (using stdClass as an event)
<?php
use stdClass;
use Kuick\Event\EventDispatcher;
use Kuick\Event\ListenerPriority;
use Kuick\Event\ListenerProvider;
$provider = new ListenerProvider();
$provider->registerListener(
stdClass::class,
function (stdClass $event) {
//handle the event
},
ListenerPriority::HIGH
);
$provider->registerListener(
stdClass::class,
function (stdClass $event) {
//handle the event
},
ListenerPriority::LOW
);
$dispatcher = new EventDispatcher($provider);
// it should handle the event with high priority listener first
$dispatcher->dispatch(new stdClass());
- Registering wildcard listeners (using stdClass as an event)
<?php
use stdClass;
use Kuick\Event\EventDispatcher;
use Kuick\Event\ListenerProvider;
$provider = new ListenerProvider();
$provider->registerListener(
'*',
function (object $event) {
//handle the event
}
);
$provider->registerListener(
'std*',
function (object $event) {
//handle the event
}
);
$dispatcher = new EventDispatcher($provider);
// it should match both listeners and run them sequentialy
$dispatcher->dispatch(new stdClass());