|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of slick/http |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Slick\Http\Message; |
|
11
|
|
|
|
|
12
|
|
|
use Slick\Http\Message\Exception\InvalidArgumentException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* HTTP Codes |
|
16
|
|
|
* |
|
17
|
|
|
* @package Slick\Http\Message |
|
18
|
|
|
*/ |
|
19
|
|
|
final class HttpCodes |
|
20
|
|
|
{ |
|
21
|
|
|
private static $codes = [ |
|
22
|
|
|
100 => "Continue", |
|
23
|
|
|
101 => "Switching Protocols", |
|
24
|
|
|
102 => "Processing", |
|
25
|
|
|
200 => "OK", |
|
26
|
|
|
201 => "Created", |
|
27
|
|
|
202 => "Accepted", |
|
28
|
|
|
203 => "Non-Authoritative Information", |
|
29
|
|
|
204 => "No Content", |
|
30
|
|
|
205 => "Reset Content", |
|
31
|
|
|
206 => "Partial Content", |
|
32
|
|
|
207 => "Multi-Status", |
|
33
|
|
|
208 => "Already Reported", |
|
34
|
|
|
226 => "IM Used", |
|
35
|
|
|
300 => "Multiple Choices", |
|
36
|
|
|
301 => "Moved Permanently", |
|
37
|
|
|
302 => "Found", |
|
38
|
|
|
303 => "See Other", |
|
39
|
|
|
304 => "Not Modified", |
|
40
|
|
|
305 => "Use Proxy", |
|
41
|
|
|
306 => "(Unused)", |
|
42
|
|
|
307 => "Temporary Redirect", |
|
43
|
|
|
308 => "Permanent Redirect", |
|
44
|
|
|
400 => "Bad Request", |
|
45
|
|
|
401 => "Unauthorized", |
|
46
|
|
|
402 => "Payment Required", |
|
47
|
|
|
403 => "Forbidden", |
|
48
|
|
|
404 => "Not Found", |
|
49
|
|
|
405 => "Method Not Allowed", |
|
50
|
|
|
406 => "Not Acceptable", |
|
51
|
|
|
407 => "Proxy Authentication Required", |
|
52
|
|
|
408 => "Request Timeout", |
|
53
|
|
|
409 => "Conflict", |
|
54
|
|
|
410 => "Gone", |
|
55
|
|
|
411 => "Length Required", |
|
56
|
|
|
412 => "Precondition Failed", |
|
57
|
|
|
413 => "Payload Too Large", |
|
58
|
|
|
414 => "URI Too Long", |
|
59
|
|
|
415 => "Unsupported Media Type", |
|
60
|
|
|
416 => "Range Not Satisfiable", |
|
61
|
|
|
417 => "Expectation Failed", |
|
62
|
|
|
421 => "Misdirected Request", |
|
63
|
|
|
422 => "Unprocessable Entity", |
|
64
|
|
|
423 => "Locked", |
|
65
|
|
|
424 => "Failed Dependency", |
|
66
|
|
|
425 => "Unassigned", |
|
67
|
|
|
426 => "Upgrade Required", |
|
68
|
|
|
427 => "Unassigned", |
|
69
|
|
|
428 => "Precondition Required", |
|
70
|
|
|
429 => "Too Many Requests", |
|
71
|
|
|
430 => "Unassigned", |
|
72
|
|
|
431 => "Request Header Fields Too Large", |
|
73
|
|
|
451 => "Unavailable For Legal Reasons", |
|
74
|
|
|
500 => "Internal Server Error", |
|
75
|
|
|
501 => "Not Implemented", |
|
76
|
|
|
502 => "Bad Gateway", |
|
77
|
|
|
503 => "Service Unavailable", |
|
78
|
|
|
504 => "Gateway Timeout", |
|
79
|
|
|
505 => "HTTP Version Not Supported", |
|
80
|
|
|
506 => "Variant Also Negotiates", |
|
81
|
|
|
507 => "Insufficient Storage", |
|
82
|
|
|
508 => "Loop Detected", |
|
83
|
|
|
509 => "Unassigned", |
|
84
|
|
|
510 => "Not Extended", |
|
85
|
|
|
511 => "Network Authentication Required" |
|
86
|
|
|
]; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get the Reason Phrase for provide code |
|
90
|
|
|
* |
|
91
|
|
|
* @param int $code |
|
92
|
|
|
* |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public static function reasonPhraseFor($code) |
|
96
|
|
|
{ |
|
97
|
|
|
$status = ''; |
|
98
|
|
|
if (array_key_exists($code, self::$codes)) { |
|
99
|
|
|
$status = self::$codes[$code]; |
|
100
|
|
|
} |
|
101
|
|
|
return $status; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Check if provided code is a valid HTTP status code |
|
106
|
|
|
* |
|
107
|
|
|
* @param int $code |
|
108
|
|
|
*/ |
|
109
|
|
|
public static function check($code) |
|
110
|
|
|
{ |
|
111
|
|
|
$regex = '/^(1|2|3|4|5)[0-9]{2}$/i'; |
|
112
|
|
|
if (!preg_match($regex, $code)) { |
|
113
|
|
|
throw new InvalidArgumentException( |
|
114
|
|
|
"Invalid HTTP response status code." |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|