From 7c0ab8c6398ad334fd5c4562eb1d244207c1e096 Mon Sep 17 00:00:00 2001 From: whwyy Date: Mon, 18 Dec 2023 21:55:44 +0800 Subject: [PATCH] eee --- src/Annotate/Delete.php | 13 +++++++------ src/Annotate/Get.php | 21 ++++++++++++--------- src/Annotate/Head.php | 12 +++++++----- src/Annotate/Interceptor.php | 22 ++++++++++++++++++---- src/Annotate/Middleware.php | 22 +++++++++++----------- src/Annotate/Options.php | 12 +++++++----- src/Annotate/Post.php | 22 ++++++++++++---------- src/Annotate/Put.php | 10 +++++----- src/Annotate/Route.php | 9 ++++++--- src/Interface/InjectRouteInterface.php | 14 ++++++++------ 10 files changed, 93 insertions(+), 64 deletions(-) diff --git a/src/Annotate/Delete.php b/src/Annotate/Delete.php index 5a9cc20..8c87144 100644 --- a/src/Annotate/Delete.php +++ b/src/Annotate/Delete.php @@ -3,11 +3,10 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Exception; use Kiri\Router\Constrict\RequestMethod; use Kiri\Router\Interface\InjectRouteInterface; -use Kiri\Router\OptionsController; use Kiri\Router\Router; +use ReflectionClass; use ReflectionException; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] @@ -25,19 +24,21 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface /** - * @param object $class + * @param ReflectionClass $class * @param string $method * @return void - * @throws + * @throws ReflectionException */ - public function dispatch(object $class, string $method): void + public function dispatch(ReflectionClass $class, string $method): void { + $controller = \Kiri::getDi()->makeReflection($class); + // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; } - Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$class, $method]); + Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$controller, $method]); } diff --git a/src/Annotate/Get.php b/src/Annotate/Get.php index c901a6a..41e0a26 100644 --- a/src/Annotate/Get.php +++ b/src/Annotate/Get.php @@ -8,6 +8,7 @@ use Kiri\Router\Constrict\RequestMethod; use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\OptionsController; use Kiri\Router\Router; +use ReflectionClass; use ReflectionException; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] @@ -24,20 +25,22 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface } - /** - * @param object $class - * @param string $method - * @return void - * @throws - */ - public function dispatch(object $class, string $method): void + /** + * @param ReflectionClass $class + * @param string $method + * @return void + * @throws ReflectionException + */ + public function dispatch(ReflectionClass $class, string $method): void { - // TODO: Implement dispatch() method. + $controller = \Kiri::getDi()->makeReflection($class); + + // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; } - Router::addRoute(RequestMethod::REQUEST_GET, $path, [$class, $method]); + Router::addRoute(RequestMethod::REQUEST_GET, $path, [$controller, $method]); } } diff --git a/src/Annotate/Head.php b/src/Annotate/Head.php index bbb23ed..8e40bbf 100644 --- a/src/Annotate/Head.php +++ b/src/Annotate/Head.php @@ -3,10 +3,11 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Exception; +use Kiri; use Kiri\Router\Constrict\RequestMethod; use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\Router; +use ReflectionClass; use ReflectionException; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] @@ -24,19 +25,20 @@ class Head extends AbstractRequestMethod implements InjectRouteInterface /** - * @param object $class + * @param ReflectionClass $class * @param string $method * @return void - * @throws + * @throws ReflectionException */ - public function dispatch(object $class, string $method): void + public function dispatch(ReflectionClass $class, string $method): void { + $controller = Kiri::getDi()->makeReflection($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; } - Router::addRoute(RequestMethod::REQUEST_HEAD, $path, [$class, $method]); + Router::addRoute(RequestMethod::REQUEST_HEAD, $path, [$controller, $method]); } diff --git a/src/Annotate/Interceptor.php b/src/Annotate/Interceptor.php index a5b9922..c351815 100644 --- a/src/Annotate/Interceptor.php +++ b/src/Annotate/Interceptor.php @@ -4,12 +4,26 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; +use Kiri\Router\Interface\InjectRouteInterface; +use ReflectionClass; + #[\Attribute(\Attribute::TARGET_METHOD)] -class Interceptor +class Interceptor implements InjectRouteInterface { - public function __construct() - { - } + public function __construct() + { + } + + + /** + * @param ReflectionClass $class + * @param string $method + * @return void + */ + public function dispatch(ReflectionClass $class, string $method): void + { + // TODO: Implement dispatch() method. + } } diff --git a/src/Annotate/Middleware.php b/src/Annotate/Middleware.php index 0a047ac..91c7083 100644 --- a/src/Annotate/Middleware.php +++ b/src/Annotate/Middleware.php @@ -3,11 +3,12 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Kiri\Di\Interface\InjectPropertyInterface; use Kiri\Router\Base\Middleware as MiddlewareManager; +use Kiri\Router\Interface\InjectRouteInterface; +use ReflectionClass; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -class Middleware implements InjectPropertyInterface +class Middleware implements InjectRouteInterface { /** @@ -18,17 +19,16 @@ class Middleware implements InjectPropertyInterface } - /** - * @param object $class - * @param string $property - * @return void - * @throws - */ - public function dispatch(object $class, string $property): void - { + /** + * @param ReflectionClass $class + * @param string $method + * @return void + */ + public function dispatch(ReflectionClass $class, string $method): void + { $middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class); - $middlewareManager->set($class::class, $property, $this->middleware); + $middlewareManager->set($class->getName(), $method, $this->middleware); } diff --git a/src/Annotate/Options.php b/src/Annotate/Options.php index cfbd2fd..efb1e58 100644 --- a/src/Annotate/Options.php +++ b/src/Annotate/Options.php @@ -3,11 +3,11 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Exception; +use Kiri; use Kiri\Router\Constrict\RequestMethod; use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\Router; -use ReflectionException; +use ReflectionClass; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Options extends AbstractRequestMethod implements InjectRouteInterface @@ -29,14 +29,16 @@ class Options extends AbstractRequestMethod implements InjectRouteInterface * @return void * @throws */ - public function dispatch(object $class, string $method): void - { + public function dispatch(ReflectionClass $class, string $method): void + { + $controller = Kiri::getDi()->makeReflection($class); + // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; } - Router::addRoute(RequestMethod::REQUEST_OPTIONS, $path, [$class, $method]); + Router::addRoute(RequestMethod::REQUEST_OPTIONS, $path, [$controller, $method]); } diff --git a/src/Annotate/Post.php b/src/Annotate/Post.php index 071019f..25b0abc 100644 --- a/src/Annotate/Post.php +++ b/src/Annotate/Post.php @@ -3,11 +3,11 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Exception; +use Kiri; use Kiri\Router\Constrict\RequestMethod; use Kiri\Router\Interface\InjectRouteInterface; -use Kiri\Router\OptionsController; use Kiri\Router\Router; +use ReflectionClass; use ReflectionException; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] @@ -24,20 +24,22 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface } - /** - * @param object $class - * @param string $method - * @return void - * @throws - */ - public function dispatch(object $class, string $method): void + /** + * @param ReflectionClass $class + * @param string $method + * @return void + * @throws ReflectionException + */ + public function dispatch(ReflectionClass $class, string $method): void { // TODO: Implement dispatch() method. + $controller = Kiri::getDi()->makeReflection($class); + $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; } - Router::addRoute(RequestMethod::REQUEST_POST, $path, [$class, $method]); + Router::addRoute(RequestMethod::REQUEST_POST, $path, [$controller, $method]); } diff --git a/src/Annotate/Put.php b/src/Annotate/Put.php index ea841ba..db0581a 100644 --- a/src/Annotate/Put.php +++ b/src/Annotate/Put.php @@ -3,12 +3,11 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Exception; +use Kiri; use Kiri\Router\Constrict\RequestMethod; use Kiri\Router\Interface\InjectRouteInterface; -use Kiri\Router\OptionsController; use Kiri\Router\Router; -use ReflectionException; +use ReflectionClass; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] class Put extends AbstractRequestMethod implements InjectRouteInterface @@ -30,14 +29,15 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface * @return void * @throws */ - public function dispatch(object $class, string $method): void + public function dispatch(ReflectionClass $class, string $method): void { + $controller = Kiri::getDi()->makeReflection($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; } - Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$class, $method]); + Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$controller, $method]); } } diff --git a/src/Annotate/Route.php b/src/Annotate/Route.php index d35ce20..485de4b 100644 --- a/src/Annotate/Route.php +++ b/src/Annotate/Route.php @@ -5,6 +5,7 @@ namespace Kiri\Router\Annotate; use Kiri\Router\Constrict\RequestMethod; use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\Router; +use ReflectionClass; use ReflectionException; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] @@ -23,17 +24,19 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface /** - * @param object $class + * @param ReflectionClass $class * @param string $method * @return void + * @throws ReflectionException */ - public function dispatch(object $class, string $method): void + public function dispatch(ReflectionClass $class, string $method): void { + $controller = \Kiri::getDi()->makeReflection($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; } - Router::addRoute([$this->method], $path, [$class, $method]); + Router::addRoute([$this->method], $path, [$controller, $method]); } } diff --git a/src/Interface/InjectRouteInterface.php b/src/Interface/InjectRouteInterface.php index 282ee4d..4878080 100644 --- a/src/Interface/InjectRouteInterface.php +++ b/src/Interface/InjectRouteInterface.php @@ -3,15 +3,17 @@ declare(strict_types=1); namespace Kiri\Router\Interface; +use ReflectionClass; + interface InjectRouteInterface { - /** - * @param object $class - * @param string $method - * @return void - */ - public function dispatch(object $class, string $method): void; + /** + * @param ReflectionClass $class + * @param string $method + * @return void + */ + public function dispatch(ReflectionClass $class, string $method): void; }