/** * 构造函数,默认启动埋在此钩子下的扩展服务 * * @param string $hookKey 钩子点,默认为类名 * @param string $interface * @param object $srv * @return void */ private function __construct($hookKey) { if (!($hooks = PwHook::getRegistry('s_' . $hookKey))) { return; } if (!($map = PwHook::resolveActionHook($hooks))) { return; } foreach ($map as $key => $value) { $this->appendDo(Wekit::getInstance($value['class'], $value['loadway']), $value['method']); } }
protected function _prepare() { if ($this->_ready) { return !empty($this->_do); } !$this->_srv && ($this->_srv = $this); foreach ($this->_key as $key => $hookKey) { if (!($hooks = PwHook::getRegistry($hookKey))) { continue; } if (!($map = PwHook::resolveActionHook($hooks, $this->_srv))) { continue; } foreach ($map as $key => $value) { $this->appendDo(Wekit::getInstance($value['class'], $value['loadway'], array($this->_srv))); } } $this->_ready = true; return !empty($this->_do); }
/** * action Hook 注册 * * @param string $registerKey 扩展点别名 * @param PwBaseHookService $bp * @throws PwException * @return void */ protected function runHook($registerKey, $bp) { if (!$registerKey) { return; } if (!$bp instanceof PwBaseHookService) { throw new PwException('class.type.fail', array('{parm1}' => 'src.library.base.PwBaseController.runHook', '{parm2}' => 'PwBaseHookService', '{parm3}' => get_class($bp))); } if (!($filters = PwHook::getRegistry($registerKey))) { return; } if (!($filters = PwHook::resolveActionHook($filters, $bp))) { return; } $args = func_get_args(); $_filters = array(); foreach ($filters as $key => $value) { $args[0] = isset($value['method']) ? $value['method'] : ''; $_filters[] = array('class' => $value['class'], 'args' => $args); } $this->resolveActionFilter($_filters); }