Documentation

Events
in package

Events

Table of Contents

$files  : array<string|int, string>
A list of found files.
$initialized  : bool
Flag to let us know if we've read from the Config file(s) and have all of the defined events.
$listeners  : array<string|int, mixed>
The list of listeners.
$performanceLog  : array<string|int, array<string, float|string>>
Stores information about the events for display in the debug toolbar.
$simulate  : bool
If true, events will not actually be fired.
getFiles()  : array<string|int, string>
Returns the files that were found/loaded during this request.
getPerformanceLogs()  : array<string|int, array<string, float|string>>
Getter for the performance log records.
initialize()  : void
Ensures that we have a events file ready.
listeners()  : array<string|int, mixed>
Returns an array of listeners for a single event. They are sorted by priority.
on()  : void
Registers an action to happen on an event. The action can be any sort of callable:
removeAllListeners()  : void
Removes all listeners.
removeListener()  : bool
Removes a single listener from an event.
setFiles()  : void
Sets the path to the file that routes are read from.
simulate()  : void
Turns simulation on or off. When on, events will not be triggered, simply logged. Useful during testing when you don't actually want the tests to run.
trigger()  : bool
Runs through all subscribed methods running them one at a time, until either: a) All subscribers have finished or b) a method returns false, at which point execution of subscribers stops.

Properties

$files

A list of found files.

protected static array<string|int, string> $files = []

$initialized

Flag to let us know if we've read from the Config file(s) and have all of the defined events.

protected static bool $initialized = false

$listeners

The list of listeners.

protected static array<string|int, mixed> $listeners = []

$performanceLog

Stores information about the events for display in the debug toolbar.

protected static array<string|int, array<string, float|string>> $performanceLog = []

$simulate

If true, events will not actually be fired.

protected static bool $simulate = false

Useful during testing.

Methods

getFiles()

Returns the files that were found/loaded during this request.

public getFiles() : array<string|int, string>
Return values
array<string|int, string>

getPerformanceLogs()

Getter for the performance log records.

public static getPerformanceLogs() : array<string|int, array<string, float|string>>
Return values
array<string|int, array<string, float|string>>

initialize()

Ensures that we have a events file ready.

public static initialize() : void
Return values
void

listeners()

Returns an array of listeners for a single event. They are sorted by priority.

public static listeners(string $eventName) : array<string|int, mixed>
Parameters
$eventName : string
Return values
array<string|int, mixed>

on()

Registers an action to happen on an event. The action can be any sort of callable:

public static on(string $eventName, callable $callback[, int $priority = EVENT_PRIORITY_NORMAL ]) : void

Events::on('create', 'myFunction'); // procedural function Events::on('create', ['myClass', 'myMethod']); // Class::method Events::on('create', [$myInstance, 'myMethod']); // Method on an existing instance Events::on('create', function() }); // Closure

Parameters
$eventName : string
$callback : callable
$priority : int = EVENT_PRIORITY_NORMAL
Return values
void

removeAllListeners()

Removes all listeners.

public static removeAllListeners([string|null $eventName = null ]) : void

If the event_name is specified, only listeners for that event will be removed, otherwise all listeners for all events are removed.

Parameters
$eventName : string|null = null
Return values
void

removeListener()

Removes a single listener from an event.

public static removeListener(string $eventName, callable $listener) : bool

If the listener couldn't be found, returns FALSE, else TRUE if it was removed.

Parameters
$eventName : string
$listener : callable
Return values
bool

setFiles()

Sets the path to the file that routes are read from.

public static setFiles(array<string|int, mixed> $files) : void
Parameters
$files : array<string|int, mixed>
Return values
void

simulate()

Turns simulation on or off. When on, events will not be triggered, simply logged. Useful during testing when you don't actually want the tests to run.

public static simulate([bool $choice = true ]) : void
Parameters
$choice : bool = true
Return values
void

trigger()

Runs through all subscribed methods running them one at a time, until either: a) All subscribers have finished or b) a method returns false, at which point execution of subscribers stops.

public static trigger(string $eventName, mixed ...$arguments) : bool
Parameters
$eventName : string
$arguments : mixed
Return values
bool

Search results