Skip to content
This repository has been archived by the owner on Dec 9, 2019. It is now read-only.

hermann8u/helium-event-dispatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lium event dispatcher component

A strict PSR-14 implementation built with simplicity in mind.

Why?

The main goal behind this library is to be a strict implementation of the PSR-14.

Installation

This library is not available on composer yet...

Usage

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.

Contributing

See the CONTRIBUTING file.

License

This project is available with the MIT license. For the full copyright, thanks to read the license file.

Releases

No releases published

Packages

No packages published

Languages