1 | <?php |
||
8 | class Response |
||
9 | { |
||
10 | |||
11 | protected $response; |
||
12 | protected $outputType = Router::HTML; |
||
13 | protected $headers = []; |
||
14 | protected $statusCode = 200; |
||
15 | protected $body; |
||
16 | protected $redirectUri; |
||
17 | protected $downloadFileName; |
||
18 | protected $downloadFilePath; |
||
19 | protected $version = '1.0'; |
||
20 | protected $customContentType; |
||
21 | protected static $statusTexts = [ |
||
22 | 100 => 'Continue', |
||
23 | 101 => 'Switching Protocols', |
||
24 | 102 => 'Processing', // RFC2518 |
||
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', // RFC4918 |
||
33 | 208 => 'Already Reported', // RFC5842 |
||
34 | 226 => 'IM Used', // RFC3229 |
||
35 | 300 => 'Multiple Choices', |
||
36 | 301 => 'Moved Permanently', |
||
37 | 302 => 'Found', |
||
38 | 303 => 'See Other', |
||
39 | 304 => 'Not Modified', |
||
40 | 305 => 'Use Proxy', |
||
41 | 307 => 'Temporary Redirect', |
||
42 | 308 => 'Permanent Redirect', // RFC7238 |
||
43 | 400 => 'Bad Request', |
||
44 | 401 => 'Unauthorized', |
||
45 | 402 => 'Payment Required', |
||
46 | 403 => 'Forbidden', |
||
47 | 404 => 'Not Found', |
||
48 | 405 => 'Method Not Allowed', |
||
49 | 406 => 'Not Acceptable', |
||
50 | 407 => 'Proxy Authentication Required', |
||
51 | 408 => 'Request Timeout', |
||
52 | 409 => 'Conflict', |
||
53 | 410 => 'Gone', |
||
54 | 411 => 'Length Required', |
||
55 | 412 => 'Precondition Failed', |
||
56 | 413 => 'Payload Too Large', |
||
57 | 414 => 'URI Too Long', |
||
58 | 415 => 'Unsupported Media Type', |
||
59 | 416 => 'Range Not Satisfiable', |
||
60 | 417 => 'Expectation Failed', |
||
61 | 418 => 'I\'m a teapot', // RFC2324 |
||
62 | 421 => 'Misdirected Request', // RFC7540 |
||
63 | 422 => 'Unprocessable Entity', // RFC4918 |
||
64 | 423 => 'Locked', // RFC4918 |
||
65 | 424 => 'Failed Dependency', // RFC4918 |
||
66 | 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
||
67 | 426 => 'Upgrade Required', // RFC2817 |
||
68 | 428 => 'Precondition Required', // RFC6585 |
||
69 | 429 => 'Too Many Requests', // RFC6585 |
||
70 | 431 => 'Request Header Fields Too Large', // RFC6585 |
||
71 | 451 => 'Unavailable For Legal Reasons', // RFC7725 |
||
72 | 500 => 'Internal Server Error', |
||
73 | 501 => 'Not Implemented', |
||
74 | 502 => 'Bad Gateway', |
||
75 | 503 => 'Service Unavailable', |
||
76 | 504 => 'Gateway Timeout', |
||
77 | 505 => 'HTTP Version Not Supported', |
||
78 | 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
||
79 | 507 => 'Insufficient Storage', // RFC4918 |
||
80 | 508 => 'Loop Detected', // RFC5842 |
||
81 | 510 => 'Not Extended', // RFC2774 |
||
82 | 511 => 'Network Authentication Required', // RFC6585 |
||
83 | ]; |
||
84 | |||
85 | public function setHeaders(array $headers = []) : void |
||
95 | |||
96 | public function setHeader(string $header, string $value) : void |
||
100 | |||
101 | public function setStatusCode(int $statusCode) : void |
||
105 | |||
106 | public function setRedirect(string $redirectUri, int $code = 302) : void |
||
112 | |||
113 | public function setBody(string $body) : void |
||
117 | |||
118 | public function setDownloadFilePath(string $filePath) : void |
||
122 | |||
123 | public function setDownloadFileName(string $fileName) : void |
||
127 | |||
128 | |||
129 | public function getDownloadFilePath() : ?string |
||
133 | |||
134 | public function getDownloadFileName() : ?string |
||
138 | |||
139 | |||
140 | public function setCustomContentType(string $contentType) : void |
||
144 | |||
145 | |||
146 | public function getCustomContentType() : ?string |
||
150 | |||
151 | public function setData(array $body) : void |
||
155 | |||
156 | public function setOutputType(int $type) : void |
||
162 | |||
163 | public function getOutputType() : int |
||
167 | |||
168 | public function getHeaders() : array |
||
172 | |||
173 | public function getStatusCode() : int |
||
181 | |||
182 | public function getRedirectUri() : string |
||
186 | |||
187 | public function sendHeaders() : void |
||
231 | |||
232 | public function sendContent() : void |
||
236 | |||
237 | private function getContent() |
||
244 | |||
245 | public function send() : void |
||
250 | } |
||
251 |