1 | <?php |
||
30 | class WebApplication implements ApplicationInterface |
||
31 | { |
||
32 | const MODULE_ADMIN = 'Admin'; |
||
33 | const MODULE_SITE = 'Website'; |
||
34 | |||
35 | /** @var DependencyInjectionAdapterInterface */ |
||
36 | private $container; |
||
37 | /** @var ConfigInterface */ |
||
38 | private $config; |
||
39 | /** @var MiddlewarePipelineInterface */ |
||
40 | private $pipeline; |
||
41 | /** @var array */ |
||
42 | private $environmentData = [ |
||
43 | 'GET' => [], |
||
44 | 'POST' => [], |
||
45 | 'SERVER' => [], |
||
46 | 'COOKIE' => [], |
||
47 | 'FILES' => [], |
||
48 | ]; |
||
49 | /** @var string */ |
||
50 | private $selectedModule = self::MODULE_SITE; |
||
51 | |||
52 | /** |
||
53 | * ApplicationInterface constructor. |
||
54 | * |
||
55 | * @param DependencyInjectionAdapterInterface $container |
||
56 | * @param ConfigInterface $config |
||
57 | * @param MiddlewarePipelineInterface $pipeline |
||
58 | */ |
||
59 | public function __construct( |
||
68 | |||
69 | /** |
||
70 | * Returns the DI Adapter instance. |
||
71 | * |
||
72 | * @return DependencyInjectionAdapterInterface |
||
73 | */ |
||
74 | public function getContainer() |
||
78 | |||
79 | /** |
||
80 | * Returns the Configuration. |
||
81 | * |
||
82 | * @return ConfigInterface |
||
83 | */ |
||
84 | public function getConfig() |
||
88 | |||
89 | /** |
||
90 | * Sets application environments according to the super globals. |
||
91 | * |
||
92 | * @param string $key |
||
93 | * @param array $data |
||
94 | * |
||
95 | * @throws InvalidArgumentException |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function setEnvironmentData($key, array $data) |
||
109 | |||
110 | /** |
||
111 | * Get ready to run the application: set final data for specific services. |
||
112 | */ |
||
113 | private function prepare() |
||
135 | |||
136 | /** |
||
137 | * Runs the application. This is where the magic happens. |
||
138 | * According tho the environment settings this must build up the middleware pipeline and execute it. |
||
139 | * |
||
140 | * a Pre-Routing Middleware can be; priority < 0: |
||
141 | * - LockCheck - check if the client IP is banned > S102|S403 |
||
142 | * - Auth - if the user is not logged in, but there's a "Remember me" cookie, then logs in > S102 |
||
143 | * |
||
144 | * Routing Middleware is fixed (RoutingMiddleware::class); priority = 0: |
||
145 | * - A middleware that routes the incoming Request and delegates to the matched middleware. > S102|S404|S405 |
||
146 | * The RouteResult should be attached to the Request. |
||
147 | * If the Routing is not defined explicitly in the pipeline, then it will be injected with priority 0. |
||
148 | * |
||
149 | * a Post-Routing Middleware can be; priority between 0 and 100: |
||
150 | * - Acl - checks if the given route is available for the client. Also checks the auth > S102|S401|S403 |
||
151 | * - CacheReader - checks if a suitable response body is cached. > S102|S200 |
||
152 | * |
||
153 | * Dispatcher Middleware is fixed (DispatcherMiddleware::class); priority = 100: |
||
154 | * - A middleware which gets the corresponding Action middleware and applies it > S102 |
||
155 | * If the Dispatcher is not defined explicitly in the pipeline, then it will be injected with priority 100. |
||
156 | * The Dispatcher should not set the response Status Code to 200 to let Post-Dispatchers to be called. |
||
157 | * |
||
158 | * a Post-Dispatch Middleware can be; priority > 100: |
||
159 | * - CacheWriter - writes response body into DataStorage (DB, File etc.) > S102 |
||
160 | * |
||
161 | * Final Middleware is fixed (FinalMiddleware:class): |
||
162 | * - This middleware behaves a bit differently. It cannot be ordered, it's always the last called middleware: |
||
163 | * - when the middleware pipeline reached its end (typically when the Status Code is still 102) |
||
164 | * - when one item of the middleware pipeline returns with return response (status code is set to 200|40*|500) |
||
165 | * - when during the pipeline process an Exception is thrown. |
||
166 | * |
||
167 | * When the middleware pipeline is finished the application prints the header and the output. |
||
168 | * |
||
169 | * If a middleware other than the Routing, Dispatcher and Final Middleware has no priority set, it will be |
||
170 | * considered to have priority = 50. |
||
171 | * |
||
172 | * @return void |
||
173 | */ |
||
174 | public function run() |
||
226 | } |
||
227 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.