1 | <?php |
||
31 | class WebApplication implements ApplicationInterface |
||
32 | { |
||
33 | /** @var DependencyInjectionAdapterInterface */ |
||
34 | private $container; |
||
35 | /** @var EnvironmentManager */ |
||
36 | private $environmentManager; |
||
37 | /** @var MiddlewarePipelineInterface */ |
||
38 | private $pipeline; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * ApplicationInterface constructor. |
||
43 | * |
||
44 | * @param DependencyInjectionAdapterInterface $container |
||
45 | * @param EnvironmentManager $environmentManager |
||
46 | * @param MiddlewarePipelineInterface $pipeline |
||
47 | */ |
||
48 | 3 | public function __construct( |
|
57 | |||
58 | /** |
||
59 | * Returns the DI Adapter instance. |
||
60 | * |
||
61 | * @return DependencyInjectionAdapterInterface |
||
62 | */ |
||
63 | 3 | public function getContainer() |
|
67 | |||
68 | /** |
||
69 | * Get ready to run the application: set final data for specific services. |
||
70 | * |
||
71 | * @codeCoverageIgnore - Check the EnvironmentManager and Container adapter tests. |
||
72 | */ |
||
73 | private function prepare() |
||
115 | |||
116 | /** |
||
117 | * Runs the application. This is where the magic happens. |
||
118 | * According tho the environment settings this must build up the middleware pipeline and execute it. |
||
119 | * |
||
120 | * a Pre-Routing Middleware can be; priority < 0: |
||
121 | * - LockCheck - check if the client IP is banned > S102|S403 |
||
122 | * - Auth - if the user is not logged in, but there's a "Remember me" cookie, then logs in > S102 |
||
123 | * |
||
124 | * Routing Middleware is fixed (RoutingMiddleware::class); priority = 0: |
||
125 | * - A middleware that routes the incoming Request and delegates to the matched middleware. > S102|S404|S405 |
||
126 | * The RouteResult should be attached to the Request. |
||
127 | * If the Routing is not defined explicitly in the pipeline, then it will be injected with priority 0. |
||
128 | * |
||
129 | * a Post-Routing Middleware can be; priority between 0 and 100: |
||
130 | * - Acl - checks if the given route is available for the client. Also checks the auth > S102|S401|S403 |
||
131 | * - CacheReader - checks if a suitable response body is cached. > S102|S200 |
||
132 | * |
||
133 | * Dispatcher Middleware is fixed (DispatcherMiddleware::class); priority = 100: |
||
134 | * - A middleware which gets the corresponding Action middleware and applies it > S102 |
||
135 | * If the Dispatcher is not defined explicitly in the pipeline, then it will be injected with priority 100. |
||
136 | * The Dispatcher should not set the response Status Code to 200 to let Post-Dispatchers to be called. |
||
137 | * |
||
138 | * a Post-Dispatch Middleware can be; priority > 100: |
||
139 | * - CacheWriter - writes response body into DataStorage (DB, File etc.) > S102 |
||
140 | * |
||
141 | * Final Middleware is fixed (FinalMiddleware:class): |
||
142 | * - This middleware behaves a bit differently. It cannot be ordered, it's always the last called middleware: |
||
143 | * - when the middleware pipeline reached its end (typically when the Status Code is still 102) |
||
144 | * - when one item of the middleware pipeline returns with return response (status code is set to 200|40*|500) |
||
145 | * - when during the pipeline process an Exception is thrown. |
||
146 | * |
||
147 | * When the middleware pipeline is finished the application prints the header and the output. |
||
148 | * |
||
149 | * If a middleware other than the Routing, Dispatcher and Final Middleware has no priority set, it will be |
||
150 | * considered to have priority = 50. |
||
151 | * |
||
152 | * @return void |
||
153 | */ |
||
154 | 2 | public function run() |
|
210 | } |
||
211 |