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

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

挂载插件到钩子 \Cml\Plugin::mount('hookName', [ function() {//匿名函数 }, '\App\Test\Plugins' => 'run' //对象, '\App\Test\Plugins::run'////静态方法 ]);
public static mount ( string $hook, array $params = [] )
$hook string 要挂载的目标钩子
$params array 相应参数
    public static function mount($hook, $params = [])
    {
        is_array($params) || ($params = [$params]);
        if (isset(self::$mountInfo[$hook])) {
            self::$mountInfo[$hook] += $params;
        } else {
            self::$mountInfo[$hook] = $params;
        }
    }

Usage Example

Пример #1
0
 /**
  * 未找到控制器的时候设置勾子
  *
  */
 public static function montFor404Page()
 {
     Plugin::mount('cml.before_show_404_page', [function () {
         $cmdLists = Config::get('cmlframework_system_command');
         $cmd = strtolower(trim(Cml::getContainer()->make('cml_route')->getAppName(), '/'));
         if (isset($cmdLists[$cmd])) {
             call_user_func($cmdLists[$cmd]);
         }
     }]);
     Plugin::hook('cml.before_show_404_page');
 }
All Usage Examples Of Cml\Plugin::mount