Core_Event
in package
Event system adds function calls for extending functionality.
Tags
Table of Contents
Properties
- $_attached : array<string|int, mixed>
- List of attached observers
- $_debug : null|bool
- Cache for _isDebug()
- $_disabled : array<string|int, mixed>
- List of disabled events
- $_lastReturn : misex
- Last returned value
Methods
- attach() : mixed
- Attach observer
- attachFirst() : mixed
- Attach observer to the beginning of the queue
- detach() : mixed
- Detach observer
- disable() : bool
- Disable event
- enable() : mixed
- Enable event
- getCount() : mixed
- Get count of observers
- getLastReturn() : mixed
- Get the last returned value
- notify() : mixed
- Notify all observers. If observer return FALSE, the cycle will stop.
- off() : mixed
- Disable event. Alias of disable()
- on() : mixed
- Enable event. Alias of enable()
- _isDebug() : null|bool
- Check is debug mode
Properties
$_attached
List of attached observers
protected
static array<string|int, mixed>
$_attached
= array()
$_debug
Cache for _isDebug()
protected
static null|bool
$_debug
= \NULL
$_disabled
List of disabled events
protected
static array<string|int, mixed>
$_disabled
= array()
$_lastReturn
Last returned value
protected
static misex
$_lastReturn
= \NULL
Methods
attach()
Attach observer
public
static attach(string $eventName, string $function[, mixed $options = NULL ]) : mixed
Parameters
- $eventName : string
-
event name
- $function : string
-
function name
- $options : mixed = NULL
-
additional options, default NULL
function my_function($object, $args) { // do something } $function = 'my_function'; // Attach observer $function for event 'Class.onBeforeDelete' Core_Event::attach('Class.onBeforeDelete', $function);
attachFirst()
Attach observer to the beginning of the queue
public
static attachFirst(string $eventName, string $function[, mixed $options = NULL ]) : mixed
Parameters
- $eventName : string
-
event name
- $function : string
-
function name
- $options : mixed = NULL
-
additional options, default NULL
class my_class { static public function my_function($object, $args) { // do something } } // Attach observer my_class::my_function for event 'Class.onBeforeDelete' Core_Event::attach('Class.onBeforeDelete', array('my_class', 'my_function'));
detach()
Detach observer
public
static detach(string $eventName, string $function) : mixed
Parameters
- $eventName : string
-
event name
- $function : string
-
function name
$function = 'my_function'; // Detach observer $function from event 'Class.onBeforeDelete' Core_Event::detach('Class.onBeforeDelete', $function);
disable()
Disable event
public
static disable(string $eventName) : bool
Parameters
- $eventName : string
-
event name
Return values
bool —TRUE if it was not previously disabled, FALSE otherwise
// Disable event
Core_Event::off('Class.onBeforeDelete');
enable()
Enable event
public
static enable(string $eventName) : mixed
Parameters
- $eventName : string
-
event name
// Enable event Core_Event::enable('Class.onBeforeDelete');
getCount()
Get count of observers
public
static getCount(string $eventName) : mixed
Parameters
- $eventName : string
-
event name
echo Core_Event::getCount('Class.onBeforeDelete');
getLastReturn()
Get the last returned value
public
static getLastReturn() : mixed
$value = Core_Event::getLastReturn();
notify()
Notify all observers. If observer return FALSE, the cycle will stop.
public
static notify( $eventName[, $object = NULL ][, $args = array() ]) : mixed
// Call event 'Class.onBeforeDelete'
Core_Event::notify('Class.onBeforeDelete', $this, array($primaryKey));
Parameters
off()
Disable event. Alias of disable()
public
static off(string $eventName) : mixed
Parameters
- $eventName : string
-
event name
Tags
on()
Enable event. Alias of enable()
public
static on(string $eventName) : mixed
Parameters
- $eventName : string
-
event name
Tags
_isDebug()
Check is debug mode
protected
static _isDebug() : null|bool