EventDispatcher
in package
Event manager.
Table of Contents
Properties
- $instance : EventDispatcher
- Singleton instance.
- $_events : Collection
- Array of events.
Methods
- AddEventListener() : bool
- Adds an event listener.
- Create() : EventDispatcher
- Static constructor.
- Dispatch() : object|null
- Dispatches an event.
- Dispose() : void
- Disposes the object.
- HasEventListener() : bool
- Checks if an event listener exists.
- RegisteredListeners() : ArrayList|null
- Returns the list of registered event listeners.
- RemoveEventListener() : bool
- Removes an event listener.
- __construct() : mixed
- Constructor.
Properties
$instance
Singleton instance.
public
static EventDispatcher
$instance
$_events
Array of events.
private
Collection
$_events
Methods
AddEventListener()
Adds an event listener.
public
AddEventListener(array<string|int, mixed>|string $ename, mixed $listener[, object|null $object = null ]) : bool
Parameters
- $ename : array<string|int, mixed>|string
-
The event name or an array of event names.
- $listener : mixed
-
The listener function or object.
- $object : object|null = null
-
The object associated with the listener function.
Return values
bool —True if the listener was added successfully, false otherwise.
Create()
Static constructor.
public
static Create() : EventDispatcher
Return values
EventDispatcher —The EventDispatcher instance.
Dispatch()
Dispatches an event.
public
Dispatch(string|Event $event[, mixed $args = null ][, bool $async = false ]) : object|null
Parameters
- $event : string|Event
-
The event object or its name.
- $args : mixed = null
-
The arguments for the event handlers.
- $async : bool = false
-
Whether to dispatch asynchronously.
Return values
object|null —The result of the event dispatching.
Dispose()
Disposes the object.
public
Dispose() : void
HasEventListener()
Checks if an event listener exists.
public
HasEventListener(string $ename, mixed $listener[, object|null $object = null ]) : bool
Parameters
- $ename : string
-
The event name.
- $listener : mixed
-
The listener function or object.
- $object : object|null = null
-
The object associated with the listener function.
Return values
bool —True if the event listener exists, false otherwise.
RegisteredListeners()
Returns the list of registered event listeners.
public
RegisteredListeners([string $ename = "" ]) : ArrayList|null
Parameters
- $ename : string = ""
-
The event name.
Return values
ArrayList|null —The list of registered event listeners.
RemoveEventListener()
Removes an event listener.
public
RemoveEventListener(string $ename, mixed $listener[, object|null $object = null ]) : bool
Parameters
- $ename : string
-
The event name.
- $listener : mixed
-
The listener function or object.
- $object : object|null = null
-
The object associated with the listener function.
Return values
bool —True if the listener was removed successfully, false otherwise.
__construct()
Constructor.
private
__construct() : mixed