From c251fa7bec08c16c70f8d8e76d03aaa54f14d113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 27 Jul 2021 14:19:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Route/Node.php | 40 ++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/HttpServer/Route/Node.php b/HttpServer/Route/Node.php index 24a28e9c..a7e71708 100644 --- a/HttpServer/Route/Node.php +++ b/HttpServer/Route/Node.php @@ -115,24 +115,46 @@ class Node extends HttpService /** @var Aop $aop */ $aop = Snowflake::app()->get('aop'); if ($this->handler instanceof Closure || !$aop->hasAop($this->handler)) { - return (static function ($application) { - $dispatchParam = Context::getContext('dispatch-param', [\request()]); - if (is_array($application->handler)) { - Snowflake::injectProperty($application->handler[0]); - } - return call_user_func($application->handler, ...$dispatchParam); - })($application); + return $this->normalHandler($application); + } else { + return $this->aopHandler($aop->getAop($this->handler), $application); } + } + + /** + * @param $aop + * @param $application + * @return Closure + */ + private function aopHandler($aop, $application): Closure + { $reflect = $aop->getAop($this->handler); - return (static function ($callback, $application, $reflect) { + $callback = [$reflect->getMethod('invoke'), 'invokeArgs']; + return static function () use ($callback, $application, $reflect) { $dispatchParam = Context::getContext('dispatch-param', [\request()]); $asp = $reflect->newInstance($application->handler); if (is_array($application->handler)) { Snowflake::injectProperty($application->handler[0]); } call_user_func($callback, $asp, $dispatchParam); - })([$reflect->getMethod('invoke'), 'invokeArgs'], $application, $reflect); + }; + } + + + /** + * @param $application + * @return Closure + */ + private function normalHandler($application): Closure + { + return static function ($application) use ($application) { + $dispatchParam = Context::getContext('dispatch-param', [\request()]); + if (is_array($application->handler)) { + Snowflake::injectProperty($application->handler[0]); + } + return call_user_func($application->handler, ...$dispatchParam); + }; }