summaryrefslogtreecommitdiff
path: root/src/Router.php
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2025-08-14 14:37:56 +0200
committerDaniel Weipert <git@mail.dweipert.de>2025-08-14 14:37:56 +0200
commitc135fcf9041c604b32827a1cb027010bca5915ab (patch)
tree95a2331d5f0bc4a736aa0e716330c39b3fa1ea26 /src/Router.php
parent3f4b51b99a4f4dc41dbdce7f34afe7e15d3d426e (diff)
POST login possible
Diffstat (limited to 'src/Router.php')
-rw-r--r--src/Router.php70
1 files changed, 0 insertions, 70 deletions
diff --git a/src/Router.php b/src/Router.php
deleted file mode 100644
index 437d995..0000000
--- a/src/Router.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-
-namespace App;
-
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Routing\Loader\Configurator\RouteConfigurator;
-use Symfony\Component\Routing\Matcher\UrlMatcher;
-use Symfony\Component\Routing\RequestContext;
-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.
- */
- public function run(): Response
- {
- $request = Request::createFromGlobals();
-
- if ($request->isMethod("OPTIONS")) {
- $response = new Response();
- $response->headers->add([
- "Access-Control-Allow-Origin" => "*",
- "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
- */
- private function addRoutes(): void
- {
- $routes = include_once(__DIR__ . "/routes.php");
- $routes($this->configurator);
- }
-}