codin/events

PSR-14 Event dispatcher

1.0.0 2022-12-16 10:22 UTC

This package is auto-updated.

Last update: 2024-12-16 14:44:45 UTC


README

version workflow license

PSR-14 Compatible event dispatcher

Usage

class MyListener implements \Psr\EventDispatcher\ListenerProviderInterface
{
    public function getListenersForEvent(object $event) : iterable
    {
        yield static function (MyEvent $event) {
            echo "$event->message\n";
        };
    }
}

class MyEvent {
    public string $message = 'Hello World';
}

$dispatcher = new Codin\Events\EventDispatcher();
$dispatcher->registerListener(new MyListener());
$dispatcher->dispatch(new MyEvent());