spiral/events
Spiral Events provides a lightweight event dispatcher for Spiral/PHP apps. Define events and listeners, publish events, and handle them synchronously with clean integration into the framework’s container and application lifecycle.
This package provides a PSR-14-compliant event dispatcher for Spiral Framework applications. Begin by installing via Composer (composer require spiral/events) and enabling the Spiral\Events\Events bootstrapper in your app’s bootstrap chain (typically via app.php config). The first use case is dispatching domain events—e.g., after a user registers—by creating an event class (e.g., UserRegistered) and calling $dispatcher->dispatch(new UserRegistered($user)).
class UserRegistered { public function __construct(public User $user) {} }). Use typed properties and avoid business logic in events.__invoke() methods (recommended) or handle() in listener classes, or use closures in newer PHP versions.config/bootloaders.php (Spiral-specific) or bind them in App::boot() using Events::listen(new UserRegistered, UserRegisteredListener::class).Spiral\Events\ListenerPriorityInterface—use getPriority() to control execution sequence.EventDispatcherInterface or use TestingEventDispatcher in unit tests; Spiral’s TestCase includes helper methods for event assertions.Bootloader pattern, override boot() to register listeners programmatically instead of relying solely on config files.spiral/jobs) for non-critical tasks to keep dispatch latency low.How can I help you explore Laravel packages today?