mj-zana / events
PSR-14 event dispatcher with lazily resolved listeners for Zana applications
v2.1.0
2026-10-25 20:32 UTC
Requires
- php: ^8.5
- mj-zana/core: ^2.0
- psr/container: ^2.0
- psr/event-dispatcher: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-25 20:42:37 UTC
README
A PSR-14 event dispatcher whose listeners are resolved lazily from the container. Requires PHP 8.5 or later.
composer require mj-zana/events
Usage
Register EventsServiceProvider, then add listeners in a module's boot():
public function boot(ContainerInterface $container): void { $container->get(ListenerProvider::class) ->listen(PatientRegistered::class, SendWelcomeMail::class) // invokable class, resolved on first dispatch ->listen(PatientRegistered::class, [AuditTrail::class, 'record'], priority: 10) ->addListenerClass(UpdateStatistics::class) // #[AsListener] ->addSubscriber(PatientNotifications::class); // EventSubscriberInterface }
$dispatcher->dispatch(new PatientRegistered($id)); $dispatcher->dispatchAll($patient->releaseEvents()); // domain events from an aggregate
- Matching: a listener for a class or interface receives instances of it, including subclasses.
- Order: higher priority runs first; at equal priority, registration order.
- Stopping: events extending
StoppableEventcan stop propagation. - Exceptions thrown by listeners propagate to the caller.
License
MIT — see LICENSE.