- Is yiisoft/event-dispatcher compatible with Laravel?
- It is a framework-agnostic PSR-14 dispatcher, so it can be installed in a Laravel app, but it does not ship a Laravel service provider, facade, or auto-discovery. You must wire it manually as a singleton and implement a listener provider that resolves listeners through Laravel's container. It is best treated as a narrow PSR-14 boundary rather than a replacement for Laravel's native event system.
- Can I replace Laravel's event dispatcher with yiisoft/event-dispatcher?
- No, not as a drop-in replacement. Laravel's dispatcher provides queued events, broadcasting, wildcard listeners, subscribers, testing fakes, and framework lifecycle integration that yiisoft/event-dispatcher does not supply. Use it only where a real PSR-14 producer or consumer requires interoperability, and keep Laravel's dispatcher as the primary event backbone.
- How do I install yiisoft/event-dispatcher in a Laravel project?
- Install it with Composer using composer require yiisoft/event-dispatcher, then verify that its PSR-14 constraints do not conflict with your Laravel and PHP versions. Because there is no Laravel package auto-discovery, you will need to register the dispatcher and listener provider yourself in a service provider. Pin the version and add adapter tests before using it in production.
- How do I register yiisoft/event-dispatcher as a singleton in Laravel?
- Create your own service provider and bind the PSR-14 dispatcher interface or the concrete dispatcher to a singleton. Inside the binding, instantiate the dispatcher with a listener provider that you control. This keeps one event bus for the PSR-14 boundary and avoids creating multiple dispatcher instances across requests or workers.
- How do I resolve PSR-14 listeners through Laravel's container?
- Implement the PSR-14 ListenerProviderInterface and use Laravel's container to resolve listener class names or callables. Your provider should map event class names to listener definitions, then call app()->make() or an injected container when the dispatcher requests listeners for an event. Write tests for listener ordering, missing listener behavior, and exception propagation.
- Does yiisoft/event-dispatcher support queued or async listeners in Laravel?
- No. The dispatcher is synchronous and in-process by design, so it does not provide queueing, retries, backoff, or async execution. If you need failure-sensitive or high-volume workflows, use Laravel's queued events or a dedicated message bus instead. You can still dispatch a Laravel job from a PSR-14 listener if that fits your architecture.
- What PHP and Laravel versions does yiisoft/event-dispatcher support?
- The package is framework-agnostic and does not publish Laravel-specific version support, so you must verify Composer constraints against your target PHP and Laravel versions. The last release was in October 2022, which raises compatibility and maintenance concerns for newer Laravel releases. Run a proof of concept and dependency audit before committing to it.
- How should I test a yiisoft/event-dispatcher adapter in Laravel?
- Write adapter tests for event identity, listener ordering, exception behavior, and payload immutability, as recommended for a PSR-14 boundary. Also test that listeners resolve correctly through Laravel's container and that the dispatcher is a singleton. Include a failure-mode test to confirm whether listener exceptions propagate into requests or queue workers.
- Is yiisoft/event-dispatcher actively maintained?
- It has low community visibility, around 73 GitHub stars, and its last release was 2022-10-27, so upstream activity appears limited. The code risk is relatively low because PSR-14 is a small, stable contract and the BSD-3-Clause license is permissive, but support and patch cadence are uncertain. Pin the version, monitor advisories, and keep an internal fork or replacement plan.
- What are alternatives to yiisoft/event-dispatcher for PSR-14 in Laravel?
- Laravel's built-in dispatcher is the best default for framework events, queues, broadcasting, and testing. If you specifically need PSR-14 interoperability, evaluate other maintained PSR-14 dispatchers or write a thin adapter around Laravel's dispatcher. The key decision is whether a dependency truly mandates PSR-14, not whether the package is popular.