11<?php
2+ /**
3+ * The file contains application Kernel class.
4+ *
5+ * PHP version 5
6+ *
7+ * @category Library
8+ * @package Cherry
9+ * @author Temuri Takalandze <takalandzet@gmail.com>
10+ * @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT
11+ * @link https://github.com/ABGEO07/cherry-core
12+ */
213
314namespace Cherry ;
415
516use Cherry \Routing \Router ;
617
18+ /**
19+ * Application Kernel class.
20+ *
21+ * @category Library
22+ * @package Cherry
23+ * @author Temuri Takalandze <takalandzet@gmail.com>
24+ * @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT
25+ * @link https://github.com/ABGEO07/cherry-core
26+ */
727class Kernel
828{
929 private $ _appRoot ;
1030
1131 public $ router ;
1232 public $ logger ;
1333
34+ /**
35+ * Kernel constructor.
36+ *
37+ * @param string $appRoot Application root path.
38+ */
1439 public function __construct ($ appRoot )
1540 {
1641 define ('__ROOT__ ' , $ appRoot );
@@ -20,6 +45,11 @@ public function __construct($appRoot)
2045 $ this ->run ();
2146 }
2247
48+ /**
49+ * Run application.
50+ *
51+ * @return void
52+ */
2353 public function run ()
2454 {
2555 $ this ->_readConfig ();
@@ -28,6 +58,11 @@ public function run()
2858 $ this ->logger = new Logger ('app ' , LOGS_PATH );
2959 }
3060
61+ /**
62+ * Read config from file.
63+ *
64+ * @return array
65+ */
3166 private function _getConfig ()
3267 {
3368 $ config = file_get_contents (__ROOT__ . '/config/config.json ' )
@@ -36,6 +71,13 @@ private function _getConfig()
3671 return json_decode ($ config , 1 );
3772 }
3873
74+ /**
75+ * Check if needed keys isset in config file
76+ *
77+ * @param array $config Application Config
78+ *
79+ * @return void
80+ */
3981 private function _validateConfig (array $ config )
4082 {
4183 $ neededKeys = [
@@ -45,21 +87,26 @@ private function _validateConfig(array $config)
4587 'LOGS_PATH '
4688 ];
4789
48- foreach ($ neededKeys as $ k )
49- {
90+ foreach ($ neededKeys as $ k ) {
5091 if (!isset ($ config [$ k ])) {
5192 die ("Parameter \"{$ k }\" don't found in config file! " );
5293 }
5394 }
5495 }
5596
97+ /**
98+ * Define application config values as constants.
99+ *
100+ * @return void
101+ */
56102 private function _readConfig ()
57103 {
58104 $ config = $ this ->_getConfig ();
59105
60106 $ this ->_validateConfig ($ config );
61107
62- foreach ($ config as $ k => $ v )
108+ foreach ($ config as $ k => $ v ) {
63109 define ($ k , __ROOT__ . '/ ' . $ v );
110+ }
64111 }
65112}
0 commit comments