1 | <?php |
||
31 | class WebApplication extends AbstractApplication |
||
32 | { |
||
33 | /** |
||
34 | * Starts the session. |
||
35 | * |
||
36 | * @return void |
||
37 | * |
||
38 | * @codeCoverageIgnore - not testing session (yet) |
||
39 | */ |
||
40 | private function initSession() : void |
||
60 | |||
61 | /** |
||
62 | * Runs the application. This is where the magic happens. |
||
63 | * According tho the environment settings this must build up the middleware pipeline and execute it. |
||
64 | * |
||
65 | * a Pre-Routing Middleware can be; priority < 0: |
||
66 | * - LockCheck - check if the client IP is banned > S102|S403 |
||
67 | * - Auth - if the user is not logged in, but there's a "Remember me" cookie, then logs in > S102 |
||
68 | * |
||
69 | * Routing Middleware is fixed (RoutingMiddleware::class); priority = 0: |
||
70 | * - A middleware that routes the incoming Request and delegates to the matched middleware. > S102|S404|S405 |
||
71 | * The RouteResult should be attached to the Request. |
||
72 | * If the Routing is not defined explicitly in the pipeline, then it will be injected with priority 0. |
||
73 | * |
||
74 | * a Post-Routing Middleware can be; priority between 0 and 100: |
||
75 | * - Acl - checks if the given route is available for the client. Also checks the auth > S102|S401|S403 |
||
76 | * - CacheReader - checks if a suitable response body is cached. > S102|S200 |
||
77 | * |
||
78 | * Dispatcher Middleware is fixed (DispatcherMiddleware::class); priority = 100: |
||
79 | * - A middleware which gets the corresponding Action middleware and applies it > S102 |
||
80 | * If the Dispatcher is not defined explicitly in the pipeline, then it will be injected with priority 100. |
||
81 | * The Dispatcher should not set the response Status Code to 200 to let Post-Dispatchers to be called. |
||
82 | * |
||
83 | * a Post-Dispatch Middleware can be; priority > 100: |
||
84 | * - CacheWriter - writes response body into DataStorage (DB, File etc.) > S102 |
||
85 | * |
||
86 | * Final Middleware is fixed (FinalMiddleware:class): |
||
87 | * - This middleware behaves a bit differently. It cannot be ordered, it's always the last called middleware: |
||
88 | * - when the middleware pipeline reached its end (typically when the Status Code is still 102) |
||
89 | * - when one item of the middleware pipeline returns with return response (status code is set to 200|40*|500) |
||
90 | * - when during the pipeline process an Exception is thrown. |
||
91 | * |
||
92 | * When the middleware pipeline is finished the application prints the header and the output. |
||
93 | * |
||
94 | * If a middleware other than the Routing, Dispatcher and Final Middleware has no priority set, it will be |
||
95 | * considered to have priority = 50. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | 5 | public function run() : void |
|
130 | |||
131 | /** |
||
132 | * Gets the Request object. |
||
133 | * |
||
134 | * @return ServerRequestInterface |
||
135 | */ |
||
136 | 5 | private function getRequest() |
|
157 | |||
158 | /** |
||
159 | * Gets the Response object. |
||
160 | * |
||
161 | * @return ResponseInterface |
||
162 | */ |
||
163 | 5 | private function getResponse() |
|
171 | |||
172 | /** |
||
173 | * Instantiates and invokes a middleware |
||
174 | * |
||
175 | * @param string $middlewareClass |
||
176 | * @param ServerRequestInterface $request |
||
177 | * @param ResponseInterface $response |
||
178 | */ |
||
179 | 5 | private function invokeMiddleware( |
|
217 | } |
||
218 |