-
- private function getType($file) {
- static $inf = null;
- static $typ = array(".css" => "text/css", ".js" => "applicatin/javascript");
-
- $ext = strrchr($file, ".");
- if (isset($typ[$ext])) {
- return $typ[$ext];
- }
-
- if (!$inf) {
- $inf = new \FINFO(FILEINFO_MIME_TYPE);
+
+ /**
+ * Create the view payload
+ * @return \stdClass
+ */
+ private function createPayload() : object {
+ $pld = new stdClass;
+
+ $pld->esc = "htmlspecialchars";
+ $pld->anchor = [$this->reference, "formatAnchor"];
+ $pld->quick = [$this->reference, "formatString"];
+ $pld->file = [$this->reference, "formatFile"];
+
+ $pld->ref = $this->baseUrl->pathinfo(
+ $this->baseUrl->mod($this->request->getRequestUrl()));
+
+ $pld->refs = $this->reference;
+ $pld->baseUrl = $this->baseUrl;
+
+ return $pld;
+ }
+
+ /**
+ * Redirect to canonical url
+ * @param string $cnn
+ */
+ private function serveCanonical(string $cnn) : void {
+ $this->response->setHeader("Location", $this->baseUrl->mod(["path" => $cnn]));
+ $this->response->setResponseCode(301);
+ $this->response->send();
+ }
+
+ /**
+ * Serve index.css
+ */
+ private function serveStylesheet() : void {
+ $this->response->setHeader("Content-Type", "text/css");
+ $this->response->setBody(new Body(\fopen(ROOT."/public/index.css", "r")));
+ $this->response->send();
+ }
+
+ /**
+ * Serve index.js
+ */
+ private function serveJavascript() : void {
+ $this->response->setHeader("Content-Type", "application/javascript");
+ $this->response->setBody(new Body(\fopen(ROOT."/public/index.js", "r")));
+ $this->response->send();
+ }
+
+ /**
+ * Server a PHP stub
+ * @throws Exception
+ *
+ */
+ private function serveStub() : void {
+ $name = $this->request->getQuery("ref", "s");
+ $repo = $this->reference->getRepoForEntry($name);
+ if (!$repo->hasStub($stub)) {
+ throw new Exception(404, "Stub not found");