EventDispatcher
in package
implements
EventDispatcherInterface
The EventDispatcherInterface is the central point of Symfony's event listener system.
Listeners are registered on the manager and events are dispatched through the manager.
Tags
Table of Contents
Interfaces
- EventDispatcherInterface
- The EventDispatcherInterface is the central point of Symfony's event listener system.
Properties
- $listeners : array<string|int, mixed>
- $optimized : array<string|int, mixed>
- $sorted : array<string|int, mixed>
Methods
- __construct() : mixed
- addListener() : mixed
- Adds an event listener that listens on the specified events.
- addSubscriber() : mixed
- Adds an event subscriber.
- dispatch() : object
- {@inheritdoc}
- getListenerPriority() : int|null
- Gets the listener priority for a specific event.
- getListeners() : array<string|int, array<string|int, callable>|callable>
- Gets the listeners of a specific event or all listeners sorted by descending priority.
- hasListeners() : bool
- Checks whether an event has any registered listeners.
- removeListener() : mixed
- Removes an event listener from the specified events.
- removeSubscriber() : mixed
- callListeners() : mixed
- Triggers the listeners of an event.
- optimizeListeners() : array<string|int, mixed>
- Optimizes the internal list of listeners for the given event by priority.
- sortListeners() : mixed
- Sorts the internal list of listeners for the given event by priority.
Properties
$listeners
private
array<string|int, mixed>
$listeners
= []
$optimized
private
array<string|int, mixed>
$optimized
$sorted
private
array<string|int, mixed>
$sorted
= []
Methods
__construct()
public
__construct() : mixed
addListener()
Adds an event listener that listens on the specified events.
public
addListener(string $eventName, callable|array<string|int, mixed> $listener[, int $priority = 0 ]) : mixed
Parameters
- $eventName : string
- $listener : callable|array<string|int, mixed>
- $priority : int = 0
-
The higher this value, the earlier an event listener will be triggered in the chain (defaults to 0)
addSubscriber()
Adds an event subscriber.
public
addSubscriber(EventSubscriberInterface $subscriber) : mixed
Parameters
- $subscriber : EventSubscriberInterface
dispatch()
{@inheritdoc}
public
dispatch(object $event[, string $eventName = null ]) : object
Parameters
- $event : object
- $eventName : string = null
Return values
objectgetListenerPriority()
Gets the listener priority for a specific event.
public
getListenerPriority(string $eventName, callable|array<string|int, mixed> $listener) : int|null
Parameters
- $eventName : string
- $listener : callable|array<string|int, mixed>
Return values
int|nullgetListeners()
Gets the listeners of a specific event or all listeners sorted by descending priority.
public
getListeners([string $eventName = null ]) : array<string|int, array<string|int, callable>|callable>
Parameters
- $eventName : string = null
Return values
array<string|int, array<string|int, callable>|callable>hasListeners()
Checks whether an event has any registered listeners.
public
hasListeners([string $eventName = null ]) : bool
Parameters
- $eventName : string = null
Return values
boolremoveListener()
Removes an event listener from the specified events.
public
removeListener(string $eventName, callable|array<string|int, mixed> $listener) : mixed
Parameters
- $eventName : string
- $listener : callable|array<string|int, mixed>
removeSubscriber()
public
removeSubscriber(EventSubscriberInterface $subscriber) : mixed
Parameters
- $subscriber : EventSubscriberInterface
callListeners()
Triggers the listeners of an event.
protected
callListeners(array<string|int, callable> $listeners, string $eventName, object $event) : mixed
This method can be overridden to add functionality that is executed for each listener.
Parameters
- $listeners : array<string|int, callable>
-
The event listeners
- $eventName : string
-
The name of the event to dispatch
- $event : object
-
The event object to pass to the event handlers/listeners
optimizeListeners()
Optimizes the internal list of listeners for the given event by priority.
private
optimizeListeners(string $eventName) : array<string|int, mixed>
Parameters
- $eventName : string
Return values
array<string|int, mixed>sortListeners()
Sorts the internal list of listeners for the given event by priority.
private
sortListeners(string $eventName) : mixed
Parameters
- $eventName : string