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

This package is auto-updated.

Last update: 2025-09-29 20:11:25 UTC


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