ea725dcfdcc1ea81ede9933f14556d66814fb956
1 <?php
defined('IN_CMS') or die('No direct access allowed.');
5 private static $content = '';
6 private static $headers = array();
7 private static $status = 200;
9 private static $statuses = array(
11 101 => 'Switching Protocols',
15 203 => 'Non-Authoritative Information',
17 205 => 'Reset Content',
18 206 => 'Partial Content',
19 207 => 'Multi-Status',
20 300 => 'Multiple Choices',
21 301 => 'Moved Permanently',
24 304 => 'Not Modified',
26 307 => 'Temporary Redirect',
28 401 => 'Unauthorized',
29 402 => 'Payment Required',
32 405 => 'Method Not Allowed',
33 406 => 'Not Acceptable',
34 407 => 'Proxy Authentication Required',
35 408 => 'Request Timeout',
38 411 => 'Length Required',
39 412 => 'Precondition Failed',
40 413 => 'Request Entity Too Large',
41 414 => 'Request-URI Too Long',
42 415 => 'Unsupported Media Type',
43 416 => 'Requested Range Not Satisfiable',
44 417 => 'Expectation Failed',
45 422 => 'Unprocessable Entity',
47 424 => 'Failed Dependency',
48 500 => 'Internal Server Error',
49 501 => 'Not Implemented',
51 503 => 'Service Unavailable',
52 504 => 'Gateway Timeout',
53 505 => 'HTTP Version Not Supported',
54 507 => 'Insufficient Storage',
55 509 => 'Bandwidth Limit Exceeded'
58 public static function header($name, $value) {
59 static::$headers[$name] = $value;
62 public static function content($str) {
63 static::$content = $str;
66 public static function append($str) {
67 static::$content .= $str;
70 public static function error($code = 500) {
71 if(isset(static::$statuses[$code])) {
72 static::$status = $code;
77 Template
::render(404);
81 public static function send() {
83 if(array_key_exists('Content-Type', static::$headers) === false) {
84 static::$headers['Content-Type'] = 'text/html; charset=UTF-8';
88 if(headers_sent() === false) {
90 $protocol = Input
::server('server_protocol', 'HTTP/1.1');
92 header($protocol . ' ' . static::$status . ' ' . static::$statuses[static::$status]);
94 foreach(static::$headers as $name => $value) {
95 header($name . ': ' . $value, true);
99 // Send it to the browser!
100 echo static::$content;
103 public static function redirect($url) {
104 static::header('Location', Url
::make($url));
105 static::$status = 302;
106 static::$content = '';