-use http\Controller\Observer;
-
-class Action extends Observer
-{
- private function serveReference(\http\Controller $ctl) {
- $payload = $ctl->getPayload();
- $finder = new Finder($this->baseUrl, REFS);
- $path = $finder->find(new \http\Url($ctl->getRequest()->getRequestUrl()));
- $payload->listing = new RefListing($path,
- $finder->glob($path, "/[_a-zA-Z]*.md"));
- $payload->title = $payload->listing->getSelf()->formatLink();
- $payload->refs = $finder;
- if ($path->isFile()) {
- $payload->html = new Markdown($path);
- $payload->sublisting = new RefListing($path,
- $finder->glob($path, "/[_a-z]*.md"));
- return true;
- }
+use http\Env\Request;
+use http\Env\Response;
+
+/**
+ * Request handler
+ */
+class Action {
+ /**
+ * The reference
+ * @var \mdref\Reference
+ */
+ private $reference;
+
+ /**
+ * @var \http\Request
+ */
+ private $request;
+
+ /**
+ * @var \http\Response
+ */
+ private $response;
+
+ /**
+ * @var \http\Url
+ */
+ private $baseUrl;
+
+ /**
+ * Initialize the reference
+ */
+ public function __construct(Reference $ref, Request $req, Response $res, BaseUrl $baseUrl) {
+ $this->reference = $ref;
+ $this->request = $req;
+ $this->response = $res;
+ $this->baseUrl = $baseUrl;
+ ob_start($res);
+ }
+
+ function esc($txt) {
+ return htmlspecialchars($txt);
+ }
+
+ /**
+ * Create the view payload
+ * @param \http\Controller $ctl
+ * @return \stdClass
+ */
+ private function createPayload() {
+ $pld = new \stdClass;
+
+ $pld->esc = "htmlspecialchars";
+ $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 canononical url
+ * @param string $cnn
+ */
+ private function serveCanonical($cnn) {
+ $this->response->setHeader("Location", $this->baseUrl->mod(["path" => $cnn]));
+ $this->response->setResponseCode(301);
+ $this->response->send();