EventHandler
in package
Handles registering and triggering events.
Tags
Table of Contents
Properties
- $_events : array<string|int, mixed>
- $_webhooks : array<string|int, mixed>
Methods
- executeEvent() : array<string|int, mixed>|null
- Execute an event.
- getEvent() : array<string|int, mixed>
- Get data about an event.
- getEvents() : array<string|int, mixed>
- Get a list of events to display on the StaffCP webhooks page.
- registerEvent() : void
- Register an event.
- registerListener() : void
- Register an event listener for a module.
- registerWebhooks() : void
- Register webhooks.
- shouldPassEventObject() : bool
- Determine whether a callback should be passed an event object or an array.
Properties
$_events
private
static array<string|int, mixed>
$_events
= []
$_webhooks
private
static array<string|int, mixed>
$_webhooks
= []
Methods
executeEvent()
Execute an event.
public
static executeEvent(AbstractEvent|string $event[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>|null
Parameters
- $event : AbstractEvent|string
-
Event name to call, or instance of event to execute.
- $params : array<string|int, mixed> = []
-
Params to pass to the event's function, not required when a class-based event is used.
Return values
array<string|int, mixed>|null —Response of lissteners, can be any type or null
getEvent()
Get data about an event.
public
static getEvent(string $event) : array<string|int, mixed>
Not used internally, currently for WebSend.
Parameters
- $event : string
-
Name of event to get data for.
Tags
Return values
array<string|int, mixed>getEvents()
Get a list of events to display on the StaffCP webhooks page.
public
static getEvents([bool $showInternal = false ]) : array<string|int, mixed>
Parameters
- $showInternal : bool = false
Return values
array<string|int, mixed> —List of all currently registered events
registerEvent()
Register an event.
public
static registerEvent(class-string|string $event[, string $description = '' ][, array<string|int, mixed> $params = [] ][, bool $return = false ][, bool $internal = false ]) : void
This must be called in the module's constructor.
Parameters
- $event : class-string|string
-
Name of event to add.
- $description : string = ''
-
Human readable description.
- $params : array<string|int, mixed> = []
-
Array of available parameters and their descriptions.
- $return : bool = false
-
Whether to return $params afterwards
- $internal : bool = false
-
Whether to hide this hook from users in the StaffCP (ie for internal events)
registerListener()
Register an event listener for a module.
public
static registerListener(string $event, callable|class-string $callback[, int $priority = 10 ]) : void
This must be called in the module's constructor.
Parameters
- $event : string
-
Event name to listen to.
- $callback : callable|class-string
-
Listener callback to execute when event is executed. If class name is provided, we will assume there is a static "execute" method on the class.
- $priority : int = 10
-
Execution priority - higher gets executed first
registerWebhooks()
Register webhooks.
public
static registerWebhooks(array<string|int, mixed> $webhooks) : void
Parameters
- $webhooks : array<string|int, mixed>
-
Array of webhooks to register
shouldPassEventObject()
Determine whether a callback should be passed an event object or an array.
private
static shouldPassEventObject(callable $callback) : bool
Example: function (UserRegisteredEvent $event) }
should be passed an event object,
whereas function (array $params) }
should be passed an array.
Parameters
- $callback : callable
-
Callback to check.
Tags
Return values
bool —Whether the callback should be passed an event object or an array.