A strict PSR-14 implementation built with simplicity in mind.
The main goal behind this library is to be a strict implementation of the PSR-14.
This library is not available on composer yet...
Here is a quick example to show you how to use it :
<?php
use App\Event\UserLoggedIn;
use Lium\EventDispatcher\EventDispatcher;
use Lium\EventDispatcher\ListenerProvider\DefaultListenerProvider;
// Listeners definitions
$listenerCalledForEveryEvent = function (object $event) {
// This listener will match all events because its argument has the scalar type "object"
echo sprintf('A listener has been called with the event "%s".', get_class($event));
};
$updateUserLastLoginDate = function (UserHasLoggedIn $event) {
$user = $event->getUser();
echo sprintf('The user "%s" has logged in.', $user->getUsername());
};
// Initialization
$listenerProvider = new DefaultListenerProvider([
$listenerCalledForEveryEvent,
$updateUserLastLoginDate,
]);
$eventDispatcher = new EventDispatcher($listenerProvider);
// Later in your code...
$eventDispatcher->dispatch(new UserHasLoggedIn($user));
The previous example will output :
A listener has been called with the event "App\Event\UserLoggedIn".
The user "johndoe" has logged in.
You can check the examples directory to see more examples.
See the CONTRIBUTING file.
This project is available with the MIT license. For the full copyright, thanks to read the license file.