\CodeIgniter\EventsEvents

Events

Summary

Methods
Properties
Constants
initialize()
on()
trigger()
listeners()
removeListener()
removeAllListeners()
setFiles()
getFiles()
simulate()
getPerformanceLogs()
No public properties found
No constants found
No protected methods found
$listeners
$initialized
$simulate
$performanceLog
$files
N/A
No private methods found
No private properties found
N/A

Properties

$listeners

$listeners : array

The list of listeners.

Type

array

$initialized

$initialized : boolean

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

Type

boolean

$simulate

$simulate : boolean

If true, events will not actually be fired.

Useful during testing.

Type

boolean

$performanceLog

$performanceLog : array

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

Type

array

$files

$files : array

A list of found files.

Type

array

Methods

initialize()

initialize() 

Ensures that we have a events file ready.

on()

on(  $event_name, callable  $callback, integer  $priority = EVENT_PRIORITY_NORMAL) 

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

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

$event_name
callable $callback
integer $priority

trigger()

trigger(  $eventName,   $arguments) : boolean

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.

Parameters

$eventName
$arguments

Returns

boolean

listeners()

listeners(  $event_name) : array

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

If the listener could not be found, returns FALSE, or TRUE if it was removed.

Parameters

$event_name

Returns

array

removeListener()

removeListener(  $event_name, callable  $listener) : boolean

Removes a single listener from an event.

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

Parameters

$event_name
callable $listener

Returns

boolean

removeAllListeners()

removeAllListeners(null  $event_name = null) 

Removes all listeners.

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

Parameters

null $event_name

setFiles()

setFiles(array  $files) 

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

Parameters

array $files

getFiles()

getFiles() : mixed

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

Returns

mixed

simulate()

simulate(boolean  $choice = true) 

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.

Parameters

boolean $choice

getPerformanceLogs()

getPerformanceLogs() : array

Getter for the performance log records.

Returns

array