This commit is contained in:
2023-08-25 11:11:16 +08:00
parent 6c90006150
commit e064971a42
5 changed files with 8 additions and 44 deletions
+1 -5
View File
@@ -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);
}
}
+1 -5
View File
@@ -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);
}
}
}
+1 -5
View File
@@ -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);
}
}
+1 -5
View File
@@ -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);
}
}
}
+4 -24
View File
@@ -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);
}
}