From ef14ba500ff27dd2d1fe6e5debd99f7a5fc4db10 Mon Sep 17 00:00:00 2001 From: winter Sparkles Date: Thu, 6 Aug 2026 23:47:34 +0100 Subject: initial commit --- App/Router.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ App/XMLResponse.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 App/Router.php create mode 100644 App/XMLResponse.php (limited to 'App') diff --git a/App/Router.php b/App/Router.php new file mode 100644 index 0000000..42fd3e1 --- /dev/null +++ b/App/Router.php @@ -0,0 +1,48 @@ +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 '

' . $status . ' for ' . htmlspecialchars($path) . '

'; + } + } + + 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); + } + } +} diff --git a/App/XMLResponse.php b/App/XMLResponse.php new file mode 100644 index 0000000..bdbf44b --- /dev/null +++ b/App/XMLResponse.php @@ -0,0 +1,44 @@ +doc = new \SimpleXMLElement("<$rootElement/>"); + foreach (self::$runFirst as $fn) { + $fn($this->doc); + } + } + + function sendRaw() { + header('Content-Type: application/xml'); + echo $this->doc->asXML(); + } + + function send() { + if (isset($_GET['RawXML'])) { + $this->sendRaw(); + return; + } + + //header('Content-Type: application/xhtml+xml'); + $processor = new \XSLTProcessor; + foreach (self::$stylesheets as $sheet) { + $processor->importStylesheet($sheet); + } + $root = \Dom\import_simplexml($this->doc); + echo $processor->transformToXml($root); + } +} -- cgit v1.3