Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

League Event Laravel Package

spiral-packages/league-event

Spiral Framework bridge for The League Event dispatcher. Provides an EventBootloader to wire PSR-style event dispatching, define event classes, and register listeners via attributes or config. Requires PHP 8.1+ and Spiral 3.0+.

View on GitHub
Deep Wiki
Context7

Getting Started

Begin by installing the package via Composer (composer require spiral-packages/league-event) and enabling the provider in app/src/Kernel.php (typically via Spiral\Packages\Event\EventBootloader). Once registered, the dispatcher is available in the DI container as League\Event\EventDispatcherInterface. Your first use case is dispatching a simple domain event (e.g., UserRegistered) and wiring up a listener to send a welcome email — no manual handler instantiation needed.

Implementation Patterns

  • Listener Registration: Use attribute-based auto-discovery via #[Listener] on handler methods or configure listeners in config/event.php (e.g., mapping event classes to handler services).
  • Event Classes: Define immutable event objects (e.g., class OrderShipped { public $orderId; }); type-hint the event in listener signatures for strict binding.
  • Dispatching: Inject EventDispatcherInterface into services/controllers and call $dispatcher->dispatch(new UserRegistered($user));.
  • Middleware Integration: Use event listeners to decouple cross-cutting concerns (e.g., logging, metrics) from controller logic.
  • Testing: Mock EventDispatcherInterface or assert dispatched events using event collectors in unit tests.

Gotchas and Tips

  • Listener Resolution: Ensure handlers are registered as services in the container (e.g., via Spiral\Core\Interceptor\InterceptorInterface support) — class names alone won’t be resolved automatically.
  • Event Name Conflicts: League\Event uses fully-qualified class names (FQCN) as event identifiers — avoid duplicate event class names across namespaces to prevent unintended listener triggering.
  • Middleware/Filter Hooks: If leveraging the FilterEvent or ListenerFilter, remember to register filters before listeners in config to avoid early termination.
  • Performance Tip: For high-volume event streams, prefer named listeners over class-string-based listeners for minor performance gains, and consider batching events where appropriate.
  • Debugging: Enable Spiral’s debug mode to trace dispatched events in the toolbar; inspect the event section in /debug for listener chain execution.
  • Legacy Hook: The package doesn’t auto-register Symfony-style event names — always rely on FQCN to match events to listeners.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log
hsluv/hsluv
seampact/codegen
seampact/hooks
seampact/ir
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk