diff options
| author | winter Sparkles | 2026-08-06 23:47:34 +0100 |
|---|---|---|
| committer | winter Sparkles | 2026-08-06 23:47:34 +0100 |
| commit | ef14ba500ff27dd2d1fe6e5debd99f7a5fc4db10 (patch) | |
| tree | 1dd707be810472b13fe8ac60f204f74dfbecf9c6 /App/XMLResponse.php | |
initial commit
Diffstat (limited to 'App/XMLResponse.php')
| -rw-r--r-- | App/XMLResponse.php | 44 |
1 files changed, 44 insertions, 0 deletions
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 @@ +<?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); + } +} |
