aboutsummaryrefslogtreecommitdiff
path: root/App/Router.php
diff options
context:
space:
mode:
authorwinter Sparkles2026-08-08 23:01:51 +0100
committerwinter Sparkles2026-08-08 23:01:51 +0100
commitb422b6ded608807c7d3bb8b965b3797ca513610b (patch)
tree7925fa972efbfff2a9bf8648334d49e3fd6b5df1 /App/Router.php
parent880a274e1ecbed42c76d3dc4a81161b3ae372726 (diff)
implement a large chunk of the auth system itself :D
Diffstat (limited to 'App/Router.php')
-rw-r--r--App/Router.php48
1 files changed, 0 insertions, 48 deletions
diff --git a/App/Router.php b/App/Router.php
deleted file mode 100644
index 42fd3e1..0000000
--- a/App/Router.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-namespace App;
-
-class Router {
- private array $config;
- private string $routesDir;
- private array $statusHandlers = [];
-
- function __construct(string $routesDir, array $config) {
- $this->routesDir = $routesDir;
- $this->config = $config;
- }
-
- function registerStatusHandler(int $status, callable $handler) {
- $this->statusHandlers[$status] = $handler;
- }
-
- private function dealWithError(int $status, string $path) {
- http_response_code($status);
- if (isset($this->statusHandlers[$status])) {
- $this->statusHandlers[$status]($path);
- } else {
- echo '<p>' . $status . ' for ' . htmlspecialchars($path) . '</p>';
- }
- }
-
- function dispatch(string $path) {
- if (str_contains($path, '..')) {
- $this->dealWithError(404, $path);
- return;
- }
-
- if (file_exists($this->routesDir . $path . '.php')) {
- require_once $this->routesDir . $path . '.php';
- } elseif (file_exists($this->routesDir . $path . 'index.php')) {
- require_once $this->routesDir . $path . 'index.php';
- } else {
- $this->dealWithError(404, $path);
- return;
- }
-
- if (function_exists($_SERVER['REQUEST_METHOD'])) {
- $_SERVER['REQUEST_METHOD']($this->config);
- } else {
- $this->dealWithError(405, $path);
- }
- }
-}