A PSR-14 Event Dispatcher implementation
composer req talesoft/tale-event
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!"