From 1dcace00ef00f2f6141dc05e857ff0ec2ec8fdc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 6 Aug 2021 10:50:07 +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/Middleware.php | 16 +++++--- Annotation/Route/Route.php | 69 ++++++++++++++++----------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/Annotation/Route/Middleware.php b/Annotation/Route/Middleware.php index 69b2d762..cf9101e1 100644 --- a/Annotation/Route/Middleware.php +++ b/Annotation/Route/Middleware.php @@ -6,6 +6,8 @@ namespace Annotation\Route; use Annotation\Attribute; use HttpServer\Route\MiddlewareManager; +use ReflectionException; +use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; use HttpServer\IInterface\Middleware as IMiddleware; @@ -30,7 +32,7 @@ use HttpServer\IInterface\Middleware as IMiddleware; $array = []; foreach ($this->middleware as $value) { - $sn = Snowflake::createObject($value); + $sn = di($value); if (!($sn instanceof IMiddleware)) { continue; } @@ -40,11 +42,13 @@ use HttpServer\IInterface\Middleware as IMiddleware; } - /** - * @param mixed $class - * @param mixed|null $method - * @return Middleware - */ + /** + * @param mixed $class + * @param mixed|null $method + * @return $this + * @throws ReflectionException + * @throws NotFindClassException + */ public function execute(mixed $class, mixed $method = null): static { $middleware = Snowflake::getDi()->get(MiddlewareManager::class); diff --git a/Annotation/Route/Route.php b/Annotation/Route/Route.php index be7c2fa3..f9fe4cba 100644 --- a/Annotation/Route/Route.php +++ b/Annotation/Route/Route.php @@ -7,49 +7,46 @@ namespace Annotation\Route; use Annotation\Attribute; use Exception; use HttpServer\Route\Router; -use Snowflake\Exception\ConfigException; use Snowflake\Snowflake; #[\Attribute(\Attribute::TARGET_METHOD)] class Route extends Attribute { - /** - * Route constructor. - * @param string $uri - * @param string $method - * @param string $version - */ - public function __construct( - public string $uri, - public string $method, - public string $version = 'v.1.0' - ) - { - } + /** + * Route constructor. + * @param string $uri + * @param string $method + * @param string $version + */ + public function __construct( + public string $uri, + public string $method, + public string $version = 'v.1.0' + ) + { + } - /** - * @param mixed $class - * @param mixed|null $method - * @return Router - * @throws Exception - */ - public function execute(mixed $class, mixed $method = null): Router - { - // TODO: Implement setHandler() method. - $router = Snowflake::app()->getRouter(); - $node = $router->addRoute($this->uri, [$class, $method], $this->method); - if ($node !== null) { - $attribute = Snowflake::getDi()->getMethodAttribute($class::class, $method); - foreach ($attribute as $item) { - if ($item instanceof Route) { - continue; - } - $item->execute($class, $method); - } - } - return $router; - } + /** + * @param mixed $class + * @param mixed|null $method + * @return Router + * @throws Exception + */ + public function execute(mixed $class, mixed $method = null): Router + { + // TODO: Implement setHandler() method. + $router = Snowflake::app()->getRouter(); + $attribute = Snowflake::getDi()->getMethodAttribute($class::class, $method); + foreach ($attribute as $item) { + if ($item instanceof Route) { + continue; + } + $item->execute($class, $method); + } + $router->addRoute($this->uri, [$class, $method], $this->method); + return $router; + } }