1 | <?php |
||
49 | class Application |
||
|
|||
50 | { |
||
51 | use Common\Helper; |
||
52 | use Common\Singleton; |
||
53 | |||
54 | /** |
||
55 | * @var string Environment name |
||
56 | */ |
||
57 | protected $environment = 'production'; |
||
58 | |||
59 | /** |
||
60 | * @var string Application path |
||
61 | */ |
||
62 | protected $path; |
||
63 | |||
64 | /** |
||
65 | * @var bool Debug application flag |
||
66 | */ |
||
67 | protected $debugFlag = false; |
||
68 | |||
69 | /** |
||
70 | * @var bool Layout usage flag |
||
71 | */ |
||
72 | protected $layoutFlag = true; |
||
73 | |||
74 | /** |
||
75 | * Get application environment |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 602 | public function getEnvironment(): string |
|
83 | |||
84 | /** |
||
85 | * Get path to Application |
||
86 | * |
||
87 | * @return string |
||
88 | * @throws \ReflectionException |
||
89 | */ |
||
90 | 602 | public function getPath(): string |
|
103 | |||
104 | /** |
||
105 | * Return Debug flag |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | 2 | public function isDebug(): bool |
|
113 | |||
114 | /** |
||
115 | * Return/setup Layout Flag |
||
116 | * |
||
117 | * @param bool|null $flag |
||
118 | * |
||
119 | * @return bool |
||
120 | */ |
||
121 | 35 | public function useLayout($flag = null): bool |
|
129 | |||
130 | /** |
||
131 | * Initialize system packages |
||
132 | * |
||
133 | * @param string $environment |
||
134 | * |
||
135 | * @throws ApplicationException |
||
136 | * @return void |
||
137 | */ |
||
138 | 602 | public function init($environment = 'production'): void |
|
173 | |||
174 | /** |
||
175 | * Initial Request instance |
||
176 | * |
||
177 | * @return void |
||
178 | * @throws \Bluz\Config\ConfigException |
||
179 | * @throws \ReflectionException |
||
180 | */ |
||
181 | 602 | protected function initConfig(): void |
|
206 | |||
207 | /** |
||
208 | * Initial Request instance |
||
209 | * |
||
210 | * @return void |
||
211 | * @throws \InvalidArgumentException |
||
212 | */ |
||
213 | 602 | protected function initRequest(): void |
|
219 | |||
220 | /** |
||
221 | * Initial Response instance |
||
222 | * |
||
223 | * @return void |
||
224 | */ |
||
225 | 602 | protected function initResponse(): void |
|
231 | |||
232 | /** |
||
233 | * Get Response instance |
||
234 | * |
||
235 | * @return \Bluz\Response\Response |
||
236 | */ |
||
237 | 3 | public function getResponse(): ResponseInstance |
|
241 | |||
242 | /** |
||
243 | * Get Request instance |
||
244 | * |
||
245 | * @return \Zend\Diactoros\ServerRequest |
||
246 | */ |
||
247 | 1 | public function getRequest(): ServerRequest |
|
251 | |||
252 | /** |
||
253 | * Initial Router instance |
||
254 | * |
||
255 | * @return void |
||
256 | */ |
||
257 | 602 | protected function initRouter(): void |
|
264 | |||
265 | /** |
||
266 | * Initial Translator instance |
||
267 | * |
||
268 | * @return void |
||
269 | * @throws Common\Exception\ConfigurationException |
||
270 | */ |
||
271 | 602 | protected function initTranslator(): void |
|
279 | |||
280 | /** |
||
281 | * Run application |
||
282 | * |
||
283 | * @return void |
||
284 | */ |
||
285 | 1 | public function run(): void |
|
291 | |||
292 | /** |
||
293 | * Process application |
||
294 | * |
||
295 | * Note: |
||
296 | * - Why you don't use "X-" prefix for custom headers? |
||
297 | * - Because it deprecated ({@link http://tools.ietf.org/html/rfc6648}) |
||
298 | * |
||
299 | * @return void |
||
300 | */ |
||
301 | 9 | public function process(): void |
|
307 | |||
308 | /** |
||
309 | * Extension point: pre process |
||
310 | * |
||
311 | * - Router processing |
||
312 | * - Analyse request headers |
||
313 | * |
||
314 | * @return void |
||
315 | */ |
||
316 | 9 | protected function preProcess(): void |
|
331 | |||
332 | /** |
||
333 | * Do process |
||
334 | * |
||
335 | * - Dispatch controller |
||
336 | * - Exceptions handling |
||
337 | * - Setup layout |
||
338 | * - Setup response body |
||
339 | * |
||
340 | * @return void |
||
341 | */ |
||
342 | protected function doProcess(): void |
||
372 | |||
373 | /** |
||
374 | * Extension point: post process |
||
375 | * |
||
376 | * @return void |
||
377 | */ |
||
378 | 9 | protected function postProcess(): void |
|
382 | |||
383 | /** |
||
384 | * Dispatch controller with params |
||
385 | * |
||
386 | * Call dispatch from any \Bluz\Package |
||
387 | * Application::getInstance()->dispatch($module, $controller, array $params); |
||
388 | * |
||
389 | * @param string $module |
||
390 | * @param string $controller |
||
391 | * @param array $params |
||
392 | * |
||
393 | * @return Controller |
||
394 | * @throws ComponentException |
||
395 | * @throws CommonException |
||
396 | * @throws ControllerException |
||
397 | * @throws ForbiddenException |
||
398 | * @throws NotAcceptableException |
||
399 | * @throws NotAllowedException |
||
400 | */ |
||
401 | 41 | public function dispatch($module, $controller, array $params = []): Controller |
|
416 | |||
417 | /** |
||
418 | * Extension point: pre dispatch |
||
419 | * |
||
420 | * @param Controller $controller |
||
421 | * |
||
422 | * @return void |
||
423 | */ |
||
424 | 41 | protected function preDispatch($controller): void |
|
435 | |||
436 | /** |
||
437 | * Do dispatch |
||
438 | * |
||
439 | * @param Controller $controller |
||
440 | * |
||
441 | * @return void |
||
442 | * @throws ComponentException |
||
443 | * @throws ControllerException |
||
444 | */ |
||
445 | 40 | protected function doDispatch($controller): void |
|
450 | |||
451 | /** |
||
452 | * Extension point: post dispatch |
||
453 | * |
||
454 | * @param Controller $controller |
||
455 | * |
||
456 | * @return void |
||
457 | */ |
||
458 | 38 | protected function postDispatch($controller): void |
|
462 | |||
463 | /** |
||
464 | * Render, is send Response |
||
465 | * |
||
466 | * @return void |
||
467 | */ |
||
468 | 1 | public function render(): void |
|
472 | |||
473 | /** |
||
474 | * Extension point: finally method |
||
475 | * |
||
476 | * @return void |
||
477 | */ |
||
478 | 1 | public function end(): void |
|
482 | } |
||
483 |