From e064971a427a954f639d98eb14a409b561c68ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 25 Aug 2023 11:11:16 +0800 Subject: [PATCH] qqq --- src/Annotate/Delete.php | 6 +----- src/Annotate/Get.php | 6 +----- src/Annotate/Post.php | 6 +----- src/Annotate/Put.php | 6 +----- src/Router.php | 28 ++++------------------------ 5 files changed, 8 insertions(+), 44 deletions(-) diff --git a/src/Annotate/Delete.php b/src/Annotate/Delete.php index 4fbf33f..e4397a2 100644 --- a/src/Annotate/Delete.php +++ b/src/Annotate/Delete.php @@ -20,7 +20,7 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface * @param string $version * @param bool $enableOption */ - public function __construct(readonly public string $path, readonly public string $version = 'v1', readonly public bool $enableOption = true) + public function __construct(readonly public string $path, readonly public string $version = 'v1') { } @@ -38,10 +38,6 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface $path = '/' . ltrim($this->path, '/'); Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$class, $method]); - if ($this->enableOption) { - $options = [di(OptionsController::class), 'index']; - Router::addRoute([RequestMethod::REQUEST_OPTIONS], $path, $options); - } } diff --git a/src/Annotate/Get.php b/src/Annotate/Get.php index a2243a6..f75712b 100644 --- a/src/Annotate/Get.php +++ b/src/Annotate/Get.php @@ -20,7 +20,7 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface * @param string $version * @param bool $enableOption */ - public function __construct(readonly public string $path, readonly public string $version = 'v1', readonly public bool $enableOption = true) + public function __construct(readonly public string $path, readonly public string $version = 'v1') { } @@ -38,10 +38,6 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface $path = '/' . ltrim($this->path, '/'); Router::addRoute(RequestMethod::REQUEST_GET, $path, [$class, $method]); - if ($this->enableOption) { - $options = [di(OptionsController::class), 'index']; - Router::addRoute([RequestMethod::REQUEST_OPTIONS], $path, $options); - } } } diff --git a/src/Annotate/Post.php b/src/Annotate/Post.php index 82d89d9..fcc6c2e 100644 --- a/src/Annotate/Post.php +++ b/src/Annotate/Post.php @@ -20,7 +20,7 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface * @param string $version * @param bool $enableOption */ - public function __construct(readonly public string $path, readonly public string $version = 'v1', readonly public bool $enableOption = true) + public function __construct(readonly public string $path, readonly public string $version = 'v1') { } @@ -38,10 +38,6 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface $path = '/' . ltrim($this->path, '/'); Router::addRoute(RequestMethod::REQUEST_POST, $path, [$class, $method]); - if ($this->enableOption) { - $options = [di(OptionsController::class), 'index']; - Router::addRoute([RequestMethod::REQUEST_OPTIONS], $path, $options); - } } diff --git a/src/Annotate/Put.php b/src/Annotate/Put.php index bd9b0b6..46ffbe3 100644 --- a/src/Annotate/Put.php +++ b/src/Annotate/Put.php @@ -20,7 +20,7 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface * @param string $version * @param bool $enableOption */ - public function __construct(readonly public string $path, readonly public string $version = 'v1', readonly public bool $enableOption = true) + public function __construct(readonly public string $path, readonly public string $version = 'v1') { } @@ -38,10 +38,6 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface $path = '/' . ltrim($this->path, '/'); Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$class, $method]); - if ($this->enableOption) { - $options = [di(OptionsController::class), 'index']; - Router::addRoute([RequestMethod::REQUEST_OPTIONS], $path, $options); - } } } diff --git a/src/Router.php b/src/Router.php index be98e1a..733dec9 100644 --- a/src/Router.php +++ b/src/Router.php @@ -57,33 +57,23 @@ class Router /** * @param string $route * @param string $handler - * @param bool $enableOption * @throws ReflectionException */ - public static function post(string $route, string $handler, bool $enableOption = true): void + public static function post(string $route, string $handler): void { $router = Kiri::getDi()->get(DataGrip::class)->get(static::$type); $router->addRoute([RequestMethod::REQUEST_POST], $route, $handler); - if ($enableOption) { - $options = [di(OptionsController::class), 'index']; - $router->addRoute([RequestMethod::REQUEST_OPTIONS], $route, $options); - } } /** * @param string $route * @param string $handler - * @param bool $enableOption * @throws ReflectionException */ - public static function get(string $route, string $handler, bool $enableOption = true): void + public static function get(string $route, string $handler): void { $router = Kiri::getDi()->get(DataGrip::class)->get(static::$type); $router->addRoute([RequestMethod::REQUEST_GET], $route, $handler); - if ($enableOption) { - $options = [di(OptionsController::class), 'index']; - $router->addRoute([RequestMethod::REQUEST_OPTIONS], $route, $options); - } } @@ -113,17 +103,12 @@ class Router /** * @param string $route * @param string $handler - * @param bool $enableOption * @throws ReflectionException */ - public static function delete(string $route, string $handler, bool $enableOption = true): void + public static function delete(string $route, string $handler): void { $router = Kiri::getDi()->get(DataGrip::class)->get(static::$type); $router->addRoute([RequestMethod::REQUEST_DELETE], $route, $handler); - if ($enableOption) { - $options = [di(OptionsController::class), 'index']; - $router->addRoute([RequestMethod::REQUEST_OPTIONS], $route, $options); - } } @@ -142,17 +127,12 @@ class Router /** * @param string $route * @param string $handler - * @param bool $enableOption * @throws ReflectionException */ - public static function put(string $route, string $handler, bool $enableOption = true): void + public static function put(string $route, string $handler): void { $router = Kiri::getDi()->get(DataGrip::class)->get(static::$type); $router->addRoute([RequestMethod::REQUEST_PUT], $route, $handler); - if ($enableOption) { - $options = [di(OptionsController::class), 'index']; - $router->addRoute([RequestMethod::REQUEST_OPTIONS], $route, $options); - } }