This commit is contained in:
xl
2023-07-06 16:02:59 +08:00
parent f99491b40d
commit 255751e112
+28 -8
View File
@@ -58,23 +58,33 @@ class Router
/**
* @param string $route
* @param string $handler
* @throws
* @param bool $enableOption
* @throws ReflectionException
*/
public static function post(string $route, string $handler): void
public static function post(string $route, string $handler, bool $enableOption = true): 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
* @throws
* @param bool $enableOption
* @throws ReflectionException
*/
public static function get(string $route, string $handler): void
public static function get(string $route, string $handler, bool $enableOption = true): 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);
}
}
@@ -104,12 +114,17 @@ class Router
/**
* @param string $route
* @param string $handler
* @throws
* @param bool $enableOption
* @throws ReflectionException
*/
public static function delete(string $route, string $handler): void
public static function delete(string $route, string $handler, bool $enableOption = true): 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);
}
}
@@ -128,12 +143,17 @@ class Router
/**
* @param string $route
* @param string $handler
* @throws
* @param bool $enableOption
* @throws ReflectionException
*/
public static function put(string $route, string $handler): void
public static function put(string $route, string $handler, bool $enableOption = true): 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);
}
}