1 | <?php |
||
29 | class FinalMiddleware implements MiddlewareInterface |
||
30 | { |
||
31 | /** @var RendererAdapterInterface */ |
||
32 | private $templateRenderer; |
||
33 | /** @var AuthAdapterInterface */ |
||
34 | private $authAdapter; |
||
35 | /** @var EnvironmentManager */ |
||
36 | private $environmentManager; |
||
37 | /** @var LogAdapterInterface */ |
||
38 | private $logAdapter; |
||
39 | |||
40 | /** |
||
41 | * FinalMiddleware constructor. |
||
42 | * |
||
43 | * @param RendererAdapterInterface $templateRenderer |
||
44 | * @param AuthAdapterInterface $authAdapter |
||
45 | * @param EnvironmentManager $environmentManager |
||
46 | * @param LogAdapterInterface $logAdapter |
||
47 | */ |
||
48 | 8 | public function __construct( |
|
59 | |||
60 | /** |
||
61 | * Sends out the headers and prints the response body to the output. |
||
62 | * |
||
63 | * @param ServerRequestInterface $request |
||
64 | * @param ResponseInterface $response |
||
65 | * @return void |
||
66 | */ |
||
67 | 3 | public function __invoke(ServerRequestInterface&$request, ResponseInterface&$response) : void |
|
90 | |||
91 | /** |
||
92 | * Prepares error response: Body and Data |
||
93 | * |
||
94 | * @param Throwable $exception |
||
95 | * @param ServerRequestInterface $request |
||
96 | * @param ResponseInterface $response |
||
97 | */ |
||
98 | 2 | private function prepareErrorResponse( |
|
116 | |||
117 | /** |
||
118 | * Logs the error. |
||
119 | * |
||
120 | * @param Throwable $exception |
||
121 | * @param ServerRequestInterface $request |
||
122 | * @param ResponseInterface $response |
||
123 | */ |
||
124 | 2 | private function logErrorResponse( |
|
148 | |||
149 | /** |
||
150 | * Inject the Content-Length header if is not already present. |
||
151 | * |
||
152 | * NOTE: if there will be chunk content displayed, check if the response getSize counts the real size correctly |
||
153 | * |
||
154 | * @param ResponseInterface $response |
||
155 | * @return void |
||
156 | * |
||
157 | * @codeCoverageIgnore - no putput for tests. |
||
158 | */ |
||
159 | private function injectContentLength(ResponseInterface&$response) : void |
||
165 | |||
166 | /** |
||
167 | * Filter a header name to word case. |
||
168 | * |
||
169 | * @param string $headerName |
||
170 | * @return string |
||
171 | */ |
||
172 | 5 | private function filterHeaderName(string $headerName) : string |
|
178 | |||
179 | /** |
||
180 | * Sends the HTTP header. |
||
181 | * |
||
182 | * @param ResponseInterface $response |
||
183 | * @return void |
||
184 | * |
||
185 | * @codeCoverageIgnore - vendor and core function calls |
||
186 | */ |
||
187 | private function sendHttpHeader(ResponseInterface $response) : void |
||
197 | |||
198 | /** |
||
199 | * Sends out output headers. |
||
200 | * |
||
201 | * @param array $headers |
||
202 | * @return void |
||
203 | * |
||
204 | * @codeCoverageIgnore - vendor and core function calls in loop |
||
205 | */ |
||
206 | private function sendOutputHeaders(array $headers) : void |
||
217 | |||
218 | /** |
||
219 | * Sends output according to the request. |
||
220 | * |
||
221 | * @param ServerRequestInterface $request |
||
222 | * @param ResponseInterface $response |
||
223 | * @return void |
||
224 | * |
||
225 | * @codeCoverageIgnore - no output for tests |
||
226 | */ |
||
227 | private function sendOutput(ServerRequestInterface $request, ResponseInterface $response) : void |
||
243 | } |
||
244 |