class Event (View source)

Constants

HIGH_PRIORITY

LOW_PRIORITY

TRIGGER_UNDEFINED

TRIGGER_CONSUMED

TRIGGER_STOPPED

TRIGGER_SUCCESS

Methods

static int
trigger(string $name, array $args = array())

Triggers all callbacks registered for a given event

static 
on(string $name, callable $callback, int $priority = 0)

Registers a callback to an event with optional priority. Note: If any subscribed callback returns a boolean false, further execution of subsequent callbacks will be halted

static 
once(string $name)

It makes a type of event unique, ensuring that all registered events of that type are triggered only once.

static 
off(string $name, callable|null $callback = null)

Removes a specific callback or all callbacks registered for an event.

static 
clear()

Clears all registered events and uniqueness flags

Details

static int trigger(string $name, array $args = array())

Triggers all callbacks registered for a given event

Parameters

string $name

Event name

array $args

Arguments to pass to the callbacks

Return Value

int

static on(string $name, callable $callback, int $priority = 0)

Registers a callback to an event with optional priority. Note: If any subscribed callback returns a boolean false, further execution of subsequent callbacks will be halted

Parameters

string $name

Event name

callable $callback

Callback to execute when the event is triggered

int $priority

Execution priority (higher numbers run earlier). Default is 0

static once(string $name)

It makes a type of event unique, ensuring that all registered events of that type are triggered only once.

Parameters

string $name

Event name

static off(string $name, callable|null $callback = null)

Removes a specific callback or all callbacks registered for an event.

If $callback is null, all listeners for the given event are removed.

Parameters

string $name

Event name

callable|null $callback

Specific callback to remove, or null to remove all

static clear()

Clears all registered events and uniqueness flags