talesoft/tale-event

A PSR-14 implementation

0.3.0 2020-03-11 20:30 UTC

This package is auto-updated.

Last update: 2024-11-12 07:07:45 UTC


README

Packagist License CI Coverage

Tale Event

What is Tale Event?

A PSR-14 Event Dispatcher implementation

Installation

composer req talesoft/tale-event

Usage

use Tale\Event\ListenerProvider\ReflectionListenerProvider;
use Tale\EventDispatcher;

$provider = new ReflectionListenerProvider();
$dispatcher = new EventDispatcher($provider);

class MyEvent
{
    private $message = '';
    
    public function setMessage(string $message): void
    {
        $this->message = $message;
    }
    
    public function getMessage(): string
    {
        return $this->message;
    }
}

$provider->addListener(function (MyEvent $event) {
    $event->setMessage('Hello from listener!');
});

$event = new MyEvent();
$dispatcher->dispatch($event);
echo $event->getMessage(); // "Hello from listener!"