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