Install League\Event via Composer
masterTo use League\Event in your PHP project, install it using Composer:
composer require league/eventrepository·master·Indexed 23 days ago
https://github.com/thephpleague/eventSearchable repository documentation for Thephpleague Event from https://github.com/thephpleague/event.
To use League\Event in your PHP project, install it using Composer:
composer require league/eventdispatchGeneratedEvents() to iterate through them and dispatch each one automatically using an EventGenerator instance.If the underlying EventDispatcherInterface passed to the BufferedEventDispatcher constructor also implements ListenerRegistry, you can use the buffered dispatcher to manage subscriptions.
Supported methods include:
subscribeTo(string $event, callable $listener, int $priority = ListenerPriority::NORMAL): voidsubscribeOnceTo(string $event, callable $listener, int $priority = ListenerPriority::NORMAL): voidsubscribeListenersFrom(ListenerSubscriber $subscriber): voidIf the wrapped dispatcher does not implement ListenerRegistry, these methods will throw an UnableToSubscribeListener exception.
EventDispatcher is the primary class for managing and dispatching events. You can instantiate it without arguments, in which case it will automatically use a PrioritizedListenerRegistry as its internal listener provider. Alternatively, you can provide your own implementation of Psr\/EventDispatcher\/ListenerProviderInterface to control how listeners are retrieved.ListenerSubscriber, you can register all of its internal listeners into the PrioritizedListenerRegistry at once using subscribeListenersFrom.Use PrioritizedListenerRegistry to manage event listeners where execution order matters. You can attach listeners to specific event classes or event names using subscribeTo. If a priority is not provided, it defaults to ListenerPriority::NORMAL.
To ensure a listener only runs once, use subscribeOnceTo.
The BufferedEventDispatcher implements Psr\/EventDispatcher\/EventDispatcherInterface but instead of immediately dispatching events, it buffers them using internal event generation behavior.
When you call dispatch($event), the event is recorded but not immediately sent to listeners. To actually trigger the listeners, you must call dispatchBufferedEvents(). This method iterates through all recorded events and dispatches them using the wrapped EventDispatcherInterface provided during construction.
The getListenersForEvent method allows you to retrieve all registered listeners for a given event object. It supports two types of matching:
HasEventName, it will also yield listeners registered specifically for the string returned by $event->eventName().This method implements Psr\EventDispatcher\ListenerProviderInterface.
Use the dispatch() method to trigger an event. It accepts any object as an event.
Psr\/EventDispatcher\/StoppableEventInterface, the dispatcher will respect the event's propagation state. If a listener calls $event->stopPropagation(), subsequent listeners in the chain will not be executed.StoppableEventInterface, all listeners will be executed in order.You can register listeners directly on the EventDispatcher using the following methods. Note that these methods require the internal listenerProvider to implement League\/Event\/ListenerRegistry (which PrioritizedListenerRegistry does).
subscribeTo(string $event, callable $listener, int $priority = ListenerPriority::NORMAL): Registers a listener for a specific event name or class. Use $priority to control execution order.subscribeOnceTo(string $event, callable $listener, int $priority = ListenerPriority::NORMAL): Registers a listener that will only be triggered once.subscribeListenersFrom(ListenerSubscriber $subscriber): Registers all listeners contained within a ListenerSubscriber object.