AbstractListener
Abstract listener for events
Attributes
- #[AllowDynamicProperties]
Table of Contents
Properties
| $listeners |
Methods
| getRegistered() | Returns all registered listeners for the given event name |
| register() | Register a listener, to be notified when the event is triggered. Only permits one registered event per callback. |
| trigger() | Notifies all registered listeners of the event (called in the order they were set). |
| triggerUntil() | Notifies all registered listeners of the event (called in the order they were set), until one returns true, then ceases notifying all remaining listeners. |
| unregister() | Unregisters a listener if the event has been registered. Will remove all copies of the registered event in the case that it was registered multiple times. |
Methods
getRegistered()
Returns all registered listeners for the given event name
public
getRegistered(string $name) : array<string|int, mixed>
Parameters
- $name : string
-
The name of the event to fetch registered callbacks for
Return values
array<string|int, mixed> —An array of registered callbacks
register()
Register a listener, to be notified when the event is triggered. Only permits one registered event per callback.
public
register(string $name, callable $callback[, string $file = null ]) : mixed
Parameters
- $name : string
-
The name of the event to register $callback under
- $callback : callable
-
The Class/Method or Object/Method or function to execute when the event is triggered.
- $file : string = null
-
The full path to the file that contains the callback, null will default to looking in the \Blesta\Core\Util\Events\Observers\Class namespace (where 'Class' is the CamelCase format of the callback class [e.g. ClassName])
trigger()
Notifies all registered listeners of the event (called in the order they were set).
public
abstract trigger(EventInterface $event) : EventInterface
Parameters
- $event : EventInterface
-
The event object to pass to the registered listeners
Return values
EventInterface —The event processed
triggerUntil()
Notifies all registered listeners of the event (called in the order they were set), until one returns true, then ceases notifying all remaining listeners.
public
abstract triggerUntil(EventInterface $event) : EventInterface
Parameters
- $event : EventInterface
-
The event object to pass to the registered listeners
Return values
EventInterface —The event processed
unregister()
Unregisters a listener if the event has been registered. Will remove all copies of the registered event in the case that it was registered multiple times.
public
unregister(string $name, callable $callback) : mixed
Parameters
- $name : string
-
The name of the event to unregister $callback from
- $callback : callable
-
The Class/Method or Object/Method or function to unregister for the event