switon / event
Class-based synchronous PSR-14 dispatch with attribute-discovered listeners for Switon Framework
v1.0.0
2026-06-06 13:43 UTC
Requires
- php: >=8.3
- psr/event-dispatcher: ^1.0
- psr/log: ^2.0
- switon/composer-extra: ^1.0
- switon/core: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12.0
README
Switon's PSR-14 event package for application dispatch, listener discovery, and event logging.
Highlights
- Wildcard listeners: one listener can handle every event with
object. - Attribute-based listeners:
#[EventListener]registers listener methods. - Automatic listener discovery: app scan paths and
extra.switon.listenersentries are included. - Event log level: events can carry a default PSR-3 level.
- Early-stop support: listeners can halt the remaining chain when needed.
- Automatic event logging: events can be logged automatically with structured output.
Installation
composer require switon/event
Quick Start
use Psr\EventDispatcher\EventDispatcherInterface; use Switon\Core\Attribute\Autowired; use Switon\Eventing\Attribute\EventListener; final class UserRegistered { public function __construct(public int $userId, public string $email) { } } class UserService { #[Autowired] protected EventDispatcherInterface $eventDispatcher; public function register(string $email): void { $this->eventDispatcher->dispatch(new UserRegistered(123, $email)); } } class UserListener { #[EventListener] public function onUserRegistered(UserRegistered $event): void { // react to the event } }
Docs: https://docs.switon.dev/latest/event
License
MIT.