*/
private $response;
+ /**
+ * @var resource
+ */
+ private $output;
+
/**
* @var \http\Url
*/
/**
* Initialize the reference
*/
- public function __construct(Reference $ref, Request $req, Response $res, BaseUrl $baseUrl) {
+ public function __construct(Reference $ref, Request $req, Response $res, BaseUrl $baseUrl, $output = null) {
$this->reference = $ref;
$this->request = $req;
$this->response = $res;
$this->baseUrl = $baseUrl;
+ $this->output = $output;
ob_start($res);
}
$pld->ref = $this->baseUrl->pathinfo(
$this->baseUrl->mod($this->request->getRequestUrl()));
+ $pld->markup = function($page) use($pld) {
+ return $this->reference->getFormatter()->markup($page, $pld);
+ };
+
$pld->refs = $this->reference;
$pld->baseUrl = $this->baseUrl;
private function serveCanonical(string $cnn) : void {
$this->response->setHeader("Location", $this->baseUrl->mod(["path" => $cnn]));
$this->response->setResponseCode(301);
- $this->response->send();
+ if (is_resource($this->output)) {
+ $this->response->send($this->output);
+ } else {
+ $this->response->send();
+ }
}
/**
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();
+ if (is_resource($this->output)) {
+ $this->response->send($this->output);
+ } else {
+ $this->response->send();
+ }
}
/**
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();
+ if (is_resource($this->output)) {
+ $this->response->send($this->output);
+ } else {
+ $this->response->send();
+ }
}
/**
$this->response->setHeader("Content-Type", "application/x-php");
$this->response->setContentDisposition(["attachment" => ["filename" => "$name.stub.php"]]);
$this->response->setBody(new Body(\fopen($stub, "r")));
- $this->response->send();
+ if (is_resource($this->output)) {
+ $this->response->send($this->output);
+ } else {
+ $this->response->send();
+ }
}
/**
include ROOT."/views/layout.phtml";
$this->response->addHeader("Link", "<" . $this->baseUrl->path . "index.css>; rel=preload; as=style");
$this->response->addHeader("Link", "<" . $this->baseUrl->path . "index.js>; rel=preload; as=script");
- $this->response->send();
+ if (isset($exception) && $exception->getCode()) {
+ $this->response->setResponseCode($exception->getCode());
+ }
+ if (is_resource($this->output)) {
+ $this->response->send($this->output);
+ } else {
+ $this->response->send();
+ }
}
/**
try {
$pld = $this->createPayload();
- if (strlen($pld->ref)) {
+ if (isset($pld->ref) && strlen($pld->ref)) {
$cnn = null;
if (($repo = $this->reference->getRepoForEntry($pld->ref, $cnn))) {
- if (strlen($cnn)) {
+ if (isset($cnn) && strlen($cnn)) {
/* redirect */
$this->serveCanonical($cnn);
return;