1 | <?php |
||
14 | class Response { |
||
15 | /** |
||
16 | * Create a new response object |
||
17 | * |
||
18 | * @return ResponseInterface |
||
19 | */ |
||
20 | 1 | public static function response() { |
|
23 | |||
24 | /** |
||
25 | * Send output based on a response object |
||
26 | * @credit modified version of slimphp/slim - Slim/App.php |
||
27 | * |
||
28 | * @codeCoverageIgnore |
||
29 | * @param ResponseInterface $response |
||
30 | * @return void |
||
31 | */ |
||
32 | public static function respond( ResponseInterface $response ) { |
||
38 | |||
39 | /** |
||
40 | * Send a request's headers to the client |
||
41 | * |
||
42 | * @codeCoverageIgnore |
||
43 | * @param ResponseInterface $response |
||
44 | * @return void |
||
45 | */ |
||
46 | protected static function sendHeaders( ResponseInterface $response ) { |
||
62 | |||
63 | /** |
||
64 | * Get a response's body stream so it is ready to be read |
||
65 | * |
||
66 | * @codeCoverageIgnore |
||
67 | * @param ResponseInterface $response |
||
68 | * @return \Psr\Http\Message\StreamInterface |
||
69 | */ |
||
70 | protected static function getBody( ResponseInterface $response ) { |
||
77 | |||
78 | /** |
||
79 | * Get a response's body's content length |
||
80 | * |
||
81 | * @codeCoverageIgnore |
||
82 | * @param ResponseInterface $response |
||
83 | * @return integer |
||
84 | */ |
||
85 | protected static function getBodyContentLength( ResponseInterface $response ) { |
||
99 | |||
100 | /** |
||
101 | * Send a request's body to the client |
||
102 | * |
||
103 | * @codeCoverageIgnore |
||
104 | * @param ResponseInterface $response |
||
105 | * @param integer $chunk_size |
||
106 | * @return void |
||
107 | */ |
||
108 | protected static function sendBody( ResponseInterface $response, $chunk_size = 4096 ) { |
||
127 | |||
128 | /** |
||
129 | * Get a cloned response with the passed string as the body |
||
130 | * |
||
131 | * @param ResponseInterface $response |
||
132 | * @param string $output |
||
133 | * @return ResponseInterface |
||
134 | */ |
||
135 | 1 | public static function output( ResponseInterface $response, $output ) { |
|
139 | |||
140 | /** |
||
141 | * Get a cloned response, resolving and rendering a view as the body |
||
142 | * |
||
143 | * @param ResponseInterface $response |
||
144 | * @param string|string[] $views |
||
145 | * @param array $context |
||
146 | * @return ResponseInterface |
||
147 | */ |
||
148 | 1 | public static function view( ResponseInterface $response, $views, $context = array() ) { |
|
157 | |||
158 | /** |
||
159 | * Get a cloned response, json encoding the passed data as the body |
||
160 | * |
||
161 | * @param ResponseInterface $response |
||
162 | * @param mixed $data |
||
163 | * @return ResponseInterface |
||
164 | */ |
||
165 | 1 | public static function json( ResponseInterface $response, $data ) { |
|
170 | |||
171 | /** |
||
172 | * Get a cloned response, with location and status headers |
||
173 | * |
||
174 | * @param ResponseInterface $response |
||
175 | * @param string $url |
||
176 | * @param integer $status |
||
177 | * @return ResponseInterface |
||
178 | */ |
||
179 | 2 | public static function redirect( ResponseInterface $response, $url, $status = 302 ) { |
|
184 | |||
185 | /** |
||
186 | * Get a cloned response, with location header equal to the current url and status header |
||
187 | * |
||
188 | * @param ResponseInterface $response |
||
189 | * @param \WPEmerge\Request $request |
||
190 | * @param integer $status |
||
191 | * @return ResponseInterface |
||
192 | */ |
||
193 | 2 | public static function reload( ResponseInterface $response, $request, $status = 302 ) { |
|
196 | |||
197 | /** |
||
198 | * Get a cloned response, with status headers and rendering a suitable view as the body |
||
199 | * |
||
200 | * @param ResponseInterface $response |
||
201 | * @param integer $status |
||
202 | * @return ResponseInterface |
||
203 | */ |
||
204 | 1 | public static function error( ResponseInterface $response, $status ) { |
|
213 | } |
||
214 |