class Dispatcher implements DispatcherInterface (View source)

The Dispatcher class.

Methods

setEvent(EventInterface $event)

Set an event to the dispatcher.

addEvent(EventInterface $event)

Add an event to this dispatcher, only if it is not existing.

boolean
hasEvent(EventInterface|string $event)

Tell if the given event has been added to this dispatcher.

getEvent(string $name, mixed $default = null)

Get the event object identified by the given name.

removeEvent(EventInterface|string $event)

Remove an event from this dispatcher.

getEvents()

Get the registered events.

clearEvents()

Clear all events.

integer
countEvents()

Count the number of registered event.

addListener(object|Closure $listener, array|integer $priorities = array())

Add a listener to this dispatcher, only if not already registered to these events.

listen(string $event, callable $callable, int $priority = ListenerPriority::NORMAL)

on

mixed
getListenerPriority(object|callable $listener, EventInterface|string $event)

Get the priority of the given listener for the given event.

object[]
getListeners(EventInterface|string $event = null)

Get the listeners registered to the given event.

boolean
hasListener(object|callable $listener, EventInterface|string $event = null)

Tell if the given listener has been added.

removeListener(object|Closure $listener, EventInterface|string $event = null)

Remove the given listener from this dispatcher.

clearListeners(EventInterface|string $event = null)

Clear the listeners in this dispatcher.

integer
countListeners(EventInterface|string $event)

Count the number of registered listeners for the given event.

triggerEvent(EventInterface|string $event, array $args = array())

Trigger an event.

Details

at line line 48
Dispatcher setEvent(EventInterface $event)

Set an event to the dispatcher.

It will replace any event with the same name.

Parameters

EventInterface $event The event.

Return Value

Dispatcher This method is chainable.

at line line 64
Dispatcher addEvent(EventInterface $event)

Add an event to this dispatcher, only if it is not existing.

Parameters

EventInterface $event The event.

Return Value

Dispatcher This method is chainable.

at line line 83
boolean hasEvent(EventInterface|string $event)

Tell if the given event has been added to this dispatcher.

Parameters

EventInterface|string $event The event object or name.

Return Value

boolean True if the listener has the given event, false otherwise.

at line line 103
EventInterface|mixed getEvent(string $name, mixed $default = null)

Get the event object identified by the given name.

Parameters

string $name The event name.
mixed $default The default value if the event was not registered.

Return Value

EventInterface|mixed The event of the default value.

at line line 123
Dispatcher removeEvent(EventInterface|string $event)

Remove an event from this dispatcher.

The registered listeners will remain.

Parameters

EventInterface|string $event The event object or name.

Return Value

Dispatcher This method is chainable.

at line line 145
EventInterface[] getEvents()

Get the registered events.

Return Value

EventInterface[] The registered event.

at line line 157
EventInterface[] clearEvents()

Clear all events.

Return Value

EventInterface[] The old events.

at line line 172
integer countEvents()

Count the number of registered event.

Return Value

integer The number of registered events.

at line line 192
DispatcherInterface addListener(object|Closure $listener, array|integer $priorities = array())

Add a listener to this dispatcher, only if not already registered to these events.

If no events are specified, it will be registered to all events matching it's methods name. In the case of a closure, you must specify at least one event name.

Parameters

object|Closure $listener The listener
array|integer $priorities An associative array of event names as keys and the corresponding listener priority as values.

Return Value

DispatcherInterface This method is chainable.

Exceptions

InvalidArgumentException

at line line 262
DispatcherInterface listen(string $event, callable $callable, int $priority = ListenerPriority::NORMAL)

on

Parameters

string $event
callable $callable
int $priority

Return Value

DispatcherInterface

at line line 277
mixed getListenerPriority(object|callable $listener, EventInterface|string $event)

Get the priority of the given listener for the given event.

Parameters

object|callable $listener The listener.
EventInterface|string $event The event object or name.

Return Value

mixed The listener priority or null if the listener doesn't exist.

at line line 301
object[] getListeners(EventInterface|string $event = null)

Get the listeners registered to the given event.

Parameters

EventInterface|string $event The event object or name.

Return Value

object[] An array of registered listeners sorted according to their priorities.

at line line 332
boolean hasListener(object|callable $listener, EventInterface|string $event = null)

Tell if the given listener has been added.

If an event is specified, it will tell if the listener is registered for that event.

Parameters

object|callable $listener The listener.
EventInterface|string $event The event object or name.

Return Value

boolean True if the listener is registered, false otherwise.

at line line 371
Dispatcher removeListener(object|Closure $listener, EventInterface|string $event = null)

Remove the given listener from this dispatcher.

If no event is specified, it will be removed from all events it is listening to.

Parameters

object|Closure $listener The listener to remove.
EventInterface|string $event The event object or name.

Return Value

Dispatcher This method is chainable.

at line line 407
Dispatcher clearListeners(EventInterface|string $event = null)

Clear the listeners in this dispatcher.

If an event is specified, the listeners will be cleared only for that event.

Parameters

EventInterface|string $event The event object or name.

Return Value

Dispatcher This method is chainable.

at line line 439
integer countListeners(EventInterface|string $event)

Count the number of registered listeners for the given event.

Parameters

EventInterface|string $event The event object or name.

Return Value

integer The number of registered listeners for the given event.

at line line 459
EventInterface triggerEvent(EventInterface|string $event, array $args = array())

Trigger an event.

Parameters

EventInterface|string $event The event object or name.
array $args The arguments to set in event.

Return Value

EventInterface The event after being passed through all listeners.