From efd34d53fda1ceae5a4c3ba0ddf31f2b607cd229 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 18 Dec 2016 09:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BHook=E7=B1=BBexec=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=89=A7=E8=A1=8C=20=E5=8C=85=E6=8B=AC?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Hook.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/think/Hook.php b/library/think/Hook.php index f247c621..4d69ca54 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -13,6 +13,7 @@ namespace think; use think\App; use think\Debug; +use think\Loader; use think\Log; class Hook @@ -111,15 +112,23 @@ class Hook public static function exec($class, $tag = '', &$params = null, $extra = null) { App::$debug && Debug::remark('behavior_start', 'time'); - if (is_callable($class)) { + $method = Loader::parseName($tag, 1, false); + if ($class instanceof \Closure) { $result = call_user_func_array($class, [ & $params, $extra]); $class = 'Closure'; + } elseif (is_array($class)) { + list($class, $method) = $class; + + $result = (new $class())->$method($params, $extra); + $class = $class . '->' . $method; } elseif (is_object($class)) { - $result = $class->$tag($params, $extra); + $result = $class->$method($params, $extra); $class = get_class($class); + } elseif (strpos($class, '::')) { + $result = call_user_func_array($class, [ & $params, $extra]); } else { $obj = new $class(); - $method = ($tag && is_callable([$obj, $tag])) ? $tag : 'run'; + $method = ($tag && is_callable([$obj, $method])) ? $method : 'run'; $result = $obj->$method($params, $extra); } if (App::$debug) {