diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2025-08-13 10:45:10 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2025-08-13 10:46:40 +0200 |
commit | beb68ad3ddc48f9e913815e0e18f11965201f32e (patch) | |
tree | c8f3cdabedb6f2635bd0f5378bc5e426ba8c5f65 /src/Router.php | |
parent | 6b7e857f21bef9ba71ac36c202678ec0d84eeff5 (diff) |
whitespace :]
Diffstat (limited to 'src/Router.php')
-rw-r--r-- | src/Router.php | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Router.php b/src/Router.php index e0b09ad..437d995 100644 --- a/src/Router.php +++ b/src/Router.php @@ -12,18 +12,18 @@ use Symfony\Component\Routing\RouteCollection; class Router { use Singleton; - + private RouteCollection $routes; private RouteConfigurator $configurator; - + public function __construct() { $this->routes = new RouteCollection(); $this->configurator = new RouteConfigurator($this->routes, $this->routes); - + $this->addRoutes(); } - + /** * match the current url against the routes. * also add preflight CORS headers on OPTIONS requests. @@ -31,7 +31,7 @@ class Router public function run(): Response { $request = Request::createFromGlobals(); - + if ($request->isMethod("OPTIONS")) { $response = new Response(); $response->headers->add([ @@ -39,26 +39,26 @@ class Router "Access-Control-Allow-Methods" => "GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD", "Access-Control-Allow-Headers" => "X-Requested-With, Content-Type, Authorization", ]); - + return $response; } - + $context = new RequestContext(); $context->fromRequest($request); - + try { $matcher = new UrlMatcher($this->routes, $context); $match = $matcher->matchRequest($request); - + $class = $match["_controller"][0]; $method = $match["_controller"][1]; - + return (new $class)->$method(); } catch (\Exception $exception) { return new ErrorResponse(ErrorCode::UNKNOWN, "Unknown error occured"); } } - + /** * add routes from the routes file */ |