From 5ab7f81c4473595f5dd1fcad3a556988b13f31a8 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Wed, 1 Jun 2016 16:32:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A1=8C=E4=B8=BA?= =?UTF-8?q?=E6=89=A9=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Hook.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/library/think/Hook.php b/library/think/Hook.php index 82834542..838ab100 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -88,13 +88,15 @@ class Hook /** * 监听标签的行为 - * @param string $tag 标签名称 - * @param mixed $params 传入参数 - * @param mixed $extra 额外参数 - * @return void + * @param string $tag 标签名称 + * @param mixed $params 传入参数 + * @param mixed $extra 额外参数 + * @param bool $once 只获取一个有效返回值 + * @return bool|mixed|void */ - public static function listen($tag, &$params = null,$extra=null) { - $result = true; + public static function listen($tag, &$params = null, $extra = null, $once = false) + { + $results = []; if (isset(self::$tags[$tag])) { foreach (self::$tags[$tag] as $name) { @@ -102,7 +104,11 @@ class Hook Debug::remark('behavior_start', 'time'); } - $result = self::exec($name, $tag, $params,$extra); + $result = self::exec($name, $tag, $params, $extra); + + if (!is_null($result) && $once) { + return $result; + } if (APP_DEBUG) { Debug::remark('behavior_end', 'time'); @@ -115,11 +121,12 @@ class Hook } if (false === $result) { // 如果返回false 则中断行为执行 - return; + break; } + $results[] = $result; } } - return $result; + return $once ? null : $results; } /** From 96992e9f7b39b38c5078a725995f58cee6570f13 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Wed, 1 Jun 2016 16:33:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Hook.php b/library/think/Hook.php index 838ab100..0a1fe9e4 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -92,7 +92,7 @@ class Hook * @param mixed $params 传入参数 * @param mixed $extra 额外参数 * @param bool $once 只获取一个有效返回值 - * @return bool|mixed|void + * @return mixed */ public static function listen($tag, &$params = null, $extra = null, $once = false) {