<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                * 用途 面向切面編程,向某個點注入處理流程 * 定義 ~~~ trait HookTrait { /** * 默認鉤子方法 * * @var unknown */ protected $_hookMethod = 'hook'; /** * 鉤子 * * @var unknown */ protected $_hooks = []; /** * 獲取鉤子 * * @param string $hook * * @return array|null */ public function getHook($name = null) { if (empty($name)) { return $this->_hooks; } else { return isset($this->_hooks[$name]) ? $this->_hooks[$name] : []; } } /** * 增加鉤子 * * @param string $name * @param mixed $behavior * @param integer $weight * @param string $tagKey */ public function addHook($name, $behavior, $weight = 0, $key = null) { if (is_array($behavior)) { // 添加多個鉤子 foreach ($behavior as $item) { $this->addHook($name, $item, $key, $weight); } } else { isset($this->_hooks[$name]) || $this->_hooks[$name] = []; // 避免重復添加 $key || $key = md5(serialize($behavior)); $this->_hooks[$name][$key] = $this->formatHook($behavior, $weight, $key); } } /** * 調用鉤子 * * @param string $name * @param mixed $params * @param mixed $extra * * @return array */ public function callHook($name, &$params, $extra = null) { $results = []; $hooks = $this->getHook($name); // 排序 usort($hooks, [ $this, 'compareHookWeight' ]); foreach ($hooks as $key => $hook) { $results[$key] = $this->executeHook($hook['behavior'], $params, $extra); // 返回false則停止執行 if (false === $results[$key]) { break; } } return $results; } /** * 重置鉤子 */ public function resetHook() { $this->_hooks = []; } /** * 執行鉤子 * * @param string $behavior * @param mixed $params * @param mixed $extra * * @return mixed */ protected function executeHook($behavior, &$params = null, $extra = null) { if (is_string($behavior)) { if (strpos($behavior, '::')) { $behavior = explode('::', $behavior, 2); } else { $behavior = [ $behavior, $this->_hookMethod ]; } } return call_user_func_array($behavior, [ &$params, $extra, $this ]); } /** * 比較兩個鉤子權值 * * @param array $a * @param array $b * * @return boolean */ protected function compareHookWeight($a, $b) { return $a['weight'] <= $b['weight']; } /** * 格式化鉤子 * * @param mixed $behavior * @param number $weight * @param string $key * * @return array */ protected function formatHook($behavior, $weight = 0, $key = null) { return [ 'behavior' => $behavior, 'weight' => $weight, 'key' => $key ]; } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看