/** * @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 testBuildWithEmptyFormat() { Config::set('hyperframework.web.view.format', ''); $this->assertSame('index.html', ViewPathBuilder::build('index')); }
/** * @return mixed */ public function getView() { if ($this->view !== null) { return $this->view; } $router = $this->getRouter(); $module = (string) $router->getModule(); if ($module !== '') { $name = $module . '/'; } else { $name = ''; } $controller = (string) $router->getController(); if ($controller !== '') { $name .= $controller . '/'; } $action = (string) $router->getAction(); if ($action === '') { throw new UnexpectedValueException('Action cannot be empty.'); } $name .= $action; return ViewPathBuilder::build($name, $this->getOutputFormat()); }