Пример #1
0
 /**
  * Calls an HTTP error, sends it as a header, and loads a template if required to do so.
  *
  * @param int  $errno HTTP error code
  * @param bool $view  true to view error on website
  */
 public static function http_error($errno = 500, $view = true)
 {
     $http_codes = array(400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I\'m a teapot', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates', 509 => 'Bandwidth Limit Exceeded', 510 => 'Not Extended', 511 => 'Network Authentication Required');
     self::logError('HTTP-error ' . $errno . ' called');
     self::log('Sending header HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
     header('HTTP/1.1 ' . $errno . ' ' . $http_codes[$errno]);
     // Do we want the error-view with it?
     if ($view == false) {
         return;
     }
     // Load the view
     $view = 'errors/' . $errno;
     self::log('Loading view ' . $view);
     // Try and load the view, if impossible, load HTTP code instead.
     try {
         Layout::reset();
         Layout::view($view);
     } catch (LayoutException $exception) {
         // No error page could be found, just echo the result
         Factory::getInstance()->output->set_output("<h1>{$errno}</h1><h3>" . $http_codes[$errno] . '</h3>');
     }
 }