<?php
namespace app\common\controller;
use think\Controller;
use think\Db;

class Hooks{
	
   public function run($param = [])
    {

		
   	  //$Hook= new \think\Hook; 
        // 动态加入命名空间
        \think\Loader::addNamespace('addons', ADDON_PATH);
        // 获取钩子数据
        $data = cache('hooks');
	
        if(!$data){
            $hooks = Db::name('Hooks')->column('name,addons');
		
            // 获取钩子的实现插件信息
            foreach ($hooks as $key => $value) {
                if($value){
                    $map[]=['status', "=", 1];
					$names=array();
						$names         = explode(',', $value);
                        
				        $map[]=['name','IN', $names];
			
                    $data = db::name('Addons')->where($map)->column('id,name');
                    if($data){
                        $addons = array_intersect($names, $data);
						
                       //\Hook::add($key, array_map('get_addon_class',$addons));
                    }
                }
            }	
			
            //cache('hooks', \Hook::get());
        }else{
            Hook::import($data, false);
         }

    }
}