This commit is contained in:
thinkphp
2016-06-01 16:34:41 +08:00

View File

@@ -91,10 +91,12 @@ class Hook
* @param string $tag 标签名称
* @param mixed $params 传入参数
* @param mixed $extra 额外参数
* @return void
* @param bool $once 只获取一个有效返回值
* @return mixed
*/
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) {
@@ -104,6 +106,10 @@ class Hook
$result = self::exec($name, $tag, $params, $extra);
if (!is_null($result) && $once) {
return $result;
}
if (APP_DEBUG) {
Debug::remark('behavior_end', 'time');
if ($name instanceof \Closure) {
@@ -115,11 +121,12 @@ class Hook
}
if (false === $result) {
// 如果返回false 则中断行为执行
return;
break;
}
$results[] = $result;
}
}
}
return $result;
return $once ? null : $results;
}
/**