1 | <?php |
||
25 | class WebApplication implements ApplicationInterface |
||
26 | { |
||
27 | const MODULE_ADMIN = 'Admin'; |
||
28 | const MODULE_SITE = 'Website'; |
||
29 | |||
30 | /** @var DependencyInjectionAdapterInterface */ |
||
31 | private $container; |
||
32 | /** @var ConfigInterface */ |
||
33 | private $config; |
||
34 | /** @var array */ |
||
35 | private $environmentData = [ |
||
36 | 'GET' => [], |
||
37 | 'POST' => [], |
||
38 | 'SERVER' => [], |
||
39 | 'COOKIE' => [], |
||
40 | 'FILES' => [], |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * ApplicationInterface constructor. |
||
45 | * |
||
46 | * @param DependencyInjectionAdapterInterface $container |
||
47 | * @param ConfigInterface $config |
||
48 | */ |
||
49 | public function __construct(DependencyInjectionAdapterInterface $container, ConfigInterface $config) |
||
54 | |||
55 | /** |
||
56 | * Returns the DI Adapter instance. |
||
57 | * |
||
58 | * @return DependencyInjectionAdapterInterface |
||
59 | */ |
||
60 | public function getContainer() |
||
64 | |||
65 | /** |
||
66 | * Returns the Configuration. |
||
67 | * |
||
68 | * @return ConfigInterface |
||
69 | */ |
||
70 | public function getConfig() |
||
74 | |||
75 | /** |
||
76 | * Sets application environments according to the super globals. |
||
77 | * |
||
78 | * @param string $key |
||
79 | * @param array $data |
||
80 | * |
||
81 | * @throws InvalidArgumentException |
||
82 | * |
||
83 | * @return $this |
||
84 | */ |
||
85 | public function setEnvironmentData($key, array $data) |
||
95 | |||
96 | /** |
||
97 | * Runs the application. This is where the magic happens. |
||
98 | * According tho the environment settings this must build up the middleware pipeline and execute it. |
||
99 | * |
||
100 | * Pre-Routing Middleware can be; priority < 0: |
||
101 | * - LockCheck - check if the client IP is banned > S102|S403 |
||
102 | * - Auth - if the user is not logged in, but there's a "Remember me" cookie, then logs in > S102 |
||
103 | * |
||
104 | * Routing Middleware is fixed; priority = 0: |
||
105 | * - A middleware that routes the incoming Request and delegates to the matched middleware. > S102|S404|S405 |
||
106 | * The RouteResult should be attached to the Request. |
||
107 | * If the Routing is not defined explicitly in the pipeline, then it will be injected with priority 0. |
||
108 | * |
||
109 | * Post-Routing Middleware can be; priority between 0 and 100: |
||
110 | * - Acl - checks if the given route is available for the client. Also checks the auth > S102|S401|S403 |
||
111 | * - CacheReader - checks if a suitable response body is cached. > S102|S200 |
||
112 | * |
||
113 | * Dispatcher Middleware is fixed; priority = 100: |
||
114 | * - A middleware which gets the corresponding Action middleware and applies it > S102|S500 |
||
115 | * If the Dispatcher is not defined explicitly in the pipeline, then it will be injected with priority 100. |
||
116 | * The Dispatcher should not set the response Status Code to 200 to let Post-Dispatchers to be called. |
||
117 | * |
||
118 | * Post-Dispatch Middleware can be; priority > 100: |
||
119 | * - CacheWriter - writes response body into DataStorage (DB, File etc.) > S102 |
||
120 | * |
||
121 | * Final Middleware is fixed: |
||
122 | * - This middleware behaves a bit differently. It cannot be ordered, it's always the last called middleware: |
||
123 | * - when the middleware pipeline reached its end (typically when the Status Code is still 102) |
||
124 | * - when one item of the middleware pipeline returns with return response (status code is set to 200|40*|500) |
||
125 | * - when during the pipeline process an Exception is thrown. |
||
126 | * |
||
127 | * When the middleware pipeline is finished the application prints the header and the output. |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | public function run() |
||
175 | } |
||
176 |