From 5f053e4aa7c1f3b5ece08caaa4696208c1049a55 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 20 May 2016 16:43:34 +0800 Subject: [PATCH] =?UTF-8?q?Hook=E7=B1=BB=E7=9A=84=E8=A1=8C=E4=B8=BA?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=94=AF=E6=8C=81=20=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E5=92=8C=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 | 14 ++++++++++---- library/think/Request.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/library/think/Hook.php b/library/think/Hook.php index f5e55af4..9746f487 100644 --- a/library/think/Hook.php +++ b/library/think/Hook.php @@ -114,7 +114,7 @@ class Hook /** * 执行某个行为 - * @param string $class 行为类名称 + * @param mixed $class 要执行的行为 * @param string $tag 方法名(标签名) * @param Mixed $params 传人的参数 * @return mixed @@ -122,9 +122,15 @@ class Hook public static function exec($class, $tag = '', &$params = null) { if ($class instanceof \Closure) { - return $class($params); + $result = call_user_func_array($class, $params); + } elseif (is_object($class)) { + $result = call_user_func_array([$class, $tag], $params); + } elseif (is_array($class)) { + $result = call_user_func_array($class, $params); + } else { + $obj = new $class(); + $result = ($tag && is_callable([$obj, $tag])) ? $obj->$tag($params) : $obj->run($params); } - $obj = new $class(); - return ($tag && is_callable([$obj, $tag])) ? $obj->$tag($params) : $obj->run($params); + return $result; } } diff --git a/library/think/Request.php b/library/think/Request.php index 3787d11a..8427a4a5 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -42,7 +42,7 @@ class Request protected $baseFile; /** - * @var string 根目录 + * @var string 访问的ROOT地址 */ protected $root;