From 31bba391445e5374dcb46cdfb6ccb6eefe904a8d Mon Sep 17 00:00:00 2001 From: topnuomi <1130395124@qq.com> Date: Sat, 24 Aug 2019 12:20:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E5=89=8D=E7=BD=AE=E3=80=81=E5=90=8E?= =?UTF-8?q?=E7=BD=AE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/library/http/Request.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/framework/library/http/Request.php b/framework/library/http/Request.php index 52cc95b..aa63e3a 100644 --- a/framework/library/http/Request.php +++ b/framework/library/http/Request.php @@ -411,14 +411,33 @@ class Request $method = $this->router->method; $params = $this->router->params; + $data = null; $object = new $ctrl(); $reflectionClass = new \ReflectionClass($ctrl); if ($reflectionClass->hasMethod('_init')) { $data = $object->_init(); } - if (!isset($data)) { - $reflectionMethod = new \ReflectionMethod($ctrl, $method); - $data = $reflectionMethod->invokeArgs($object, $params); + + if ($data === null || $data === '') { + // 前置方法 + $beforeReturnData = null; + $beforeMethod = 'before_' . $method; + if ($reflectionClass->hasMethod($beforeMethod)) { + $beforeReturnData = $object->{$beforeMethod}(); + } + + if ($beforeReturnData === null || $beforeReturnData === '') { + $reflectionMethod = new \ReflectionMethod($ctrl, $method); + $data = $reflectionMethod->invokeArgs($object, $params); + + // 后置方法 + $afterMethod = 'after_' . $method; + if ($reflectionClass->hasMethod($afterMethod)) { + $object->{$afterMethod}(); + } + } else { + $data = $beforeReturnData; + } } $this->afterRoute($data);