From a51b666303a9a47d53434f515ba1053bede25228 Mon Sep 17 00:00:00 2001 From: whwyy Date: Mon, 18 Dec 2023 22:23:17 +0800 Subject: [PATCH] eee --- src/Annotate/Delete.php | 13 ++--- src/Annotate/Get.php | 15 ++---- src/Annotate/Head.php | 13 ++--- src/Annotate/Interceptor.php | 9 ++-- src/Annotate/Middleware.php | 11 ++-- src/Annotate/Options.php | 9 ++-- src/Annotate/Post.php | 13 ++--- src/Annotate/Put.php | 15 +++--- src/Annotate/Route.php | 14 ++---- src/Aspect/Aspect.php | 70 +++++++------------------- src/Interface/InjectRouteInterface.php | 19 ------- src/Validator/BindForm.php | 6 ++- src/Validator/Binding.php | 1 - 13 files changed, 67 insertions(+), 141 deletions(-) delete mode 100644 src/Interface/InjectRouteInterface.php diff --git a/src/Annotate/Delete.php b/src/Annotate/Delete.php index 8c87144..c063974 100644 --- a/src/Annotate/Delete.php +++ b/src/Annotate/Delete.php @@ -3,14 +3,12 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; +use Kiri\Di\Interface\InjectMethodInterface; 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)] -class Delete extends AbstractRequestMethod implements InjectRouteInterface +class Delete extends AbstractRequestMethod implements InjectMethodInterface { @@ -24,14 +22,13 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface /** - * @param ReflectionClass $class + * @param string $class * @param string $method * @return void - * @throws ReflectionException */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { - $controller = \Kiri::getDi()->makeReflection($class); + $controller = \Kiri::getDi()->get($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); diff --git a/src/Annotate/Get.php b/src/Annotate/Get.php index 41e0a26..6e06b54 100644 --- a/src/Annotate/Get.php +++ b/src/Annotate/Get.php @@ -3,16 +3,12 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Exception; +use Kiri\Di\Interface\InjectMethodInterface; 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)] -class Get extends AbstractRequestMethod implements InjectRouteInterface +class Get extends AbstractRequestMethod implements InjectMethodInterface { @@ -26,14 +22,13 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface /** - * @param ReflectionClass $class + * @param string $class * @param string $method * @return void - * @throws ReflectionException */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { - $controller = \Kiri::getDi()->makeReflection($class); + $controller = \Kiri::getDi()->get($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); diff --git a/src/Annotate/Head.php b/src/Annotate/Head.php index 8e40bbf..c432106 100644 --- a/src/Annotate/Head.php +++ b/src/Annotate/Head.php @@ -5,13 +5,11 @@ namespace Kiri\Router\Annotate; use Kiri; use Kiri\Router\Constrict\RequestMethod; -use Kiri\Router\Interface\InjectRouteInterface; +use Kiri\Di\Interface\InjectMethodInterface; use Kiri\Router\Router; -use ReflectionClass; -use ReflectionException; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -class Head extends AbstractRequestMethod implements InjectRouteInterface +class Head extends AbstractRequestMethod implements InjectMethodInterface { @@ -25,14 +23,13 @@ class Head extends AbstractRequestMethod implements InjectRouteInterface /** - * @param ReflectionClass $class + * @param string $class * @param string $method * @return void - * @throws ReflectionException */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { - $controller = Kiri::getDi()->makeReflection($class); + $controller = Kiri::getDi()->get($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { diff --git a/src/Annotate/Interceptor.php b/src/Annotate/Interceptor.php index c351815..161219c 100644 --- a/src/Annotate/Interceptor.php +++ b/src/Annotate/Interceptor.php @@ -4,11 +4,10 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; -use Kiri\Router\Interface\InjectRouteInterface; -use ReflectionClass; +use Kiri\Di\Interface\InjectMethodInterface; #[\Attribute(\Attribute::TARGET_METHOD)] -class Interceptor implements InjectRouteInterface +class Interceptor implements InjectMethodInterface { public function __construct() @@ -17,11 +16,11 @@ class Interceptor implements InjectRouteInterface /** - * @param ReflectionClass $class + * @param string $class * @param string $method * @return void */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { // TODO: Implement dispatch() method. } diff --git a/src/Annotate/Middleware.php b/src/Annotate/Middleware.php index 91c7083..9ef720a 100644 --- a/src/Annotate/Middleware.php +++ b/src/Annotate/Middleware.php @@ -3,12 +3,11 @@ declare(strict_types=1); namespace Kiri\Router\Annotate; +use Kiri\Di\Interface\InjectMethodInterface; use Kiri\Router\Base\Middleware as MiddlewareManager; -use Kiri\Router\Interface\InjectRouteInterface; -use ReflectionClass; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -class Middleware implements InjectRouteInterface +class Middleware implements InjectMethodInterface { /** @@ -20,15 +19,15 @@ class Middleware implements InjectRouteInterface /** - * @param ReflectionClass $class + * @param string $class * @param string $method * @return void */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { $middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class); - $middlewareManager->set($class->getName(), $method, $this->middleware); + $middlewareManager->set($class, $method, $this->middleware); } diff --git a/src/Annotate/Options.php b/src/Annotate/Options.php index efb1e58..76cfd5a 100644 --- a/src/Annotate/Options.php +++ b/src/Annotate/Options.php @@ -5,12 +5,11 @@ namespace Kiri\Router\Annotate; use Kiri; use Kiri\Router\Constrict\RequestMethod; -use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\Router; -use ReflectionClass; +use Kiri\Di\Interface\InjectMethodInterface; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -class Options extends AbstractRequestMethod implements InjectRouteInterface +class Options extends AbstractRequestMethod implements InjectMethodInterface { @@ -29,9 +28,9 @@ class Options extends AbstractRequestMethod implements InjectRouteInterface * @return void * @throws */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { - $controller = Kiri::getDi()->makeReflection($class); + $controller = Kiri::getDi()->get($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); diff --git a/src/Annotate/Post.php b/src/Annotate/Post.php index 25b0abc..1126b29 100644 --- a/src/Annotate/Post.php +++ b/src/Annotate/Post.php @@ -5,13 +5,11 @@ namespace Kiri\Router\Annotate; use Kiri; use Kiri\Router\Constrict\RequestMethod; -use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\Router; -use ReflectionClass; -use ReflectionException; +use Kiri\Di\Interface\InjectMethodInterface; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -class Post extends AbstractRequestMethod implements InjectRouteInterface +class Post extends AbstractRequestMethod implements InjectMethodInterface { @@ -25,15 +23,14 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface /** - * @param ReflectionClass $class + * @param string $class * @param string $method * @return void - * @throws ReflectionException */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { // TODO: Implement dispatch() method. - $controller = Kiri::getDi()->makeReflection($class); + $controller = Kiri::getDi()->get($class); $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { diff --git a/src/Annotate/Put.php b/src/Annotate/Put.php index db0581a..eebdf96 100644 --- a/src/Annotate/Put.php +++ b/src/Annotate/Put.php @@ -5,12 +5,14 @@ namespace Kiri\Router\Annotate; use Kiri; use Kiri\Router\Constrict\RequestMethod; -use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\Router; -use ReflectionClass; +use Kiri\Di\Interface\InjectMethodInterface; +/** + * + */ #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -class Put extends AbstractRequestMethod implements InjectRouteInterface +class Put extends AbstractRequestMethod implements InjectMethodInterface { @@ -24,14 +26,13 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface /** - * @param object $class + * @param string $class * @param string $method * @return void - * @throws */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { - $controller = Kiri::getDi()->makeReflection($class); + $controller = Kiri::getDi()->get($class); // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { diff --git a/src/Annotate/Route.php b/src/Annotate/Route.php index 485de4b..936229b 100644 --- a/src/Annotate/Route.php +++ b/src/Annotate/Route.php @@ -3,13 +3,11 @@ namespace Kiri\Router\Annotate; use Kiri\Router\Constrict\RequestMethod; -use Kiri\Router\Interface\InjectRouteInterface; use Kiri\Router\Router; -use ReflectionClass; -use ReflectionException; +use Kiri\Di\Interface\InjectMethodInterface; #[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] -class Route extends AbstractRequestMethod implements InjectRouteInterface +class Route extends AbstractRequestMethod implements InjectMethodInterface { @@ -24,15 +22,13 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface /** - * @param ReflectionClass $class + * @param string $class * @param string $method * @return void - * @throws ReflectionException */ - public function dispatch(ReflectionClass $class, string $method): void + public function dispatch(string $class, string $method): void { - $controller = \Kiri::getDi()->makeReflection($class); - // TODO: Implement dispatch() method. + $controller = \Kiri::getDi()->get($class); $path = '/' . ltrim($this->path, '/'); if (!empty($this->version)) { $path = '/' . trim($this->version) . $path; diff --git a/src/Aspect/Aspect.php b/src/Aspect/Aspect.php index bc215b1..a168848 100644 --- a/src/Aspect/Aspect.php +++ b/src/Aspect/Aspect.php @@ -3,65 +3,29 @@ namespace Kiri\Router\Aspect; -use Kiri\Di\Interface\InjectProxyInterface; +use Kiri\Di\Interface\InjectMethodInterface; use PhpParser\ParserFactory; -#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)] -class Aspect implements InjectProxyInterface +#[\Attribute(\Attribute::TARGET_METHOD)] +class Aspect implements InjectMethodInterface { - /** - * @param array|string $aspect - */ - public function __construct(readonly public array|string $aspect = []) - { - } + /** + * @param array|string $aspect + */ + public function __construct(readonly public array|string $aspect = []) + { + } - /** - * @param string $fileName - * @param object $class - * @param string $method - * @return void - */ - public function dispatch(string $fileName, object $class, string $method): void - { - // TODO: Implement dispatch() method. - try { - $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); - $ast = $parser->parse(file_get_contents($fileName)); - - $cacheFile = storage('proxy_functions.php'); - if (!file_exists($cacheFile)) { - file_put_contents($cacheFile, 'generateClourse($functionName) . PHP_EOL; - - file_put_contents($cacheFile, $code, FILE_APPEND); - } catch (\Throwable $throwable) { - die(throwable($throwable)); - } - } - - - private function generateClourse($functionName): string - { - return <<