Beispiel #1
0
 /**
  *
  * @param Message\Response $response
  */
 protected function emitHeaders(Message\Response $response)
 {
     if (!$response->getStatusCode()) {
         $response->setStatus(200, "OK");
     }
     if ($response->getStatusCode() != 200) {
         $status = $response->getStatusCode();
         $message = $response->getStatusString() ?: Message\HttpStatus::message($status);
         $proto = $response->getProto() ?: "HTTP";
         $version = $response->getVersion() ?: "1.1";
         $this->addHeader("{$proto}/{$version} {$status} {$message}");
     }
     $sent = array();
     $headers = $response->getHeaders();
     foreach ($headers as $info) {
         $name = $info['header'];
         foreach ($info['content'] as $value) {
             if ($value !== null) {
                 $this->addHeader("{$name}: {$value}", !isset($sent[$name]));
                 $sent[$name] = true;
             } else {
                 $this->removeHeader($name);
             }
         }
     }
     if (!$this->poweredByEnabled() && $headers->get('X-Powered-By') === null && !headers_sent()) {
         $this->removeHeader('X-Powered-By');
     }
 }
Beispiel #2
0
 /**
  * Creates an error model
  * @throws Exception\RuntimeException
  */
 protected function createError(Resources $context, $message, $status = 404)
 {
     $response = $context->getResponse();
     $config = $context->getConfig();
     $layout = $config->value('view.error_layout');
     if (!$layout) {
         throw new Exception\RuntimeException("[ERROR LAYOUT NOT SET] {$message}", 2);
     }
     $debug = $config->value('application.environment') == 'development';
     $error = array('status' => array('code' => $status, 'text' => Message\HttpStatus::message($status)), 'debug' => $debug);
     if ($debug) {
         $error['message'] = $message;
         $error['backtrace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
     }
     $response->setStatusCode($status);
     $model = new ViewModel();
     $model->setLayout($layout)->setTemplate(false)->setData(['errors' => [$error]]);
     return $model;
 }
Beispiel #3
0
 /**
  * @return string
  */
 public function renderError($message, array $trace = array(), $status = 200, $token = null)
 {
     if ($this->getEnvironment() == 'development') {
         $title = $message;
         $content = $this->renderDebug($message, $trace);
     } else {
         $title = $this->escape(HttpStatus::message($status));
         $content = "<h1>{$status} <span class=\"title\">{$title}</span></h1>\n";
     }
     if ($token) {
         $token = $this->escape($token);
         $content .= "\n" . "<p><span class=\"log-token\">token: {$token}</span></p>\n";
     }
     return $this->renderPage($title, $content);
 }