1 | <?php |
||
12 | class Response { |
||
13 | /** |
||
14 | * Create a new response object |
||
15 | * |
||
16 | * @return ResponseInterface |
||
17 | */ |
||
18 | 1 | public static function response() { |
|
21 | |||
22 | /** |
||
23 | * Send output based on a response object |
||
24 | * @credit modified version of slimphp/slim - Slim/App.php |
||
25 | * |
||
26 | * @codeCoverageIgnore |
||
27 | * @param ResponseInterface $response |
||
28 | * @return null |
||
29 | */ |
||
30 | public static function respond( ResponseInterface $response ) { |
||
36 | |||
37 | /** |
||
38 | * Send a request's headers to the client |
||
39 | * |
||
40 | * @param ResponseInterface $response |
||
41 | * @return null |
||
42 | */ |
||
43 | protected static function sendHeaders( ResponseInterface $response ) { |
||
59 | |||
60 | /** |
||
61 | * Return a response's body stream so it is ready to be read |
||
62 | * |
||
63 | * @param ResponseInterface $response |
||
64 | * @return \Psr\Http\Message\StreamInterface |
||
65 | */ |
||
66 | protected static function getBody( ResponseInterface $response ) { |
||
73 | |||
74 | /** |
||
75 | * Return a response's body's content length |
||
76 | * |
||
77 | * @param ResponseInterface $response |
||
78 | * @return integer |
||
79 | */ |
||
80 | protected static function getBodyContentLength( ResponseInterface $response ) { |
||
94 | |||
95 | /** |
||
96 | * Send a request's body to the client |
||
97 | * |
||
98 | * @param ResponseInterface $response |
||
99 | * @return null |
||
100 | */ |
||
101 | protected static function sendBody( ResponseInterface $response, $chunk_size = 4096 ) { |
||
120 | |||
121 | /** |
||
122 | * Return a cloned response with the passed string as the body |
||
123 | * |
||
124 | * @param ResponseInterface $response |
||
125 | * @param string $output |
||
126 | * @return ResponseInterface |
||
127 | */ |
||
128 | public static function output( ResponseInterface $response, $output ) { |
||
132 | |||
133 | /** |
||
134 | * Resolve a template or a template array to an absolute filepath |
||
135 | * |
||
136 | * @param string|string[] $templates |
||
137 | * @return string |
||
138 | */ |
||
139 | protected static function resolveTemplate( $templates ) { |
||
150 | |||
151 | /** |
||
152 | * Resolve the first existing absolute template filepath from an array of template filepaths |
||
153 | * |
||
154 | * @param string[] $templates |
||
155 | * @return string |
||
156 | */ |
||
157 | protected static function resolveTemplateFromFilesystem( $templates ) { |
||
165 | |||
166 | /** |
||
167 | * Return a cloned response, resolving and rendering a template as the body |
||
168 | * |
||
169 | * @param ResponseInterface $response |
||
170 | * @param string|string[] $templates |
||
171 | * @param array $context |
||
172 | * @return ResponseInterface |
||
173 | */ |
||
174 | public static function template( ResponseInterface $response, $templates, $context = array() ) { |
||
184 | |||
185 | /** |
||
186 | * Return a cloned response, json encoding the passed data as the body |
||
187 | * |
||
188 | * @param ResponseInterface $response |
||
189 | * @param mixed $data |
||
190 | * @return ResponseInterface |
||
191 | */ |
||
192 | public static function json( ResponseInterface $response, $data ) { |
||
197 | |||
198 | /** |
||
199 | * Return a cloned response, with location and status headers |
||
200 | * |
||
201 | * @param ResponseInterface $response |
||
202 | * @param string $url |
||
203 | * @param integer $status |
||
204 | * @return ResponseInterface |
||
205 | */ |
||
206 | public static function redirect( ResponseInterface $response, $url, $status = 302 ) { |
||
211 | |||
212 | /** |
||
213 | * Return a cloned response, with status headers and rendering a suitable template as the body |
||
214 | * |
||
215 | * @param ResponseInterface $response |
||
216 | * @param integer $status |
||
217 | * @return ResponseInterface |
||
218 | */ |
||
219 | public static function error( ResponseInterface $response, $status ) { |
||
228 | } |
||
229 |