/** * 触发事件 * @param $type * @param $data * @return mixed * @throws Exception\NotFound */ function trigger($type, $data) { /** * 异步,将事件压入队列 */ if ($this->async) { return $this->_queue->push(array('type' => $type, 'data' => $data)); } else { return $this->_execute($type, $data); } }
/** * 投递事件 * @return mixed * @throws Exception\NotFound */ function dispatch() { $_args = func_get_args(); $function = $_args[0]; /** * 同步,直接在引发事件时处理 */ if (!$this->async) { if (!is_callable($function)) { throw new Exception\NotFound("function {$function} not found."); } return call_user_func_array($function, array_slice($_args, 1)); } else { return $this->_queue->push($_args); } }