Skip to content

Commit

Permalink
Fix(Route): private static function validateRequestType(array ): void {
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleon4 committed May 14, 2022
1 parent 69b3adf commit 95d81df
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/LionRoute/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Route {

private static RouteCollector $router;
private static array $addMiddleware = [];
private static array $route_methods = ['GET', 'POST', 'PUT', 'DELETE', 'ANY', 'OPTIONS', 'HEAD', 'PATCH'];

public static function init(): Route {
self::$router = new RouteCollector(new RouteParser());
Expand Down Expand Up @@ -117,7 +118,15 @@ public static function delete(string $url, \Closure|array $controller_function,
}

public static function any(string $url, \Closure|array $controller_function, array $filters = []): void {
self::executeMethod('any', $url, $controller_function, $filters);
if (count($filters) > 0) {
self::$router->any(
$url,
$controller_function,
isset($filters[1]) ? ['before' => $filters[0], 'after' => $filters[1]] : ['before' => $filters[0]]
);
} else {
self::$router->any($url, $controller_function);
}
}

private static function processInput(int $index): string {
Expand All @@ -136,14 +145,17 @@ public static function dispatch(int $index): void {
self::processInput($index)
)
);
exit();
} catch (HttpRouteNotFoundException $e) {
self::processOutput(
['status' => "error", 'message' => "Path not found: {$e->getMessage()}"]
);
exit();
} catch (HttpMethodNotAllowedException $e) {
self::processOutput(
['status' => "error", 'message' => "Method not allowed: {$e->getMessage()}"]
['status' => "error", 'message' => "Method not allowed, {$e->getMessage()}"]
);
exit();
}
}

Expand Down

0 comments on commit 95d81df

Please sign in to comment.