comparison http-response-status-codes.inc @ 43:f42dbf44b661

Beautify file.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Fri, 05 Oct 2012 03:16:23 +0200
parents 9dab5b96b789
children c6d0892f81ff
comparison
equal deleted inserted replaced
42:9bdf3f8b487a 43:f42dbf44b661
1 <?php 1 <?php
2 /**
3 * StatusCodes provides named constants for
4 * HTTP protocol status codes. Written for the
5 * Recess Framework (http://www.recessframework.com/)
6 *
7 * @author Kris Jordan
8 * @license MIT
9 * @package recess.http
10 */
11 class StatusCodes
12 {
13 // [Informational 1xx]
14 const HTTP_CONTINUE = 100;
15 const HTTP_SWITCHING_PROTOCOLS = 101;
2 16
3 /** 17 // [Successful 2xx]
18 const HTTP_OK = 200;
19 const HTTP_CREATED = 201;
20 const HTTP_ACCEPTED = 202;
21 const HTTP_NONAUTHORITATIVE_INFORMATION = 203;
22 const HTTP_NO_CONTENT = 204;
23 const HTTP_RESET_CONTENT = 205;
24 const HTTP_PARTIAL_CONTENT = 206;
4 25
5 * StatusCodes provides named constants for 26 // [Redirection 3xx]
27 const HTTP_MULTIPLE_CHOICES = 300;
28 const HTTP_MOVED_PERMANENTLY = 301;
29 const HTTP_FOUND = 302;
30 const HTTP_SEE_OTHER = 303;
31 const HTTP_NOT_MODIFIED = 304;
32 const HTTP_USE_PROXY = 305;
33 const HTTP_UNUSED= 306;
34 const HTTP_TEMPORARY_REDIRECT = 307;
6 35
7 * HTTP protocol status codes. Written for the 36 // [Client Error 4xx]
37 const errorCodesBeginAt = 400;
38 const HTTP_BAD_REQUEST = 400;
39 const HTTP_UNAUTHORIZED = 401;
40 const HTTP_PAYMENT_REQUIRED = 402;
41 const HTTP_FORBIDDEN = 403;
42 const HTTP_NOT_FOUND = 404;
43 const HTTP_METHOD_NOT_ALLOWED = 405;
44 const HTTP_NOT_ACCEPTABLE = 406;
45 const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
46 const HTTP_REQUEST_TIMEOUT = 408;
47 const HTTP_CONFLICT = 409;
48 const HTTP_GONE = 410;
49 const HTTP_LENGTH_REQUIRED = 411;
50 const HTTP_PRECONDITION_FAILED = 412;
51 const HTTP_REQUEST_ENTITY_TOO_LARGE = 413;
52 const HTTP_REQUEST_URI_TOO_LONG = 414;
53 const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
54 const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
55 const HTTP_EXPECTATION_FAILED = 417;
8 56
9 * Recess Framework (http://www.recessframework.com/) 57 // [Server Error 5xx]
58 const HTTP_INTERNAL_SERVER_ERROR = 500;
59 const HTTP_NOT_IMPLEMENTED = 501;
60 const HTTP_BAD_GATEWAY = 502;
61 const HTTP_SERVICE_UNAVAILABLE = 503;
62 const HTTP_GATEWAY_TIMEOUT = 504;
63 const HTTP_VERSION_NOT_SUPPORTED = 505;
10 64
11 * 65 private static $messages =
66 array(
67 // [Informational 1xx]
68 100=>'100 Continue',
69 101=>'101 Switching Protocols',
12 70
13 * @author Kris Jordan 71 // [Successful 2xx]
72 200=>'200 OK',
73 201=>'201 Created',
74 202=>'202 Accepted',
75 203=>'203 Non-Authoritative Information',
76 204=>'204 No Content',
77 205=>'205 Reset Content',
78 206=>'206 Partial Content',
14 79
15 * @license MIT 80 // [Redirection 3xx]
81 300=>'300 Multiple Choices',
82 301=>'301 Moved Permanently',
83 302=>'302 Found',
84 303=>'303 See Other',
85 304=>'304 Not Modified',
86 305=>'305 Use Proxy',
87 306=>'306 (Unused)',
88 307=>'307 Temporary Redirect',
16 89
17 * @package recess.http 90 // [Client Error 4xx]
91 400=>'400 Bad Request',
92 401=>'401 Unauthorized',
93 402=>'402 Payment Required',
94 403=>'403 Forbidden',
95 404=>'404 Not Found',
96 405=>'405 Method Not Allowed',
97 406=>'406 Not Acceptable',
98 407=>'407 Proxy Authentication Required',
99 408=>'408 Request Timeout',
100 409=>'409 Conflict',
101 410=>'410 Gone',
102 411=>'411 Length Required',
103 412=>'412 Precondition Failed',
104 413=>'413 Request Entity Too Large',
105 414=>'414 Request-URI Too Long',
106 415=>'415 Unsupported Media Type',
107 416=>'416 Requested Range Not Satisfiable',
108 417=>'417 Expectation Failed',
18 109
19 */ 110 // [Server Error 5xx]
111 500=>'500 Internal Server Error',
112 501=>'501 Not Implemented',
113 502=>'502 Bad Gateway',
114 503=>'503 Service Unavailable',
115 504=>'504 Gateway Timeout',
116 505=>'505 HTTP Version Not Supported'
117 );
20 118
21 class StatusCodes { 119 public static function httpHeaderFor($code)
120 {
121 return 'HTTP/1.1 ' . self::$messages[$code];
122 }
22 123
23 // [Informational 1xx] 124 public static function getMessageForCode($code)
125 {
126 return self::$messages[$code];
127 }
24 128
25 const HTTP_CONTINUE = 100; 129 public static function isError($code)
130 {
131 return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST;
132 }
26 133
27 const HTTP_SWITCHING_PROTOCOLS = 101; 134 public static function canHaveBody($code)
28 135 {
29 // [Successful 2xx] 136 return
30 137 // True if not in 100s
31 const HTTP_OK = 200; 138 ($code < self::HTTP_CONTINUE || $code >= self::HTTP_OK)
32 139 && // and not 204 NO CONTENT
33 const HTTP_CREATED = 201; 140 $code != self::HTTP_NO_CONTENT
34 141 && // and not 304 NOT MODIFIED
35 const HTTP_ACCEPTED = 202; 142 $code != self::HTTP_NOT_MODIFIED;
36 143 }
37 const HTTP_NONAUTHORITATIVE_INFORMATION = 203;
38
39 const HTTP_NO_CONTENT = 204;
40
41 const HTTP_RESET_CONTENT = 205;
42
43 const HTTP_PARTIAL_CONTENT = 206;
44
45 // [Redirection 3xx]
46
47 const HTTP_MULTIPLE_CHOICES = 300;
48
49 const HTTP_MOVED_PERMANENTLY = 301;
50
51 const HTTP_FOUND = 302;
52
53 const HTTP_SEE_OTHER = 303;
54
55 const HTTP_NOT_MODIFIED = 304;
56
57 const HTTP_USE_PROXY = 305;
58
59 const HTTP_UNUSED= 306;
60
61 const HTTP_TEMPORARY_REDIRECT = 307;
62
63 // [Client Error 4xx]
64
65 const errorCodesBeginAt = 400;
66
67 const HTTP_BAD_REQUEST = 400;
68
69 const HTTP_UNAUTHORIZED = 401;
70
71 const HTTP_PAYMENT_REQUIRED = 402;
72
73 const HTTP_FORBIDDEN = 403;
74
75 const HTTP_NOT_FOUND = 404;
76
77 const HTTP_METHOD_NOT_ALLOWED = 405;
78
79 const HTTP_NOT_ACCEPTABLE = 406;
80
81 const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407;
82
83 const HTTP_REQUEST_TIMEOUT = 408;
84
85 const HTTP_CONFLICT = 409;
86
87 const HTTP_GONE = 410;
88
89 const HTTP_LENGTH_REQUIRED = 411;
90
91 const HTTP_PRECONDITION_FAILED = 412;
92
93 const HTTP_REQUEST_ENTITY_TOO_LARGE = 413;
94
95 const HTTP_REQUEST_URI_TOO_LONG = 414;
96
97 const HTTP_UNSUPPORTED_MEDIA_TYPE = 415;
98
99 const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
100
101 const HTTP_EXPECTATION_FAILED = 417;
102
103 // [Server Error 5xx]
104
105 const HTTP_INTERNAL_SERVER_ERROR = 500;
106
107 const HTTP_NOT_IMPLEMENTED = 501;
108
109 const HTTP_BAD_GATEWAY = 502;
110
111 const HTTP_SERVICE_UNAVAILABLE = 503;
112
113 const HTTP_GATEWAY_TIMEOUT = 504;
114
115 const HTTP_VERSION_NOT_SUPPORTED = 505;
116
117
118
119 private static $messages = array(
120
121 // [Informational 1xx]
122
123 100=>'100 Continue',
124
125 101=>'101 Switching Protocols',
126
127 // [Successful 2xx]
128
129 200=>'200 OK',
130
131 201=>'201 Created',
132
133 202=>'202 Accepted',
134
135 203=>'203 Non-Authoritative Information',
136
137 204=>'204 No Content',
138
139 205=>'205 Reset Content',
140
141 206=>'206 Partial Content',
142
143 // [Redirection 3xx]
144
145 300=>'300 Multiple Choices',
146
147 301=>'301 Moved Permanently',
148
149 302=>'302 Found',
150
151 303=>'303 See Other',
152
153 304=>'304 Not Modified',
154
155 305=>'305 Use Proxy',
156
157 306=>'306 (Unused)',
158
159 307=>'307 Temporary Redirect',
160
161 // [Client Error 4xx]
162
163 400=>'400 Bad Request',
164
165 401=>'401 Unauthorized',
166
167 402=>'402 Payment Required',
168
169 403=>'403 Forbidden',
170
171 404=>'404 Not Found',
172
173 405=>'405 Method Not Allowed',
174
175 406=>'406 Not Acceptable',
176
177 407=>'407 Proxy Authentication Required',
178
179 408=>'408 Request Timeout',
180
181 409=>'409 Conflict',
182
183 410=>'410 Gone',
184
185 411=>'411 Length Required',
186
187 412=>'412 Precondition Failed',
188
189 413=>'413 Request Entity Too Large',
190
191 414=>'414 Request-URI Too Long',
192
193 415=>'415 Unsupported Media Type',
194
195 416=>'416 Requested Range Not Satisfiable',
196
197 417=>'417 Expectation Failed',
198
199 // [Server Error 5xx]
200
201 500=>'500 Internal Server Error',
202
203 501=>'501 Not Implemented',
204
205 502=>'502 Bad Gateway',
206
207 503=>'503 Service Unavailable',
208
209 504=>'504 Gateway Timeout',
210
211 505=>'505 HTTP Version Not Supported'
212
213 );
214
215
216
217 public static function httpHeaderFor($code) {
218
219 return 'HTTP/1.1 ' . self::$messages[$code];
220
221 } 144 }
222
223 public static function getMessageForCode($code) {
224
225 return self::$messages[$code];
226
227 }
228
229
230 public static function isError($code) {
231
232 return is_numeric($code) && $code >= self::HTTP_BAD_REQUEST;
233
234 }
235
236
237 public static function canHaveBody($code) {
238
239 return
240
241 // True if not in 100s
242
243 ($code < self::HTTP_CONTINUE || $code >= self::HTTP_OK)
244
245 && // and not 204 NO CONTENT
246
247 $code != self::HTTP_NO_CONTENT
248
249 && // and not 304 NOT MODIFIED
250
251 $code != self::HTTP_NOT_MODIFIED;
252
253 }
254 }
255
256 ?> 145 ?>