Пример #1
0
 /**
  * @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);
     }
 }
 /**
  * @expectedException Hyperframework\Common\ClassNotFoundException
  */
 public function testCreateViewByInvalidConfig()
 {
     Config::set('hyperframework.web.view.class', 'Unknown');
     ViewFactory::createView();
 }
Пример #3
0
 /**
  * @return void
  */
 public function renderView()
 {
     $view = $this->getView();
     if (is_object($view)) {
         $view->render($this->getActionResult());
         return;
     } elseif (is_string($view) === false) {
         throw new UnexpectedValueException("View must be a string or an object, " . gettype($view) . " given.");
     }
     $path = $view;
     if ($path === '') {
         throw new UnexpectedValueException('View path cannot be empty.');
     }
     $viewModel = $this->getActionResult();
     if ($viewModel !== null && is_array($viewModel) === false) {
         throw new UnexpectedValueException('View model must be an array, ' . gettype($viewModel) . ' given.');
     }
     $view = ViewFactory::createView($viewModel);
     $view->render($path);
 }