- private function serveInternal(\http\Controller $ctl) {
- $payload = $ctl->getPayload();
- $finder = new Finder($this->baseUrl, ROOT);
- $url = new \http\Url($ctl->getRequest()->getRequestUrl());
- $path = $finder->find($url, "");
- if ($path->isFile("")) {
- $payload->html = $path->toHtml();
- } else if (strcmp($url, $this->baseUrl)) {
- throw new \http\Controller\Exception(404, "Could not find '$path'");
+ /**
+ * Serve index.css
+ * @param \http\Controller $ctl
+ */
+ private function serveStylesheet($ctl) {
+ $ctl->detachAll(Observer\View::class);
+ $ctl->getResponse()->setHeader("Content-Type", "text/css");
+ $ctl->getResponse()->setBody(new \http\Message\Body(fopen(ROOT."/public/index.css", "r")));
+ }
+
+ /**
+ * Serve index.js
+ * @param \http\Controller $ctl
+ */
+ private function serveJavascript($ctl) {
+ $ctl->detachAll(Observer\View::class);
+ $ctl->getResponse()->setHeader("Content-Type", "application/javascript");
+ $ctl->getResponse()->setBody(new \http\Message\Body(fopen(ROOT."/public/index.js", "r")));
+ }
+
+ /**
+ * Serve a preset
+ * @param \http\Controller $ctl
+ * @param \stdClass $pld
+ * @throws \http\Controller\Exception
+ */
+ private function servePreset($ctl, $pld) {
+ switch ($pld->ref) {
+ case "AUTHORS":
+ case "LICENSE":
+ case "VERSION":
+ $pld->text = file_get_contents(ROOT."/$pld->ref");
+ break;
+ case "index.css":
+ $this->serveStylesheet($ctl);
+ break;
+ case "index.js":
+ $this->serveJavascript($ctl);
+ break;
+ default:
+ throw new \http\Controller\Exception(404, "$pld->ref not found");