Cml\Plugin::hook PHP Метод

hook() публичный статический Метод

执行插件
public static hook ( string $hook, array $params = [] ) : mixed
$hook string 插件钩子名称
$params array 参数
Результат mixed
    public static function hook($hook, $params = [])
    {
        $hookRun = isset(self::$mountInfo[$hook]) ? self::$mountInfo[$hook] : null;
        if (!is_null($hookRun)) {
            foreach ($hookRun as $key => $val) {
                if (is_int($key)) {
                    $callBack = $val;
                } else {
                    $plugin = new $key();
                    $callBack = [$plugin, $val];
                }
                $return = call_user_func_array($callBack, array_slice(func_get_args(), 1));
                if (!is_null($return)) {
                    return $return;
                }
            }
        }
        return null;
    }

Usage Example

Пример #1
0
 /**
  * 输出数据
  *
  */
 public function display()
 {
     header('Content-Type: application/json;charset=' . Config::get('default_charset'));
     if ($GLOBALS['debug']) {
         $sqls = Debug::getSqls();
         if (isset($sqls[0])) {
             $this->args['sql'] = implode($sqls, ', ');
         }
     }
     Plugin::hook('cml.before_cml_stop');
     exit(json_encode($this->args, PHP_VERSION >= '5.4.0' ? JSON_UNESCAPED_UNICODE : 0));
 }
All Usage Examples Of Cml\Plugin::hook