Documentation

CiviEventDispatcherInterface

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
author

Bernhard Schussek bschussek@gmail.com

Table of Contents

Methods

addListener()  : mixed
Adds an event listener that listens on the specified events.
addSubscriber()  : mixed
Adds an event subscriber.
dispatch()  : object
Dispatches an event to all registered listeners.
getListenerPriority()  : int|null
Gets the listener priority for a specific event.
getListeners()  : array<string|int, mixed>
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

Methods

addListener()

Adds an event listener that listens on the specified events.

public addListener(string $eventName, callable $listener[, int $priority = 0 ]) : mixed
Parameters
$eventName : string

The event to listen on

$listener : callable

The listener

$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

The subscriber is asked for all the events it is interested in and added as a listener for these events.

Parameters
$subscriber : EventSubscriberInterface

dispatch()

Dispatches an event to all registered listeners.

public dispatch(string $eventName[, object|null $event = NULL ]) : object
Parameters
$eventName : string

The name of the event to dispatch. The name of the event is the name of the method that is invoked on listeners.

$event : object|null = NULL

The event to pass to the event handlers/listeners The dispatcher technically accepts any kind of event-object.

CiviCRM typically uses GenericHookEvent. Specifically:

  • For hook_civicrm_*, GenericHookEvent is strongly required.
  • For civi.*, GenericHookEvent is typical but not strongly required.

Symfony also defines classes for event-objects (Event, GenericEvent). Historically, these types -were- mandatory, but they have had poor interoperability (across versions/environments). GenericHookEvent has provided easier interoperability.

Looking forward, the current dispatcher does not specifically require any single type, and there may be use-cases where libraries or extensions define other types. The suitability of this is left as an exercise to the reader.

If $event is a null, then an empty placeholder (GenericHookEvent) is used.

Return values
object

The final event object.

getListenerPriority()

Gets the listener priority for a specific event.

public getListenerPriority(string $eventName, callable $listener) : int|null

Returns null if the event or the listener does not exist.

Parameters
$eventName : string

The name of the event

$listener : callable

The listener

Return values
int|null

The event listener priority

getListeners()

Gets the listeners of a specific event or all listeners sorted by descending priority.

public getListeners([string|null $eventName = NULL ]) : array<string|int, mixed>
Parameters
$eventName : string|null = NULL

The name of the event

Return values
array<string|int, mixed>

The event listeners for the specified event, or all event listeners by event name

hasListeners()

Checks whether an event has any registered listeners.

public hasListeners([string|null $eventName = NULL ]) : bool
Parameters
$eventName : string|null = NULL

The name of the event

Return values
bool

true if the specified event has any listeners, false otherwise

removeListener()

Removes an event listener from the specified events.

public removeListener(string $eventName, callable $listener) : mixed
Parameters
$eventName : string

The event to remove a listener from

$listener : callable

The listener to remove

removeSubscriber()

public removeSubscriber(EventSubscriberInterface $subscriber) : mixed
Parameters
$subscriber : EventSubscriberInterface

        
On this page

Search results