nimp / observer
minimal realization lets the text editor object notify other service objects about changes in its state
v1.0.4
2025-09-29 14:39 UTC
Requires
- php: >=8.3
- psr/event-dispatcher: 1.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.2
README
Minimalistic implementation of event dispatching according to PSR-14: EventDispatcher + ListenerProvider.
Installation
composer require nimp/observer
Quick start
final class MyListener implements EventListenerInterface { public function events(): iterable { yield StartedEvent::class => $this->onStarted(...); yield MyEvent::class => 'onMyEvent'; yield MyStoppableEvent::class => function (MyStoppableEvent $e): void { // handle and stop propagation if needed $e->stop(); }; } public function onStarted(StartedEvent $event): void { // handle StartedEvent } public function onMyEvent(object $event): void { // handle MyEvent } } $provider = new ListenerProvider(); $provider->addListeners(new MyListener()); $dispatcher = new EventDispatcher($provider);
Tests
composer install && composer test