/** * @param int $statusCode * @param string $statusReasonPhrase * @param object $error * @param string $outputFormat * @return void */ public function render($statusCode, $statusReasonPhrase, $error, $outputFormat = null) { $rootPath = Config::getString('hyperframework.web.error_view.root_path', ''); if ($rootPath === '') { $rootPath = Config::getString('hyperframework.web.view.root_path', ''); if ($rootPath === '') { $rootPath = 'views' . DIRECTORY_SEPARATOR . '_error'; } else { $rootPath = FilePathCombiner::combine($rootPath, '_error'); } } $files = [ViewPathBuilder::build($statusCode, $outputFormat), ViewPathBuilder::build('default', $outputFormat)]; $rootPath = FileFullPathBuilder::build($rootPath); $path = null; foreach ($files as $file) { $file = FilePathCombiner::combine($rootPath, $file); if (file_exists($file)) { $path = $file; break; } } if ($path === null) { Response::setHeader('Content-Type: text/plain; charset=utf-8'); echo $statusCode; if ((string) $statusReasonPhrase !== '') { echo ' ', $statusReasonPhrase; } } else { $view = ViewFactory::createView(['status_code' => $statusCode, 'status_reason_pharse' => $statusReasonPhrase, 'error' => $error]); $view->render($path); } }
public function renderView() { if ($this->isViewEnabled() === false) { return; } Response::setHeader('Content-Type: application/json'); $json = json_encode($this->getActionResult(), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); if ($json === false) { throw new UnexpectedValueException('The action result is invalid.'); } echo $json; }
public function testSetHeader() { $this->mockEngineMethod('setHeader')->with('Name: value'); Response::setHeader('Name: value'); }
/** * @return void */ private function rewriteHttpHeaders() { Response::removeHeaders(); $error = $this->getError(); if ($error instanceof HttpException) { foreach ($error->getHttpHeaders() as $header) { Response::setHeader($header); } } else { Response::setHeader('HTTP/1.1 500 Internal Server Error'); } }
/** * @param string $url * @param int $statusCode * @return void */ public function redirect($url, $statusCode = 302) { Response::setHeader('Location: ' . $url, true, $statusCode); $this->quit(); }
/** * @param string $url * @param int $statusCode * @return void */ protected function redirect($url, $statusCode = 302) { Response::setHeader('Location: ' . $url, true, $statusCode); $this->getApp()->quit(); }