ACC SHELL
<?php
// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is 100% my work. Do not copy.
class Event
{
public static $_ = array();
public $id = '';
public $callbacks = array();
public $options = array();
public $result = array();
public static function invoke($id, $options = null)
{
if (!is_array($id))
$id = array($id);
foreach ($id as $temp)
self::e($temp)->call($options);
}
public static function e($id)
{
if (!isset(self::$_[$id]))
self::$_[$id] = new Event($id);
return self::$_[$id];
}
public function __construct($id, $options = array())
{
$this->id = $id;
$this->options = $options;
}
public function set($key, $value = null)
{
if ($value === null)
unset($this->options[$key]);
else
$this->options[$key] = $value;
}
public function get($key, $default = null)
{
return isset($this->options[$key]) ? $this->options[$key] : $default;
}
public function add($callback, $order = false)
{
if ($order)
$this->callbacks[$order] = $callback;
else
$this->callbacks[] = $callback;
ksort($this->callbacks);
}
public function remove($callback)
{
foreach ($this->callbacks as $k => $v)
if ($callback == $v)
unset($this->callbacks[$k]);
ksort($this->callbacks);
}
public function call($options = array(), $last_result = null, $last = false)
{
$temp = $this->options;
$this->options = array_merge($this->options, $options);
$this->result = array();
foreach ($this->callbacks as $k => $v)
$this->result[$k] = $last_result = call_user_func($v, $this, $last_result);
$this->options = $temp;
return ($last) ? $last_result : $this->result;
}
}
?>
ACC SHELL 2018