20 public function listen($name,$callback,$prio = 50){
21 \Rsi\Record::add($this->_events,[$name,$prio],[]);
22 $this->_events[$name][$prio][] = $callback;
23 ksort($this->_events[$name]);
32 public function trigger($name,$sender = null){
33 if($log = $this->
component(
'log')) $log->debug(__CLASS__ .
"::trigger('$name',...)",__FILE__,__LINE__);
34 if(array_key_exists($name,$this->_events)){
35 $this->_counts[$name] = $this->
count($name) + 1;
36 $params = array_slice(func_get_args(),1);
37 foreach($this->_events[$name] as $events)
foreach($events as $callback){
38 if(is_array($callback) && is_string($name = \
Rsi\Record::value($callback))) $callback = [$this->
component($name),array_pop($callback)];
39 if(($result = call_user_func_array($callback,$params)) !== null)
return $result;
50 return $this->_counts[$name] ?? (array_key_exists($name,$this->_events) ? 0 :
false);
listen($name, $callback, $prio=50)
Start listening to an event.
trigger($name, $sender=null)
Trigger an event.
count($name)
Number of times an event has been triggered.
component($name)
Get a component (local or default).