aboutsummaryrefslogtreecommitdiff
path: root/App
diff options
context:
space:
mode:
Diffstat (limited to 'App')
-rw-r--r--App/Router.php48
-rw-r--r--App/XMLResponse.php44
2 files changed, 0 insertions, 92 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);
- }
- }
-}
diff --git a/App/XMLResponse.php b/App/XMLResponse.php
deleted file mode 100644
index bdbf44b..0000000
--- a/App/XMLResponse.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-namespace App;
-
-class XMLResponse {
- public \SimpleXMLElement $doc;
- private static array $stylesheets;
- private static array $runFirst;
-
- static function addStylesheet(string $path) {
- $sheet = \Dom\XMLDocument::createFromFile($path);
- self::$stylesheets[] = $sheet;
- }
-
- static function addPreamble(callable $preamble) {
- self::$runFirst[] = $preamble;
- }
-
- function __construct(string $rootElement = 'page') {
- $this->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);
- }
-}