public function doTransform(Interfaces\Response $response) { $meta = $response->getMeta(); $response->setContent($this->getConfig()->get('TemplateManager.current')->render($meta['template'], $response)); //return the altered response return $response; }
public function doTransform(Interfaces\Response $response) { $source = $this->config->get('FileLayer.source'); $file = $source . $response->getUrl(); //what file names may be indexes is declared in FileLayer.indexes if (is_dir($file)) { $file = $this->locateIndex($file); } //strip index filenames from URL, so that Response contains canonical URL $url = $response->getUrl(); foreach ($this->config->get('FileLayer.indexes') as $index) { $url = preg_replace('/\\/' . preg_quote($index) . '$/i', '', $url); } $response->setUrl($url); //404 on nonexistent indexes or otherwise non-found files if (!$file) { return $this->error($response, 404); } //Check for dangerous paths //Currently limited to checking that requested file is inside FileLayer.source $file = realpath($file); if (!file_exists($file) || !(strpos($file, $this->config->get('FileLayer.source')) === 0)) { return $this->error($response, 404); } //return the altered response $response->setFile($file); return $response; }
public function transformError(Interfaces\Response $response, $status = 500, $message = false) { $response->setStatus($status); $response->setMeta(array('title' => "Error {$status}", 'skipTemplate' => false)); $response->setContent("<h1>Error {$status}</h1><p>Unable to fulfill request for <em>" . $response->getUrl() . "</em></p>"); return $response; }