innmind/event-bus

This package is abandoned and no longer maintained. No replacement package was suggested.

Event dispatcher library

4.1.0 2021-02-06 09:54 UTC

This package is auto-updated.

Last update: 2022-12-12 08:11:33 UTC


README

Build Status codecov Type Coverage

Simple library to dispatch events to listeners; with the particularity that you can't order your listeners, listeners can't modify the event, listeners can't stop other listeners to be called and the event must be an object.

Instalation

composer require innmind/event-bus

Example

use function Innmind\EventBus\bootstrap;
use Innmind\Immutable\Map;

class MyEvent{}

$echo = function(MyEvent $event): void {
    echo 'foo';
};

$dispatch = bootstrap()['bus'](
    Map::of('string', 'callable')
        (MyEvent::class, $echo)
);

$dispatch(new MyEvent); // will print "foo"

All listeners must be callables and can listen to a specific class, a parent class or an interface.