Skip to content

Commit 394ecdd

Browse files
author
Greg Bowler
authored
Add named constant for each HTTP status code (#24)
* Add named constant for each HTTP status code * Add exception for throwing in application code
1 parent f7bb4fa commit 394ecdd

File tree

3 files changed

+156
-91
lines changed

3 files changed

+156
-91
lines changed

composer.lock

Lines changed: 30 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HttpRedirectException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
namespace Gt\Http;
3+
4+
class HttpRedirectException extends HttpException {}

src/StatusCode.php

Lines changed: 122 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,128 @@
33
namespace Gt\Http;
44

55
class StatusCode {
6+
const CONTINUE = 100;
7+
const SWITCHING_PROTOCOLS = 101;
8+
const PROCESSING = 102;
9+
const OK = 200;
10+
const CREATED = 201;
11+
const ACCEPTED = 202;
12+
const NON_AUTHORITATIVE_INFORMATION = 203;
13+
const NO_CONTENT = 204;
14+
const RESET_CONTENT = 205;
15+
const PARTIAL_CONTENT = 206;
16+
const MULTI_STATUS = 207;
17+
const ALREADY_REPORTED = 208;
18+
const MULTIPLE_CHOICES = 300;
19+
const MOVED_PERMANENTLY = 301;
20+
const FOUND = 302;
21+
const SEE_OTHER = 303;
22+
const NOT_MODIFIED = 304;
23+
const USE_PROXY = 305;
24+
const SWITCH_PROXY = 306;
25+
const TEMPORARY_REDIRECT = 307;
26+
const BAD_REQUEST = 400;
27+
const UNAUTHORIZED = 401;
28+
const PAYMENT_REQUIRED = 402;
29+
const FORBIDDEN = 403;
30+
const NOT_FOUND = 404;
31+
const METHOD_NOT_ALLOWED = 405;
32+
const NOT_ACCEPTABLE = 406;
33+
const PROXY_AUTHENTICATION_REQUIRED = 407;
34+
const REQUEST_TIME_OUT = 408;
35+
const CONFLICT = 409;
36+
const GONE = 410;
37+
const LENGTH_REQUIRED = 411;
38+
const PRECONDITION_FAILED = 412;
39+
const REQUEST_ENTITY_TOO_LARGE = 413;
40+
const REQUEST_URI_TOO_LARGE = 414;
41+
const UNSUPPORTED_MEDIA_TYPE = 415;
42+
const REQUESTED_RANGE_NOT_SATISFIABLE = 416;
43+
const EXPECTATION_FAILED = 417;
44+
const IM_A_TEAPOT = 418;
45+
const UNPROCESSABLE_ENTITY = 422;
46+
const LOCKED = 423;
47+
const FAILED_DEPENDENCY = 424;
48+
const UNORDERED_COLLECTION = 425;
49+
const UPGRADE_REQUIRED = 426;
50+
const PRECONDITION_REQUIRED = 428;
51+
const TOO_MANY_REQUESTS = 429;
52+
const REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
53+
const UNAVAILABLE_FOR_LEGAL_REASONS = 451;
54+
55+
const INTERNAL_SERVER_ERROR = 500;
56+
const NOT_IMPLEMENTED = 501;
57+
const BAD_GATEWAY = 502;
58+
const SERVICE_UNAVAILABLE = 503;
59+
const GATEWAY_TIMEOUT = 504;
60+
const HTTP_VERSION_NOT_SUPPORTED = 505;
61+
const VARIANT_ALSO_NEGOTIATES = 506;
62+
const INSUFFICIENT_STORAGE = 507;
63+
const LOOP_DETECTED = 508;
64+
const NETWORK_AUTHENTICATION_REQUIRED = 511;
65+
666
const REASON_PHRASE = [
7-
100 => "Continue",
8-
101 => "Switching Protocols",
9-
102 => "Processing",
10-
200 => "OK",
11-
201 => "Created",
12-
202 => "Accepted",
13-
203 => "Non-Authoritative Information",
14-
204 => "No Content",
15-
205 => "Reset Content",
16-
206 => "Partial Content",
17-
207 => "Multi-status",
18-
208 => "Already Reported",
19-
300 => "Multiple Choices",
20-
301 => "Moved Permanently",
21-
302 => "Found",
22-
303 => "See Other",
23-
304 => "Not Modified",
24-
305 => "Use Proxy",
25-
306 => "Switch Proxy",
26-
307 => "Temporary Redirect",
27-
400 => "Bad Request",
28-
401 => "Unauthorized",
29-
402 => "Payment Required",
30-
403 => "Forbidden",
31-
404 => "Not Found",
32-
405 => "Method Not Allowed",
33-
406 => "Not Acceptable",
34-
407 => "Proxy Authentication Required",
35-
408 => "Request Time-out",
36-
409 => "Conflict",
37-
410 => "Gone",
38-
411 => "Length Required",
39-
412 => "Precondition Failed",
40-
413 => "Request Entity Too Large",
41-
414 => "Request-URI Too Large",
42-
415 => "Unsupported Media Type",
43-
416 => "Requested range not satisfiable",
44-
417 => "Expectation Failed",
45-
418 => "I'm a teapot",
46-
422 => "Unprocessable Entity",
47-
423 => "Locked",
48-
424 => "Failed Dependency",
49-
425 => "Unordered Collection",
50-
426 => "Upgrade Required",
51-
428 => "Precondition Required",
52-
429 => "Too Many Requests",
53-
431 => "Request Header Fields Too Large",
54-
451 => "Unavailable For Legal Reasons",
55-
500 => "Internal Server Error",
56-
501 => "Not Implemented",
57-
502 => "Bad Gateway",
58-
503 => "Service Unavailable",
59-
504 => "Gateway Time-out",
60-
505 => "HTTP Version not supported",
61-
506 => "Variant Also Negotiates",
62-
507 => "Insufficient Storage",
63-
508 => "Loop Detected",
64-
511 => "Network Authentication Required",
65-
];
67+
self::CONTINUE => "Continue",
68+
self::SWITCHING_PROTOCOLS => "Switching Protocols",
69+
self::PROCESSING => "Processing",
70+
71+
self::OK => "OK",
72+
self::CREATED => "Created",
73+
self::ACCEPTED => "Accepted",
74+
self::NON_AUTHORITATIVE_INFORMATION => "Non-Authoritative Information",
75+
self::NO_CONTENT => "No Content",
76+
self::RESET_CONTENT => "Reset Content",
77+
self::PARTIAL_CONTENT => "Partial Content",
78+
self::MULTI_STATUS => "Multi-status",
79+
self::ALREADY_REPORTED => "Already Reported",
6680

81+
self::MULTIPLE_CHOICES => "Multiple Choices",
82+
self::MOVED_PERMANENTLY => "Moved Permanently",
83+
self::FOUND => "Found",
84+
self::SEE_OTHER => "See Other",
85+
self::NOT_MODIFIED => "Not Modified",
86+
self::USE_PROXY => "Use Proxy",
87+
self::SWITCH_PROXY => "Switch Proxy",
88+
self::TEMPORARY_REDIRECT => "Temporary Redirect",
89+
90+
self::BAD_REQUEST => "Bad Request",
91+
self::UNAUTHORIZED => "Unauthorized",
92+
self::PAYMENT_REQUIRED => "Payment Required",
93+
self::FORBIDDEN => "Forbidden",
94+
self::NOT_FOUND => "Not Found",
95+
self::METHOD_NOT_ALLOWED => "Method Not Allowed",
96+
self::NOT_ACCEPTABLE => "Not Acceptable",
97+
self::PROXY_AUTHENTICATION_REQUIRED => "Proxy Authentication Required",
98+
self::REQUEST_TIME_OUT => "Request Time-out",
99+
self::CONFLICT => "Conflict",
100+
self::GONE => "Gone",
101+
self::LENGTH_REQUIRED => "Length Required",
102+
self::PRECONDITION_FAILED => "Precondition Failed",
103+
self::REQUEST_ENTITY_TOO_LARGE => "Request Entity Too Large",
104+
self::REQUEST_URI_TOO_LARGE => "Request-URI Too Large",
105+
self::UNSUPPORTED_MEDIA_TYPE => "Unsupported Media Type",
106+
self::REQUESTED_RANGE_NOT_SATISFIABLE => "Requested range not satisfiable",
107+
self::EXPECTATION_FAILED => "Expectation Failed",
108+
self::IM_A_TEAPOT => "I'm a teapot",
109+
self::UNPROCESSABLE_ENTITY => "Unprocessable Entity",
110+
self::LOCKED => "Locked",
111+
self::FAILED_DEPENDENCY => "Failed Dependency",
112+
self::UNORDERED_COLLECTION => "Unordered Collection",
113+
self::UPGRADE_REQUIRED => "Upgrade Required",
114+
self::PRECONDITION_REQUIRED => "Precondition Required",
115+
self::TOO_MANY_REQUESTS => "Too Many Requests",
116+
self::REQUEST_HEADER_FIELDS_TOO_LARGE => "Request Header Fields Too Large",
117+
self::UNAVAILABLE_FOR_LEGAL_REASONS => "Unavailable For Legal Reasons",
118+
119+
self::INTERNAL_SERVER_ERROR => "Internal Server Error",
120+
self::NOT_IMPLEMENTED => "Not Implemented",
121+
self::BAD_GATEWAY => "Bad Gateway",
122+
self::SERVICE_UNAVAILABLE => "Service Unavailable",
123+
self::GATEWAY_TIMEOUT => "Gateway Time-out",
124+
self::HTTP_VERSION_NOT_SUPPORTED => "HTTP Version not supported",
125+
self::VARIANT_ALSO_NEGOTIATES => "Variant Also Negotiates",
126+
self::INSUFFICIENT_STORAGE => "Insufficient Storage",
127+
self::LOOP_DETECTED => "Loop Detected",
128+
self::NETWORK_AUTHENTICATION_REQUIRED => "Network Authentication Required",
129+
];
67130
}

0 commit comments

Comments
 (0)