joomla/event
Joomla Event provides the building blocks for PHP event systems, including a dispatcher implementation with prioritized listeners. Use it to define, register, and trigger events in a clean, decoupled way. Requires PHP 8.1+.
Install the package via Composer: composer require joomla/event "~3.0". Begin by creating a simple Dispatcher and registering a closure listener for an event like 'onUserLogin'. Dispatch the event and verify your listener executes. This minimal flow—dispatcher → listener → dispatch—demonstrates the core pattern. Start with docs/overview.md and the “Creating a Decorated Dispatcher” example for hands-on learning.
Dispatcher as a central bus in service containers or application kernels. Register subscribers (classes implementing SubscriberInterface) to decouple concerns (e.g., logging, caching, validation).DispatcherAwareTrait in domain models (e.g., UserModel, OrderService) to inject a dispatcher and dispatch onBefore{Action} and onAfter{Action} events transparently.Priority::EARLY, HIGH, NORMAL, ABOVE_NORMAL, etc., to control execution order—e.g., security checks (HIGH) before UI rendering (NORMAL).LazyServiceEventListener to defer instantiation until dispatch time, especially useful for listeners depending on DI containers or services with circular dependencies.EventImmutable for events whose arguments should be read-only by listeners (common in audit or validation scenarios).EventInterface argument. PHP will throw a TypeError if the signature doesn’t match.triggerEvent() deprecation: Though still present in Dispatcher, use dispatch()—the legacy method is deprecated and removed in future versions.removeListener() requires an exact match of listener (e.g., [$subscriber, 'method'] or closure identity). If you registered a closure inline, keep a reference to remove it later.DispatcherInterface into classes using DispatcherAwareTrait to isolate event behavior in unit tests.How can I help you explore Laravel packages today?