Skip to content

Solo Event DispatcherPlain events. Predictable listeners.

A PSR-14 event dispatcher with priorities, subscribers and listeners matched by class, parent class or interface.

Solo Event Dispatcher

Register and dispatch ​

php
use Solo\EventDispatcher\EventDispatcher;
use Solo\EventDispatcher\ListenerProvider;

final readonly class OrderPlaced
{
    public function __construct(public int $orderId)
    {
    }
}

$listeners = new ListenerProvider();
$listeners->addListener(OrderPlaced::class, static function (OrderPlaced $event): void {
    echo "Reserving stock for order {$event->orderId}\n";
}, priority: 10);
$listeners->addListener(OrderPlaced::class, static function (OrderPlaced $event): void {
    echo "Sending the confirmation of order {$event->orderId}\n";
});

$dispatcher = new EventDispatcher($listeners);
$event = $dispatcher->dispatch(new OrderPlaced(42)); // the same object

An event is any object, and a listener is any callable that accepts it. Read the getting-started guide and the API reference for subscribers, stoppable events, failures and container wiring.

Installation ​

PHP 8.3+ is required. Composer installs psr/event-dispatcher ^1.0 and psr/log ^3.0 with the package.

sh
composer require solophp/event-dispatcher

Continue with the getting-started guide.

MIT licensed.