Dispatcher
Implements \Joomla\Event\DispatcherInterfaceImplementation of a DispatcherInterface supporting prioritized listeners.
since |
1.0 |
---|
Methods
addEvent
Add an event to this dispatcher, only if it is not existing.
addEvent(\Joomla\Event\EventInterface $event) : \Joomla\Event\Dispatcher
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface
The event.
Response
\Joomla\Event\Dispatcher
This method is chainable.
addListener
Add a listener to this dispatcher, only if not already registered to these events.
addListener(object|\Closure $listener, array $events = array()) : \Joomla\Event\Dispatcher
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.
throws |
|
---|---|
since |
1.0 |
Arguments
- $listener
object|\Closure
The listener- $events
array
An associative array of event names as keys and the corresponding listener priority as values.
Response
\Joomla\Event\Dispatcher
This method is chainable.
clearEvents
Clear all events.
clearEvents() : array<mixed,\Joomla\Event\EventInterface>
clearListeners
Clear the listeners in this dispatcher.
clearListeners(\Joomla\Event\EventInterface|string $event = null) : \Joomla\Event\Dispatcher
If an event is specified, the listeners will be cleared only for that event.
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
\Joomla\Event\Dispatcher
This method is chainable.
countEvents
Count the number of registered event.
countEvents() : integer
since |
1.0 |
---|
Response
integer
The numer of registered events.
countListeners
Count the number of registered listeners for the given event.
countListeners(\Joomla\Event\EventInterface|string $event) : integer
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
integer
The number of registered listeners for the given event.
getEvent
Get the event object identified by the given name.
getEvent(string $name, mixed $default = null) : \Joomla\Event\EventInterface|mixed
since |
1.0 |
---|
Arguments
- $name
string
The event name.- $default
mixed
The default value if the event was not registered.
Response
\Joomla\Event\EventInterface|mixed
The event of the default value.
getEvents
Get the registered events.
getEvents() : array<mixed,\Joomla\Event\EventInterface>
getListenerPriority
Get the priority of the given listener for the given event.
getListenerPriority(object|\Closure $listener, \Joomla\Event\EventInterface|string $event) : mixed
since |
1.0 |
---|
Arguments
- $listener
object|\Closure
The listener.- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
mixed
The listener priority or null if the listener doesn't exist.
getListeners
Get the listeners registered to the given event.
getListeners(\Joomla\Event\EventInterface|string $event) : array<mixed,object>
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
array<mixed,object>
An array of registered listeners sorted according to their priorities.
hasEvent
Tell if the given event has been added to this dispatcher.
hasEvent(\Joomla\Event\EventInterface|string $event) : boolean
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
boolean
True if the listener has the given event, false otherwise.
hasListener
Tell if the given listener has been added.
hasListener(object|\Closure $listener, \Joomla\Event\EventInterface|string $event = null) : boolean
If an event is specified, it will tell if the listener is registered for that event.
since |
1.0 |
---|
Arguments
- $listener
object|\Closure
The listener.- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
boolean
True if the listener is registered, false otherwise.
removeEvent
Remove an event from this dispatcher.
removeEvent(\Joomla\Event\EventInterface|string $event) : \Joomla\Event\Dispatcher
The registered listeners will remain.
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
\Joomla\Event\Dispatcher
This method is chainable.
removeListener
Remove the given listener from this dispatcher.
removeListener(object|\Closure $listener, \Joomla\Event\EventInterface|string $event = null) : \Joomla\Event\Dispatcher
If no event is specified, it will be removed from all events it is listening to.
since |
1.0 |
---|
Arguments
- $listener
object|\Closure
The listener to remove.- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
\Joomla\Event\Dispatcher
This method is chainable.
setEvent
Set an event to the dispatcher.
setEvent(\Joomla\Event\EventInterface $event) : \Joomla\Event\Dispatcher
It will replace any event with the same name.
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface
The event.
Response
\Joomla\Event\Dispatcher
This method is chainable.
setListenerFilter
Sets a regular expression to filter the class methods when adding a listener.
setListenerFilter(string $regex) : \Joomla\Event\Dispatcher
since |
1.0 |
---|---|
deprecated |
1.1.0 Incorporate a method in your listener object such as |
Arguments
- $regex
string
A regular expression (for example '^on' will only register methods starting with "on").
Response
\Joomla\Event\Dispatcher
This method is chainable.
triggerEvent
Trigger an event.
triggerEvent(\Joomla\Event\EventInterface|string $event) : \Joomla\Event\EventInterface
since |
1.0 |
---|
Arguments
- $event
\Joomla\Event\EventInterface|string
The event object or name.
Response
\Joomla\Event\EventInterface
The event after being passed through all listeners.
Properties
events
An array of registered events indexed by the event names.
listenerFilter
A regular expression that will filter listener method names.
since |
1.0 |
---|---|
deprecated |
1.1.0 |
Type(s)
string
listeners
An array of ListenersPriorityQueue indexed by the event names.