Event class.
Protected constructor since this is a static class.
NULL
protected function __construct()
{
// Nothing here
}
Adds an event listener to the queue.
| Type | Description |
|---|---|
| string | Event name |
| callback | Event callback |
NULL
public static function register($name, $callback)
{
static::$events[$name][] = $callback;
}
Returns TRUE if an event listener is registered for the event and FALSE if not.
| Type | Description |
|---|---|
| string | Event name |
boolean
public static function registered($name)
{
return isset(static::$events[$name]);
}
Clears all event listeners for an event.
| Type | Description |
|---|---|
| string | Event name |
NULL
public static function clear($name)
{
unset(static::$events[$name]);
}
Runs all callbacks for an event and returns an array contaning the return values of each callback.
| Type | Description |
|---|---|
| string | Event name |
| array | (optional) Callback parameters |
array
public static function trigger($name, array $params = array())
{
$values = array();
if(isset(static::$events[$name]))
{
foreach(static::$events[$name] as $event)
{
$values[] = call_user_func_array($event, $params);
}
}
return $values;
}