From 85959626376c811a26ccd9a2d0341e4efb3740ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 15 Dec 2020 18:42:54 +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 --- Annotation/Route/Node.php | 35 ++++++++++++++++++++++++++++------- HttpServer/Route/Reduce.php | 1 - 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Annotation/Route/Node.php b/Annotation/Route/Node.php index 95fdcb13..80da06e4 100644 --- a/Annotation/Route/Node.php +++ b/Annotation/Route/Node.php @@ -3,30 +3,51 @@ namespace Annotation\Route; +use HttpServer\Route\Node as RNode; +use ReflectionException; +use Snowflake\Exception\NotFindClassException; +use Snowflake\Snowflake; trait Node { /** - * @param $node - * @return mixed + * @param RNode $node + * @return RNode + * @throws */ - public function add($node): mixed + public function add(RNode $node): RNode { if (!empty($this->middleware)) { - $node->addMiddleware($this->middleware); + $node->addMiddleware($this->reflectClass($this->middleware)); } if (!empty($this->interceptor)) { - $node->addInterceptor($this->interceptor); + $node->addInterceptor($this->reflectClass($this->interceptor)); } if (!empty($this->limits)) { - $node->addLimits($this->limits); + $node->addLimits($this->reflectClass($this->limits)); } if (!empty($this->after)) { - $node->addAfter($this->after); + $node->addAfter($this->reflectClass($this->after)); } return $node; } + + /** + * @param array $classes + * @return array + * @throws ReflectionException + * @throws NotFindClassException + */ + private function reflectClass(array $classes): array + { + $di = Snowflake::getDi(); + foreach ($classes as $key => $class) { + $classes[$key] = [$di->get($class), 'onHandler']; + } + return $classes; + } + } diff --git a/HttpServer/Route/Reduce.php b/HttpServer/Route/Reduce.php index c3880116..8b373bdf 100644 --- a/HttpServer/Route/Reduce.php +++ b/HttpServer/Route/Reduce.php @@ -51,7 +51,6 @@ class Reduce if ($pipe instanceof Middleware) { return $pipe->onHandler($passable, $stack); } else { - var_dump($pipe); return call_user_func($pipe, $passable, $stack); } };