* @var \http\Url
*/
private $baseUrl;
-
+
/**
* Initialize the reference
*/
function esc($txt) {
return htmlspecialchars($txt);
}
-
+
/**
* Create the view payload
* @param \http\Controller $ctl
*/
private function createPayload() {
$pld = new \stdClass;
-
+
$pld->esc = "htmlspecialchars";
+ $pld->anchor = [$this->reference, "formatAnchor"];
$pld->quick = [$this->reference, "formatString"];
$pld->file = [$this->reference, "formatFile"];
$pld->refs = $this->reference;
$pld->baseUrl = $this->baseUrl;
-
+
return $pld;
}
-
+
/**
* Redirect to canononical url
* @param string $cnn
$this->response->setResponseCode(301);
$this->response->send();
}
-
+
/**
* Serve index.css
*/
$this->response->setBody(new \http\Message\Body(fopen(ROOT."/public/index.css", "r")));
$this->response->send();
}
-
+
/**
* Serve index.js
*/
$this->response->setBody(new \http\Message\Body(fopen(ROOT."/public/index.js", "r")));
$this->response->send();
}
-
+
/**
* Serve a preset
* @param \stdClass $pld
+ * @return true to continue serving the payload
* @throws Exception
*/
private function servePreset($pld) {
case "LICENSE":
case "VERSION":
$pld->text = file_get_contents(ROOT."/$pld->ref");
- break;
+ return true;
case "index.css":
- $this->serveStylesheet($ctl);
+ $this->serveStylesheet();
break;
case "index.js":
- $this->serveJavascript($ctl);
+ $this->serveJavascript();
break;
default:
throw new Exception(404, "$pld->ref not found");
}
+ return false;
}
private function serve() {
include ROOT."/views/layout.phtml";
$this->response->send();
}
-
+
public function handle() {
try {
/* direct match */
$pld->entry = $repo->getEntry($pld->ref);
}
- } else {
- return $this->servePreset($pld);
+ } elseif (!$this->servePreset($pld)) {
+ return;
}
}
-
+
} catch (\Exception $e) {
$pld->exception = $e;
}
$this->serve($pld);
}
-}
\ No newline at end of file
+}