psr/event-dispatcher
PSR-14 interfaces for event dispatching in PHP. Defines standard contracts for dispatchers, listeners, and providers to enable interoperability between frameworks and libraries. Not an implementation—use a compatible PSR-14 dispatcher package.
Architecture fit: The package provides standardized interfaces for event handling, enabling strict decoupling between components and frameworks. It fits modern microservices or polyglot architectures by allowing consistent event communication across diverse services (e.g., Laravel, Symfony, custom systems) without vendor lock-in. Ideal for scenarios requiring third-party library interoperability or multi-framework integration.
Integration feasibility: High feasibility for PHP projects using PSR-14-compliant implementations (e.g., Laravel 8+, Symfony). Requires installing a concrete dispatcher (e.g., symfony/event-dispatcher) alongside the interfaces. Integration is trivial in Laravel due to native PSR-14 support but demands careful dependency management for non-standard setups.
Technical risk: Low for core functionality but high for misuse—teams may install only the interface package without a dispatcher implementation, causing runtime errors. Secondary risks include inconsistent event handling across teams if implementations diverge (e.g., synchronous vs. async dispatchers), and legacy system incompatibility if existing event logic relies on non-PSR patterns.
Key questions:
StoppableEventInterface/ListenerProviderInterface across teams?Stack fit: Perfect for Laravel stacks (v8+), as its Event facade and EventServiceProvider natively implement PSR-14. Also compatible with Symfony, Laminas, and custom PHP applications. Fits monolithic or microservice architectures where event-driven communication between services is required.
Migration path:
psr/event-dispatcher and a dispatcher implementation (e.g., symfony/event-dispatcher).Illuminate\Contracts\Events\Dispatcher type-hints with Psr\EventDispatcher\EventDispatcherInterface in new services.Psr\EventDispatcher\ListenerProviderInterface or use __invoke-based listeners.Event::listen() calls in favor of PSR-compliant dispatching patterns.Compatibility: Fully compatible with PHP 7.2+ and all PSR-14-compliant frameworks. Works alongside Laravel’s native event
How can I help you explore Laravel packages today?