e35b3f5f43bf5f2b9d59141e8cbcb70835cf2011
14 * @var \mdref\Reference
34 * Initialize the reference
36 public function __construct(Reference
$ref, Request
$req, Response
$res, BaseUrl
$baseUrl) {
37 $this->reference
= $ref;
38 $this->request
= $req;
39 $this->response
= $res;
40 $this->baseUrl
= $baseUrl;
44 return htmlspecialchars($txt);
48 * Create the view payload
49 * @param \http\Controller $ctl
52 private function createPayload() {
55 $pld->esc
= "htmlspecialchars";
56 $pld->quick
= [$this->reference
, "formatString"];
57 $pld->file
= [$this->reference
, "formatFile"];
59 $pld->ref
= $this->baseUrl
->pathinfo(
60 $this->baseUrl
->mod($this->request
->getRequestUrl()));
62 $pld->refs
= $this->reference
;
63 $pld->baseUrl
= $this->baseUrl
;
69 * Redirect to canononical url
72 private function serveCanonical($cnn) {
73 $this->response
->setHeader("Location", $this->baseUrl
->mod(["path" => $cnn]));
74 $this->response
->setResponseCode(301);
80 private function serveStylesheet() {
81 $this->response
->setHeader("Content-Type", "text/css");
82 $this->esponse
->setBody(new \http\Message\
Body(fopen(ROOT
."/public/index.css", "r")));
88 private function serveJavascript() {
89 $this->response
->setHeader("Content-Type", "application/javascript");
90 $this->response
->setBody(new \http\Message\
Body(fopen(ROOT
."/public/index.js", "r")));
95 * @param \stdClass $pld
98 private function servePreset($pld) {
103 $pld->text
= file_get_contents(ROOT
."/$pld->ref");
106 $this->serveStylesheet($ctl);
109 $this->serveJavascript($ctl);
112 throw new Exception(404, "$pld->ref not found");
116 private function serve() {
117 extract((array) func_get_arg(0));
118 include ROOT
."/views/layout.phtml";
121 public function handle() {
124 $pld = $this->createPayload();
126 if (strlen($pld->ref
)) {
128 if (($repo = $this->reference
->getRepoForEntry($pld->ref
, $cnn))) {
131 return $this->serveCanonical($cnn);
134 $pld->entry
= $repo->getEntry($pld->ref
);
137 return $this->servePreset($pld);
141 } catch (\Exception
$e) {
142 $pld->exception
= $e;