1 | <?php |
||
5 | class HttpResponse implements Response |
||
6 | { |
||
7 | private $version = '1.1'; |
||
8 | private $statusCode = 200; |
||
9 | private $statusText = 'OK'; |
||
10 | private $headers = []; |
||
11 | private $cookies = []; |
||
12 | private $content; |
||
13 | |||
14 | private $statusTexts = [ |
||
15 | 100 => 'Continue', |
||
16 | 101 => 'Switching Protocols', |
||
17 | 102 => 'Processing', |
||
18 | 200 => 'OK', |
||
19 | 201 => 'Created', |
||
20 | 202 => 'Accepted', |
||
21 | 203 => 'Non-Authoritative Information', |
||
22 | 204 => 'No Content', |
||
23 | 205 => 'Reset Content', |
||
24 | 206 => 'Partial Content', |
||
25 | 207 => 'Multi-Status', |
||
26 | 208 => 'Already Reported', |
||
27 | 226 => 'IM Used', |
||
28 | 300 => 'Multiple Choices', |
||
29 | 301 => 'Moved Permanently', |
||
30 | 302 => 'Found', |
||
31 | 303 => 'See Other', |
||
32 | 304 => 'Not Modified', |
||
33 | 305 => 'Use Proxy', |
||
34 | 306 => 'Reserved', |
||
35 | 307 => 'Temporary Redirect', |
||
36 | 308 => 'Permanent Redirect', |
||
37 | 400 => 'Bad Request', |
||
38 | 401 => 'Unauthorized', |
||
39 | 402 => 'Payment Required', |
||
40 | 403 => 'Forbidden', |
||
41 | 404 => 'Not Found', |
||
42 | 405 => 'Method Not Allowed', |
||
43 | 406 => 'Not Acceptable', |
||
44 | 407 => 'Proxy Authentication Required', |
||
45 | 408 => 'Request Timeout', |
||
46 | 409 => 'Conflict', |
||
47 | 410 => 'Gone', |
||
48 | 411 => 'Length Required', |
||
49 | 412 => 'Precondition Failed', |
||
50 | 413 => 'Request Entity Too Large', |
||
51 | 414 => 'Request-URI Too Long', |
||
52 | 415 => 'Unsupported Media Type', |
||
53 | 416 => 'Requested Range Not Satisfiable', |
||
54 | 417 => 'Expectation Failed', |
||
55 | 418 => 'I\'m a teapot', |
||
56 | 422 => 'Unprocessable Entity', |
||
57 | 423 => 'Locked', |
||
58 | 424 => 'Failed Dependency', |
||
59 | 425 => 'Reserved for WebDAV advanced collections expired proposal', |
||
60 | 426 => 'Upgrade Required', |
||
61 | 428 => 'Precondition Required', |
||
62 | 429 => 'Too Many Requests', |
||
63 | 431 => 'Request Header Fields Too Large', |
||
64 | 500 => 'Internal Server Error', |
||
65 | 501 => 'Not Implemented', |
||
66 | 502 => 'Bad Gateway', |
||
67 | 503 => 'Service Unavailable', |
||
68 | 504 => 'Gateway Timeout', |
||
69 | 505 => 'HTTP Version Not Supported', |
||
70 | 506 => 'Variant Also Negotiates', |
||
71 | 507 => 'Insufficient Storage', |
||
72 | 508 => 'Loop Detected', |
||
73 | 510 => 'Not Extended', |
||
74 | 511 => 'Network Authentication Required', |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * Sets the HTTP status code. |
||
79 | * |
||
80 | * @param integer $statusCode |
||
81 | * @param string $statusText (optional) |
||
82 | * @return void |
||
83 | */ |
||
84 | public function setStatusCode($statusCode, $statusText = null) |
||
95 | |||
96 | /** |
||
97 | * Returns the HTTP status code |
||
98 | * @return int |
||
99 | */ |
||
100 | public function getStatusCode() |
||
104 | |||
105 | /** |
||
106 | * Adds a header with the given name. |
||
107 | * |
||
108 | * @param string $name |
||
109 | * @param string $value |
||
110 | * @return void |
||
111 | */ |
||
112 | public function addHeader($name, $value) |
||
116 | |||
117 | /** |
||
118 | * Sets a new header for the given name. |
||
119 | * |
||
120 | * Replaces all headers with the same names. |
||
121 | * |
||
122 | * @param string $name |
||
123 | * @param string $value |
||
124 | * @return void |
||
125 | */ |
||
126 | public function setHeader($name, $value) |
||
132 | |||
133 | /** |
||
134 | * Returns an array with the HTTP headers. |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getHeaders() |
||
148 | |||
149 | /** |
||
150 | * Adds a new cookie. |
||
151 | * |
||
152 | * @param Cookie $cookie |
||
153 | * @return void |
||
154 | */ |
||
155 | public function addCookie(Cookie $cookie) |
||
159 | |||
160 | /** |
||
161 | * Deletes a cookie. |
||
162 | * |
||
163 | * @param Cookie $cookie |
||
164 | * @return void |
||
165 | */ |
||
166 | public function deleteCookie(Cookie $cookie) |
||
172 | |||
173 | /** |
||
174 | * Sets the body content. |
||
175 | * |
||
176 | * @param string $content |
||
177 | * @return void |
||
178 | */ |
||
179 | public function setContent($content) |
||
183 | |||
184 | /** |
||
185 | * Returns the body content. |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | public function getContent() |
||
193 | |||
194 | /** |
||
195 | * Sets the headers for a redirect. |
||
196 | * |
||
197 | * @param string $url |
||
198 | * @return void |
||
199 | */ |
||
200 | public function redirect($url) |
||
205 | |||
206 | private function getRequestLineHeaders() |
||
221 | |||
222 | private function getStandardHeaders() |
||
234 | |||
235 | private function getCookieHeaders() |
||
245 | } |
||
246 |