function __construct(HttpRequest $request, $uri = '') { parent::__construct($request); if (!$uri || !preg_match('`^(/|[a-z0-9]+://)`', $uri)) { $uri = $request->baseurl . '/' . ltrim($uri, '/'); } $this->headers['Location'] = $uri; }
function render($render_stream = true) { if (!isset($this->content)) { if ($this->view) { $this->variables += array('response' => $this, 'request' => $this->request, 'app' => $this->app); if ($this->request instanceof Request\HttpRequest) { $this->variables += array('baseurl' => $this->request->baseurl, 'webroot' => $this->request->webroot, 'webhost' => $this->request->webhost); } $this->content = $this->app->hook('response.render', $this); } else { $this->content = $this->variables['body']; } } return parent::render($render_stream); }
function __construct(Request $request, $filename, $force_download = false) { if (!is_file($filename) || !is_readable($filename)) { throw new \Hydra\Exception\NotFoundHttpException("File not found: {$filename}"); } $this->isPhp = preg_match('/\\.php$/', $filename); $this->filename = $filename; if ($force_download) { $this->headers['Content-Type'] = 'application/octet-stream'; } else { // Try to guess Content-Type if (!$this->isPhp) { $this->headers['Content-Type'] = MimeTypeGuesser::getInstance()->guess($filename); } elseif ($request->app->config->response['guessPhpContentType']) { $ext = Utils::fileExt(substr($filename, 0, -4)); if (isset($request->app->mimetypes[$ext])) { $this->headers['Content-Type'] = $request->app->mimetypes[$ext]; } } } if (!$this->isPhp) { $this->headers['Content-Length'] = filesize($filename); } $response = $this; parent::__construct($request, function () use($response) { // We don't want any left-over output when sending a file. ob_end_clean(); if ($response->isPhp) { $request = $response->request; $app = $response->app; require $response->filename; } else { if ($response->app->config->response['XSendfile']) { $filename = realpath($response->filename); header("X-Sendfile: {$filename}"); } else { set_time_limit(0); //Set the execution time to infinite. readfile($response->filename); } } }); }