1 | <?php |
||
33 | class ServiceAdapter extends AbstractAdapter |
||
34 | { |
||
35 | /** |
||
36 | * Starts the session. |
||
37 | * |
||
38 | * @return ServiceInterface |
||
39 | * |
||
40 | * @codeCoverageIgnore - not testing session (yet) |
||
41 | */ |
||
42 | public function initSession() : ServiceInterface |
||
64 | |||
65 | /** |
||
66 | * Runs the application. This is where the magic happens. |
||
67 | * According tho the environment settings this must build up the middleware pipeline and execute it. |
||
68 | * |
||
69 | * a Pre-Routing Middleware can be; priority < 0: |
||
70 | * - LockCheck - check if the client IP is banned > S102|S403 |
||
71 | * - Auth - if the user is not logged in, but there's a "Remember me" cookie, then logs in > S102 |
||
72 | * |
||
73 | * Routing Middleware is fixed (RoutingMiddleware::class); priority = 0: |
||
74 | * - A middleware that routes the incoming Request and delegates to the matched middleware. > S102|S404|S405 |
||
75 | * The RouteResult should be attached to the Request. |
||
76 | * If the Routing is not defined explicitly in the pipeline, then it will be injected with priority 0. |
||
77 | * |
||
78 | * a Post-Routing Middleware can be; priority between 0 and 100: |
||
79 | * - Acl - checks if the given route is available for the client. Also checks the auth > S102|S401|S403 |
||
80 | * - CacheReader - checks if a suitable response body is cached. > S102|S200 |
||
81 | * |
||
82 | * Dispatcher Middleware is fixed (DispatcherMiddleware::class); priority = 100: |
||
83 | * - A middleware which gets the corresponding Action middleware and applies it > S102 |
||
84 | * If the Dispatcher is not defined explicitly in the pipeline, then it will be injected with priority 100. |
||
85 | * The Dispatcher should not set the response Status Code to 200 to let Post-Dispatchers to be called. |
||
86 | * |
||
87 | * a Post-Dispatch Middleware can be; priority > 100: |
||
88 | * - CacheWriter - writes response body into DataStorage (DB, File etc.) > S102 |
||
89 | * |
||
90 | * Final Middleware is fixed (FinalMiddleware:class): |
||
91 | * - This middleware behaves a bit differently. It cannot be ordered, it's always the last called middleware: |
||
92 | * - when the middleware pipeline reached its end (typically when the Status Code is still 102) |
||
93 | * - when one item of the middleware pipeline returns with return response (status code is set to 200|40*|500) |
||
94 | * - when during the pipeline process an Exception is thrown. |
||
95 | * |
||
96 | * When the middleware pipeline is finished the application prints the header and the output. |
||
97 | * |
||
98 | * If a middleware other than the Routing, Dispatcher and Final Middleware has no priority set, it will be |
||
99 | * considered to have priority = 50. |
||
100 | * |
||
101 | * @return ServiceInterface |
||
102 | */ |
||
103 | 5 | public function run() : ServiceInterface |
|
152 | |||
153 | /** |
||
154 | * Renders the response body and sends it to the client. |
||
155 | * |
||
156 | * @return void |
||
157 | * |
||
158 | * @codeCoverageIgnore - no output for tests |
||
159 | */ |
||
160 | public function renderOutput() : void |
||
188 | |||
189 | /** |
||
190 | * Sends the response body to the client. |
||
191 | * |
||
192 | * @return void |
||
193 | * |
||
194 | * @codeCoverageIgnore - no output for tests |
||
195 | */ |
||
196 | public function sendOutput() : void |
||
228 | |||
229 | /** |
||
230 | * Instantiates and invokes a middleware |
||
231 | * |
||
232 | * @param string $middlewareClass |
||
233 | * @return void |
||
234 | */ |
||
235 | 5 | protected function invokeMiddleware(string $middlewareClass) : void |
|
256 | |||
257 | /** |
||
258 | * Inject the Content-Length header if is not already present. |
||
259 | * |
||
260 | * NOTE: if there will be chunk content displayed, check if the response getSize counts the real size correctly |
||
261 | * |
||
262 | * @param null|int $contentLength |
||
263 | * @return void |
||
264 | * |
||
265 | * @codeCoverageIgnore - no putput for tests. |
||
266 | */ |
||
267 | protected function injectContentLength(? int $contentLength) : void |
||
275 | |||
276 | /** |
||
277 | * Filter a header name to word case. |
||
278 | * |
||
279 | * @param string $headerName |
||
280 | * @return string |
||
281 | */ |
||
282 | 5 | protected function filterHeaderName(string $headerName) : string |
|
288 | |||
289 | /** |
||
290 | * Sends the HTTP header. |
||
291 | * |
||
292 | * @return void |
||
293 | * |
||
294 | * @codeCoverageIgnore - vendor and core function calls |
||
295 | */ |
||
296 | protected function sendHttpHeader() : void |
||
306 | |||
307 | /** |
||
308 | * Sends out output headers. |
||
309 | * |
||
310 | * @param array $headers |
||
311 | * @return void |
||
312 | * |
||
313 | * @codeCoverageIgnore - vendor and core function calls in loop |
||
314 | */ |
||
315 | protected function sendOutputHeaders(array $headers) : void |
||
327 | } |
||
328 |