@@ -1,197 +1,197 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | 26 | |
27 | - /** |
|
28 | - * @file bootstrap.php |
|
29 | - * |
|
30 | - * Contains the loading process: loading of constants, common functions, libraries |
|
31 | - * configurations, etc |
|
32 | - * verification of the environment and the routing of the request. |
|
33 | - * |
|
34 | - * @package core |
|
35 | - * @author Tony NGUEREZA |
|
36 | - * @copyright Copyright (c) 2017 |
|
37 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
38 | - * @link http://www.iacademy.cf |
|
39 | - * @version 1.0.0 |
|
40 | - * @filesource |
|
41 | - */ |
|
27 | + /** |
|
28 | + * @file bootstrap.php |
|
29 | + * |
|
30 | + * Contains the loading process: loading of constants, common functions, libraries |
|
31 | + * configurations, etc |
|
32 | + * verification of the environment and the routing of the request. |
|
33 | + * |
|
34 | + * @package core |
|
35 | + * @author Tony NGUEREZA |
|
36 | + * @copyright Copyright (c) 2017 |
|
37 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
38 | + * @link http://www.iacademy.cf |
|
39 | + * @version 1.0.0 |
|
40 | + * @filesource |
|
41 | + */ |
|
42 | 42 | |
43 | - //if the application is running in CLI mode $_SESSION global variable is not available |
|
44 | - if(IS_CLI){ |
|
45 | - $_SESSION = array(); |
|
46 | - } |
|
43 | + //if the application is running in CLI mode $_SESSION global variable is not available |
|
44 | + if(IS_CLI){ |
|
45 | + $_SESSION = array(); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * inclusion of global constants of the environment that contain : name of the framework, |
|
50 | - * version, release date, version of PHP required, etc. |
|
51 | - */ |
|
52 | - require_once CORE_PATH . 'constants.php'; |
|
48 | + /** |
|
49 | + * inclusion of global constants of the environment that contain : name of the framework, |
|
50 | + * version, release date, version of PHP required, etc. |
|
51 | + */ |
|
52 | + require_once CORE_PATH . 'constants.php'; |
|
53 | 53 | |
54 | - /** |
|
55 | - * include file containing commons functions used in the framework such: show_error, |
|
56 | - * php_exception_handler, php_error_handler, get_instance, etc. |
|
57 | - */ |
|
58 | - require_once CORE_PATH . 'common.php'; |
|
54 | + /** |
|
55 | + * include file containing commons functions used in the framework such: show_error, |
|
56 | + * php_exception_handler, php_error_handler, get_instance, etc. |
|
57 | + */ |
|
58 | + require_once CORE_PATH . 'common.php'; |
|
59 | 59 | |
60 | - /** |
|
61 | - * The Benchmark class |
|
62 | - */ |
|
63 | - $BENCHMARK =& class_loader('Benchmark'); |
|
60 | + /** |
|
61 | + * The Benchmark class |
|
62 | + */ |
|
63 | + $BENCHMARK =& class_loader('Benchmark'); |
|
64 | 64 | |
65 | - $BENCHMARK->mark('APP_EXECUTION_START'); |
|
65 | + $BENCHMARK->mark('APP_EXECUTION_START'); |
|
66 | 66 | |
67 | - /** |
|
68 | - * instance of the Log class |
|
69 | - */ |
|
67 | + /** |
|
68 | + * instance of the Log class |
|
69 | + */ |
|
70 | 70 | $LOGGER =& class_loader('Log', 'classes'); |
71 | 71 | |
72 | 72 | $LOGGER->setLogger('ApplicationBootstrap'); |
73 | 73 | |
74 | 74 | $LOGGER->debug('Checking PHP version ...'); |
75 | 75 | |
76 | - /** |
|
77 | - * Verification of the PHP environment: minimum and maximum version |
|
78 | - */ |
|
79 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
80 | - show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
81 | - } |
|
82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
83 | - show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
84 | - } |
|
85 | - $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
76 | + /** |
|
77 | + * Verification of the PHP environment: minimum and maximum version |
|
78 | + */ |
|
79 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
80 | + show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
|
81 | + } |
|
82 | + else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
83 | + show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
|
84 | + } |
|
85 | + $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
|
86 | 86 | |
87 | - /** |
|
88 | - * Setting of the PHP error message handling function |
|
89 | - */ |
|
90 | - set_error_handler('php_error_handler'); |
|
87 | + /** |
|
88 | + * Setting of the PHP error message handling function |
|
89 | + */ |
|
90 | + set_error_handler('php_error_handler'); |
|
91 | 91 | |
92 | - /** |
|
93 | - * Setting of the PHP error exception handling function |
|
94 | - */ |
|
95 | - set_exception_handler('php_exception_handler'); |
|
92 | + /** |
|
93 | + * Setting of the PHP error exception handling function |
|
94 | + */ |
|
95 | + set_exception_handler('php_exception_handler'); |
|
96 | 96 | |
97 | - /** |
|
98 | - * Setting of the PHP shutdown handling function |
|
99 | - */ |
|
100 | - register_shutdown_function('php_shudown_handler'); |
|
97 | + /** |
|
98 | + * Setting of the PHP shutdown handling function |
|
99 | + */ |
|
100 | + register_shutdown_function('php_shudown_handler'); |
|
101 | 101 | |
102 | - //if user have some composer packages |
|
103 | - $LOGGER->debug('Check for composer autoload'); |
|
104 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
105 | - $LOGGER->info('The composer autoload file exists include it'); |
|
106 | - require_once VENDOR_PATH . 'autoload.php'; |
|
107 | - } |
|
108 | - else{ |
|
109 | - $LOGGER->info('The composer autoload file does not exist skipping'); |
|
110 | - } |
|
102 | + //if user have some composer packages |
|
103 | + $LOGGER->debug('Check for composer autoload'); |
|
104 | + if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
105 | + $LOGGER->info('The composer autoload file exists include it'); |
|
106 | + require_once VENDOR_PATH . 'autoload.php'; |
|
107 | + } |
|
108 | + else{ |
|
109 | + $LOGGER->info('The composer autoload file does not exist skipping'); |
|
110 | + } |
|
111 | 111 | |
112 | - $LOGGER->debug('Begin to load the required resources'); |
|
112 | + $LOGGER->debug('Begin to load the required resources'); |
|
113 | 113 | |
114 | - /** |
|
115 | - * Load the EventInfo class file |
|
116 | - */ |
|
117 | - require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
114 | + /** |
|
115 | + * Load the EventInfo class file |
|
116 | + */ |
|
117 | + require_once CORE_CLASSES_PATH . 'EventInfo.php'; |
|
118 | 118 | |
119 | 119 | |
120 | - $BENCHMARK->mark('CONFIG_INIT_START'); |
|
121 | - /** |
|
122 | - * Load configurations and using the |
|
123 | - * static method "init()" to initialize the Config class . |
|
124 | - */ |
|
125 | - $CONFIG =& class_loader('Config', 'classes'); |
|
126 | - $CONFIG->init(); |
|
127 | - $BENCHMARK->mark('CONFIG_INIT_END'); |
|
120 | + $BENCHMARK->mark('CONFIG_INIT_START'); |
|
121 | + /** |
|
122 | + * Load configurations and using the |
|
123 | + * static method "init()" to initialize the Config class . |
|
124 | + */ |
|
125 | + $CONFIG =& class_loader('Config', 'classes'); |
|
126 | + $CONFIG->init(); |
|
127 | + $BENCHMARK->mark('CONFIG_INIT_END'); |
|
128 | 128 | |
129 | - $BENCHMARK->mark('MODULE_INIT_START'); |
|
130 | - /** |
|
131 | - * Load modules and using the |
|
132 | - * static method "init()" to initialize the Module class. |
|
133 | - */ |
|
134 | - $MODULE =& class_loader('Module', 'classes'); |
|
135 | - $MODULE->init(); |
|
136 | - $BENCHMARK->mark('MODULE_INIT_END'); |
|
129 | + $BENCHMARK->mark('MODULE_INIT_START'); |
|
130 | + /** |
|
131 | + * Load modules and using the |
|
132 | + * static method "init()" to initialize the Module class. |
|
133 | + */ |
|
134 | + $MODULE =& class_loader('Module', 'classes'); |
|
135 | + $MODULE->init(); |
|
136 | + $BENCHMARK->mark('MODULE_INIT_END'); |
|
137 | 137 | |
138 | - $LOGGER->debug('Loading Base Controller ...'); |
|
139 | - /** |
|
140 | - * Include of the file containing the Base Controller class |
|
141 | - */ |
|
142 | - require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
143 | - $LOGGER->info('Base Controller loaded successfully'); |
|
138 | + $LOGGER->debug('Loading Base Controller ...'); |
|
139 | + /** |
|
140 | + * Include of the file containing the Base Controller class |
|
141 | + */ |
|
142 | + require_once CORE_CLASSES_PATH . 'Controller.php'; |
|
143 | + $LOGGER->info('Base Controller loaded successfully'); |
|
144 | 144 | |
145 | - /** |
|
146 | - * Register controllers autoload function |
|
147 | - */ |
|
148 | - spl_autoload_register('autoload_controller'); |
|
145 | + /** |
|
146 | + * Register controllers autoload function |
|
147 | + */ |
|
148 | + spl_autoload_register('autoload_controller'); |
|
149 | 149 | |
150 | - /** |
|
151 | - * Loading Security class |
|
152 | - */ |
|
153 | - $SECURITY =& class_loader('Security', 'classes'); |
|
154 | - $SECURITY->checkWhiteListIpAccess(); |
|
150 | + /** |
|
151 | + * Loading Security class |
|
152 | + */ |
|
153 | + $SECURITY =& class_loader('Security', 'classes'); |
|
154 | + $SECURITY->checkWhiteListIpAccess(); |
|
155 | 155 | |
156 | - /** |
|
157 | - * Loading Url class |
|
158 | - */ |
|
159 | - $URL =& class_loader('Url', 'classes'); |
|
156 | + /** |
|
157 | + * Loading Url class |
|
158 | + */ |
|
159 | + $URL =& class_loader('Url', 'classes'); |
|
160 | 160 | |
161 | - if(get_config('cache_enable', false)){ |
|
162 | - /** |
|
163 | - * Load Cache interface file |
|
164 | - */ |
|
165 | - require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
166 | - $cacheHandler = get_config('cache_handler'); |
|
167 | - if(! $cacheHandler){ |
|
168 | - show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
169 | - } |
|
170 | - $CACHE = null; |
|
171 | - //first check if the cache handler is the system driver |
|
172 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
173 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
174 | - } |
|
175 | - else{ |
|
176 | - //it's not a system driver use user library |
|
177 | - $CACHE =& class_loader($cacheHandler); |
|
178 | - } |
|
179 | - //check if the page already cached |
|
180 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
181 | - $RESPONSE = & class_loader('Response', 'classes'); |
|
182 | - if($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
183 | - return; |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
161 | + if(get_config('cache_enable', false)){ |
|
162 | + /** |
|
163 | + * Load Cache interface file |
|
164 | + */ |
|
165 | + require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
|
166 | + $cacheHandler = get_config('cache_handler'); |
|
167 | + if(! $cacheHandler){ |
|
168 | + show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
|
169 | + } |
|
170 | + $CACHE = null; |
|
171 | + //first check if the cache handler is the system driver |
|
172 | + if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
173 | + $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
174 | + } |
|
175 | + else{ |
|
176 | + //it's not a system driver use user library |
|
177 | + $CACHE =& class_loader($cacheHandler); |
|
178 | + } |
|
179 | + //check if the page already cached |
|
180 | + if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
181 | + $RESPONSE = & class_loader('Response', 'classes'); |
|
182 | + if($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
183 | + return; |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | 187 | |
188 | - //load model class |
|
189 | - require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
188 | + //load model class |
|
189 | + require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
|
190 | 190 | |
191 | - $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
192 | - /** |
|
193 | - * Routing |
|
194 | - * instantiation of the "Router" class and request processing. |
|
195 | - */ |
|
196 | - $ROUTER = & class_loader('Router', 'classes'); |
|
197 | - $ROUTER->processRequest(); |
|
191 | + $LOGGER->info('Everything is OK load Router library and dispatch the request to the corresponding controller'); |
|
192 | + /** |
|
193 | + * Routing |
|
194 | + * instantiation of the "Router" class and request processing. |
|
195 | + */ |
|
196 | + $ROUTER = & class_loader('Router', 'classes'); |
|
197 | + $ROUTER->processRequest(); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | |
43 | 43 | //if the application is running in CLI mode $_SESSION global variable is not available |
44 | - if(IS_CLI){ |
|
44 | + if (IS_CLI) { |
|
45 | 45 | $_SESSION = array(); |
46 | 46 | } |
47 | 47 | |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * The Benchmark class |
62 | 62 | */ |
63 | - $BENCHMARK =& class_loader('Benchmark'); |
|
63 | + $BENCHMARK = & class_loader('Benchmark'); |
|
64 | 64 | |
65 | 65 | $BENCHMARK->mark('APP_EXECUTION_START'); |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * instance of the Log class |
69 | 69 | */ |
70 | - $LOGGER =& class_loader('Log', 'classes'); |
|
70 | + $LOGGER = & class_loader('Log', 'classes'); |
|
71 | 71 | |
72 | 72 | $LOGGER->setLogger('ApplicationBootstrap'); |
73 | 73 | |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | /** |
77 | 77 | * Verification of the PHP environment: minimum and maximum version |
78 | 78 | */ |
79 | - if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')){ |
|
79 | + if (version_compare(phpversion(), TNH_REQUIRED_PHP_MIN_VERSION, '<')) { |
|
80 | 80 | show_error('Your PHP Version [' . phpversion() . '] is less than [' . TNH_REQUIRED_PHP_MIN_VERSION . '], please install a new version or update your PHP to the latest.', 'PHP Error environment'); |
81 | 81 | } |
82 | - else if(version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')){ |
|
82 | + else if (version_compare(phpversion(), TNH_REQUIRED_PHP_MAX_VERSION, '>')) { |
|
83 | 83 | show_error('Your PHP Version [' . phpversion() . '] is greather than [' . TNH_REQUIRED_PHP_MAX_VERSION . '] please install a PHP version that is compatible.', 'PHP Error environment'); |
84 | 84 | } |
85 | 85 | $LOGGER->info('PHP version [' . phpversion() . '] is OK [REQUIRED MINIMUM: ' . TNH_REQUIRED_PHP_MIN_VERSION . ', REQUIRED MAXIMUM: ' . TNH_REQUIRED_PHP_MAX_VERSION . '], application can work without any issue'); |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | |
102 | 102 | //if user have some composer packages |
103 | 103 | $LOGGER->debug('Check for composer autoload'); |
104 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
104 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
105 | 105 | $LOGGER->info('The composer autoload file exists include it'); |
106 | 106 | require_once VENDOR_PATH . 'autoload.php'; |
107 | 107 | } |
108 | - else{ |
|
108 | + else { |
|
109 | 109 | $LOGGER->info('The composer autoload file does not exist skipping'); |
110 | 110 | } |
111 | 111 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * Load configurations and using the |
123 | 123 | * static method "init()" to initialize the Config class . |
124 | 124 | */ |
125 | - $CONFIG =& class_loader('Config', 'classes'); |
|
125 | + $CONFIG = & class_loader('Config', 'classes'); |
|
126 | 126 | $CONFIG->init(); |
127 | 127 | $BENCHMARK->mark('CONFIG_INIT_END'); |
128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * Load modules and using the |
132 | 132 | * static method "init()" to initialize the Module class. |
133 | 133 | */ |
134 | - $MODULE =& class_loader('Module', 'classes'); |
|
134 | + $MODULE = & class_loader('Module', 'classes'); |
|
135 | 135 | $MODULE->init(); |
136 | 136 | $BENCHMARK->mark('MODULE_INIT_END'); |
137 | 137 | |
@@ -150,36 +150,36 @@ discard block |
||
150 | 150 | /** |
151 | 151 | * Loading Security class |
152 | 152 | */ |
153 | - $SECURITY =& class_loader('Security', 'classes'); |
|
153 | + $SECURITY = & class_loader('Security', 'classes'); |
|
154 | 154 | $SECURITY->checkWhiteListIpAccess(); |
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Loading Url class |
158 | 158 | */ |
159 | - $URL =& class_loader('Url', 'classes'); |
|
159 | + $URL = & class_loader('Url', 'classes'); |
|
160 | 160 | |
161 | - if(get_config('cache_enable', false)){ |
|
161 | + if (get_config('cache_enable', false)) { |
|
162 | 162 | /** |
163 | 163 | * Load Cache interface file |
164 | 164 | */ |
165 | 165 | require_once CORE_CLASSES_CACHE_PATH . 'CacheInterface.php'; |
166 | 166 | $cacheHandler = get_config('cache_handler'); |
167 | - if(! $cacheHandler){ |
|
167 | + if (!$cacheHandler) { |
|
168 | 168 | show_error('The cache feature is enabled in the configuration but the cache handler class is not set.'); |
169 | 169 | } |
170 | 170 | $CACHE = null; |
171 | 171 | //first check if the cache handler is the system driver |
172 | - if(file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')){ |
|
173 | - $CACHE =& class_loader($cacheHandler, 'classes/cache'); |
|
172 | + if (file_exists(CORE_CLASSES_CACHE_PATH . $cacheHandler . '.php')) { |
|
173 | + $CACHE = & class_loader($cacheHandler, 'classes/cache'); |
|
174 | 174 | } |
175 | - else{ |
|
175 | + else { |
|
176 | 176 | //it's not a system driver use user library |
177 | - $CACHE =& class_loader($cacheHandler); |
|
177 | + $CACHE = & class_loader($cacheHandler); |
|
178 | 178 | } |
179 | 179 | //check if the page already cached |
180 | - if(! empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get'){ |
|
180 | + if (!empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'get') { |
|
181 | 181 | $RESPONSE = & class_loader('Response', 'classes'); |
182 | - if($RESPONSE->renderFinalPageFromCache($CACHE)){ |
|
182 | + if ($RESPONSE->renderFinalPageFromCache($CACHE)) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | } |
@@ -1,32 +1,32 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | defined('ROOT_PATH') || exit('Access denied'); |
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | 26 | |
27 | 27 | class Pagination{ |
28 | 28 | |
29 | - /** |
|
29 | + /** |
|
30 | 30 | * The list of loaded config |
31 | 31 | * @var array |
32 | 32 | */ |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | if (empty($config) || ! is_array($config)){ |
50 | 50 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
51 | 51 | } |
52 | - else{ |
|
53 | - $config = array_merge($config, $overwriteConfig); |
|
54 | - $this->config = $config; |
|
52 | + else{ |
|
53 | + $config = array_merge($config, $overwriteConfig); |
|
54 | + $this->config = $config; |
|
55 | 55 | //put it gobally |
56 | - Config::setAll($config); |
|
57 | - unset($config); |
|
58 | - } |
|
56 | + Config::setAll($config); |
|
57 | + unset($config); |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | else{ |
61 | 61 | show_error('Unable to find the pagination configuration file'); |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | return $this->paginationQueryString; |
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * Set the value of the pagination query string |
|
97 | - * @param string $paginationQueryString the new value |
|
98 | - * @return object |
|
99 | - */ |
|
95 | + /** |
|
96 | + * Set the value of the pagination query string |
|
97 | + * @param string $paginationQueryString the new value |
|
98 | + * @return object |
|
99 | + */ |
|
100 | 100 | public function setPaginationQueryString($paginationQueryString){ |
101 | 101 | $this->paginationQueryString = $paginationQueryString; |
102 | 102 | return $this; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $queryString = Url::queryString(); |
114 | 114 | $currentUrl = Url::current(); |
115 | 115 | $query = ''; |
116 | - if ($queryString == ''){ |
|
116 | + if ($queryString == ''){ |
|
117 | 117 | $query = '?' . $pageQueryName . '='; |
118 | 118 | } |
119 | 119 | else{ |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function getLink($totalRows, $currentPageNumber){ |
148 | 148 | $numberOfLink = $this->config['nb_link']; |
149 | - $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
149 | + $numberOfRowPerPage = $this->config['pagination_per_page']; |
|
150 | 150 | if (empty($this->paginationQueryString)){ |
151 | 151 | //determine the pagination query string value |
152 | 152 | $this->determinePaginationQueryStringValue(); |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | $numberOfRowPerPage = (int) $numberOfRowPerPage; |
160 | 160 | |
161 | 161 | if ($currentPageNumber <= 0){ |
162 | - $currentPageNumber = 1; |
|
163 | - } |
|
162 | + $currentPageNumber = 1; |
|
163 | + } |
|
164 | 164 | if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) { |
165 | 165 | return $navbar; |
166 | 166 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber); |
186 | 186 | } |
187 | 187 | else if ($currentPageNumber == $numberOfPage){ |
188 | - $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
|
188 | + $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
|
189 | 189 | } |
190 | 190 | $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
191 | 191 | return $navbar; |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | } |
254 | 254 | } |
255 | 255 | $navbar .= $this->config['next_open'] |
256 | - . '<a href="' . $query . ($currentPageNumber + 1) . '">' |
|
257 | - . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
256 | + . '<a href="' . $query . ($currentPageNumber + 1) . '">' |
|
257 | + . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
258 | 258 | return $navbar; |
259 | 259 | } |
260 | 260 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Pagination{ |
|
27 | + class Pagination { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of loaded config |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | * Create an instance of pagination |
43 | 43 | * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php |
44 | 44 | */ |
45 | - public function __construct(array $overwriteConfig = array()){ |
|
46 | - if (file_exists(CONFIG_PATH . 'config_pagination.php')){ |
|
45 | + public function __construct(array $overwriteConfig = array()) { |
|
46 | + if (file_exists(CONFIG_PATH . 'config_pagination.php')) { |
|
47 | 47 | $config = array(); |
48 | 48 | require_once CONFIG_PATH . 'config_pagination.php'; |
49 | - if (empty($config) || ! is_array($config)){ |
|
49 | + if (empty($config) || !is_array($config)) { |
|
50 | 50 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
51 | 51 | } |
52 | - else{ |
|
52 | + else { |
|
53 | 53 | $config = array_merge($config, $overwriteConfig); |
54 | 54 | $this->config = $config; |
55 | 55 | //put it gobally |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | unset($config); |
58 | 58 | } |
59 | 59 | } |
60 | - else{ |
|
60 | + else { |
|
61 | 61 | show_error('Unable to find the pagination configuration file'); |
62 | 62 | } |
63 | 63 | } |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * config_pagination.php |
69 | 69 | * @param array $config the configuration to overwrite |
70 | 70 | */ |
71 | - public function setConfig(array $config = array()){ |
|
72 | - if (! empty($config)){ |
|
71 | + public function setConfig(array $config = array()) { |
|
72 | + if (!empty($config)) { |
|
73 | 73 | $this->config = array_merge($this->config, $config); |
74 | 74 | Config::setAll($config); |
75 | 75 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return array |
82 | 82 | */ |
83 | - public function getConfig(){ |
|
83 | + public function getConfig() { |
|
84 | 84 | return $this->config; |
85 | 85 | } |
86 | 86 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * Return the value of the pagination query string |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - public function getPaginationQueryString(){ |
|
91 | + public function getPaginationQueryString() { |
|
92 | 92 | return $this->paginationQueryString; |
93 | 93 | } |
94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param string $paginationQueryString the new value |
98 | 98 | * @return object |
99 | 99 | */ |
100 | - public function setPaginationQueryString($paginationQueryString){ |
|
100 | + public function setPaginationQueryString($paginationQueryString) { |
|
101 | 101 | $this->paginationQueryString = $paginationQueryString; |
102 | 102 | return $this; |
103 | 103 | } |
@@ -108,25 +108,25 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return object |
110 | 110 | */ |
111 | - public function determinePaginationQueryStringValue(){ |
|
111 | + public function determinePaginationQueryStringValue() { |
|
112 | 112 | $pageQueryName = $this->config['page_query_string_name']; |
113 | 113 | $queryString = Url::queryString(); |
114 | 114 | $currentUrl = Url::current(); |
115 | 115 | $query = ''; |
116 | - if ($queryString == ''){ |
|
116 | + if ($queryString == '') { |
|
117 | 117 | $query = '?' . $pageQueryName . '='; |
118 | 118 | } |
119 | - else{ |
|
119 | + else { |
|
120 | 120 | $tab = explode($pageQueryName . '=', $queryString); |
121 | 121 | $nb = count($tab); |
122 | - if ($nb == 1){ |
|
122 | + if ($nb == 1) { |
|
123 | 123 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
124 | 124 | } |
125 | - else{ |
|
126 | - if ($tab[0] == ''){ |
|
125 | + else { |
|
126 | + if ($tab[0] == '') { |
|
127 | 127 | $query = '?' . $pageQueryName . '='; |
128 | 128 | } |
129 | - else{ |
|
129 | + else { |
|
130 | 130 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
131 | 131 | } |
132 | 132 | } |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return string the pagination link |
146 | 146 | */ |
147 | - public function getLink($totalRows, $currentPageNumber){ |
|
147 | + public function getLink($totalRows, $currentPageNumber) { |
|
148 | 148 | $numberOfLink = $this->config['nb_link']; |
149 | 149 | $numberOfRowPerPage = $this->config['pagination_per_page']; |
150 | - if (empty($this->paginationQueryString)){ |
|
150 | + if (empty($this->paginationQueryString)) { |
|
151 | 151 | //determine the pagination query string value |
152 | 152 | $this->determinePaginationQueryStringValue(); |
153 | 153 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $numberOfLink = (int) $numberOfLink; |
159 | 159 | $numberOfRowPerPage = (int) $numberOfRowPerPage; |
160 | 160 | |
161 | - if ($currentPageNumber <= 0){ |
|
161 | + if ($currentPageNumber <= 0) { |
|
162 | 162 | $currentPageNumber = 1; |
163 | 163 | } |
164 | 164 | if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) { |
@@ -173,18 +173,18 @@ discard block |
||
173 | 173 | * @param int $numberOfPage the total number of page |
174 | 174 | * @return string |
175 | 175 | */ |
176 | - protected function buildPaginationNavbar($currentPageNumber, $numberOfPage){ |
|
176 | + protected function buildPaginationNavbar($currentPageNumber, $numberOfPage) { |
|
177 | 177 | $values = $this->getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage); |
178 | 178 | $begin = $values['begin']; |
179 | 179 | $end = $values['end']; |
180 | 180 | $navbar = null; |
181 | - if ($currentPageNumber == 1){ |
|
181 | + if ($currentPageNumber == 1) { |
|
182 | 182 | $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber); |
183 | 183 | } |
184 | - else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
184 | + else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) { |
|
185 | 185 | $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber); |
186 | 186 | } |
187 | - else if ($currentPageNumber == $numberOfPage){ |
|
187 | + else if ($currentPageNumber == $numberOfPage) { |
|
188 | 188 | $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
189 | 189 | } |
190 | 190 | $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
@@ -197,32 +197,32 @@ discard block |
||
197 | 197 | * @param int $numberOfPage the total number of page |
198 | 198 | * @return array the begin and end number |
199 | 199 | */ |
200 | - protected function getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage){ |
|
200 | + protected function getPaginationBeginAndEndNumber($currentPageNumber, $numberOfPage) { |
|
201 | 201 | $start = null; |
202 | 202 | $begin = null; |
203 | 203 | $end = null; |
204 | 204 | $numberOfLink = $this->config['nb_link']; |
205 | - if ($numberOfLink % 2 == 0){ |
|
205 | + if ($numberOfLink % 2 == 0) { |
|
206 | 206 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
207 | 207 | $end = $currentPageNumber + ($numberOfLink / 2); |
208 | 208 | } |
209 | - else{ |
|
209 | + else { |
|
210 | 210 | $start = $currentPageNumber - floor($numberOfLink / 2); |
211 | 211 | $end = $currentPageNumber + floor($numberOfLink / 2); |
212 | 212 | } |
213 | - if ($start <= 1){ |
|
213 | + if ($start <= 1) { |
|
214 | 214 | $begin = 1; |
215 | 215 | $end = $numberOfLink; |
216 | 216 | } |
217 | - else if ($start > 1 && $end < $numberOfPage){ |
|
217 | + else if ($start > 1 && $end < $numberOfPage) { |
|
218 | 218 | $begin = $start; |
219 | 219 | $end = $end; |
220 | 220 | } |
221 | - else{ |
|
221 | + else { |
|
222 | 222 | $begin = ($numberOfPage - $numberOfLink) + 1; |
223 | 223 | $end = $numberOfPage; |
224 | 224 | } |
225 | - if ($numberOfPage <= $numberOfLink){ |
|
225 | + if ($numberOfPage <= $numberOfLink) { |
|
226 | 226 | $begin = 1; |
227 | 227 | $end = $numberOfPage; |
228 | 228 | } |
@@ -239,14 +239,14 @@ discard block |
||
239 | 239 | * @param int $currentPageNumber the pagination current page number |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber){ |
|
242 | + protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber) { |
|
243 | 243 | $navbar = null; |
244 | 244 | $query = $this->paginationQueryString; |
245 | - for($i = $begin; $i <= $end; $i++){ |
|
246 | - if ($i == $currentPageNumber){ |
|
245 | + for ($i = $begin; $i <= $end; $i++) { |
|
246 | + if ($i == $currentPageNumber) { |
|
247 | 247 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
248 | 248 | } |
249 | - else{ |
|
249 | + else { |
|
250 | 250 | $navbar .= $this->config['digit_open'] |
251 | 251 | . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
252 | 252 | . $this->config['digit_close']; |
@@ -265,23 +265,23 @@ discard block |
||
265 | 265 | * @param int $currentPageNumber the pagination current page number |
266 | 266 | * @return string |
267 | 267 | */ |
268 | - protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber){ |
|
268 | + protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber) { |
|
269 | 269 | $navbar = null; |
270 | 270 | $query = $this->paginationQueryString; |
271 | 271 | $navbar .= $this->config['previous_open'] |
272 | 272 | . '<a href="' . $query . ($currentPageNumber - 1) . '">' |
273 | 273 | . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
274 | - for($i = $begin; $i <= $end; $i++){ |
|
275 | - if ($i == $currentPageNumber){ |
|
274 | + for ($i = $begin; $i <= $end; $i++) { |
|
275 | + if ($i == $currentPageNumber) { |
|
276 | 276 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
277 | 277 | } |
278 | - else{ |
|
278 | + else { |
|
279 | 279 | $navbar .= $this->config['digit_open'] |
280 | - . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' |
|
280 | + . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
|
281 | 281 | . $this->config['digit_close']; |
282 | 282 | } |
283 | 283 | } |
284 | - $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
284 | + $navbar .= $this->config['next_open'] . "<a href='$query" . ($currentPageNumber + 1) . "'>" . $this->config['next_text'] . "</a>" . $this->config['next_close']; |
|
285 | 285 | return $navbar; |
286 | 286 | } |
287 | 287 | |
@@ -292,19 +292,19 @@ discard block |
||
292 | 292 | * @param int $currentPageNumber the pagination current page number |
293 | 293 | * @return string |
294 | 294 | */ |
295 | - protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber){ |
|
295 | + protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber) { |
|
296 | 296 | $navbar = null; |
297 | 297 | $query = $this->paginationQueryString; |
298 | 298 | $navbar .= $this->config['previous_open'] |
299 | 299 | . '<a href="' . $query . ($currentPageNumber - 1) . '">' |
300 | 300 | . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
301 | - for($i = $begin; $i <= $end; $i++){ |
|
302 | - if ($i == $currentPageNumber){ |
|
301 | + for ($i = $begin; $i <= $end; $i++) { |
|
302 | + if ($i == $currentPageNumber) { |
|
303 | 303 | $navbar .= $this->config['active_link_open'] |
304 | 304 | . $currentPageNumber |
305 | 305 | . $this->config['active_link_close']; |
306 | 306 | } |
307 | - else{ |
|
307 | + else { |
|
308 | 308 | $navbar .= $this->config['digit_open'] |
309 | 309 | . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
310 | 310 | . $this->config['digit_close']; |
@@ -48,16 +48,14 @@ discard block |
||
48 | 48 | require_once CONFIG_PATH . 'config_pagination.php'; |
49 | 49 | if (empty($config) || ! is_array($config)){ |
50 | 50 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
51 | - } |
|
52 | - else{ |
|
51 | + } else{ |
|
53 | 52 | $config = array_merge($config, $overwriteConfig); |
54 | 53 | $this->config = $config; |
55 | 54 | //put it gobally |
56 | 55 | Config::setAll($config); |
57 | 56 | unset($config); |
58 | 57 | } |
59 | - } |
|
60 | - else{ |
|
58 | + } else{ |
|
61 | 59 | show_error('Unable to find the pagination configuration file'); |
62 | 60 | } |
63 | 61 | } |
@@ -115,18 +113,15 @@ discard block |
||
115 | 113 | $query = ''; |
116 | 114 | if ($queryString == ''){ |
117 | 115 | $query = '?' . $pageQueryName . '='; |
118 | - } |
|
119 | - else{ |
|
116 | + } else{ |
|
120 | 117 | $tab = explode($pageQueryName . '=', $queryString); |
121 | 118 | $nb = count($tab); |
122 | 119 | if ($nb == 1){ |
123 | 120 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
124 | - } |
|
125 | - else{ |
|
121 | + } else{ |
|
126 | 122 | if ($tab[0] == ''){ |
127 | 123 | $query = '?' . $pageQueryName . '='; |
128 | - } |
|
129 | - else{ |
|
124 | + } else{ |
|
130 | 125 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
131 | 126 | } |
132 | 127 | } |
@@ -180,11 +175,9 @@ discard block |
||
180 | 175 | $navbar = null; |
181 | 176 | if ($currentPageNumber == 1){ |
182 | 177 | $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber); |
183 | - } |
|
184 | - else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
178 | + } else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
185 | 179 | $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber); |
186 | - } |
|
187 | - else if ($currentPageNumber == $numberOfPage){ |
|
180 | + } else if ($currentPageNumber == $numberOfPage){ |
|
188 | 181 | $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber); |
189 | 182 | } |
190 | 183 | $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
@@ -205,20 +198,17 @@ discard block |
||
205 | 198 | if ($numberOfLink % 2 == 0){ |
206 | 199 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
207 | 200 | $end = $currentPageNumber + ($numberOfLink / 2); |
208 | - } |
|
209 | - else{ |
|
201 | + } else{ |
|
210 | 202 | $start = $currentPageNumber - floor($numberOfLink / 2); |
211 | 203 | $end = $currentPageNumber + floor($numberOfLink / 2); |
212 | 204 | } |
213 | 205 | if ($start <= 1){ |
214 | 206 | $begin = 1; |
215 | 207 | $end = $numberOfLink; |
216 | - } |
|
217 | - else if ($start > 1 && $end < $numberOfPage){ |
|
208 | + } else if ($start > 1 && $end < $numberOfPage){ |
|
218 | 209 | $begin = $start; |
219 | 210 | $end = $end; |
220 | - } |
|
221 | - else{ |
|
211 | + } else{ |
|
222 | 212 | $begin = ($numberOfPage - $numberOfLink) + 1; |
223 | 213 | $end = $numberOfPage; |
224 | 214 | } |
@@ -245,8 +235,7 @@ discard block |
||
245 | 235 | for($i = $begin; $i <= $end; $i++){ |
246 | 236 | if ($i == $currentPageNumber){ |
247 | 237 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
248 | - } |
|
249 | - else{ |
|
238 | + } else{ |
|
250 | 239 | $navbar .= $this->config['digit_open'] |
251 | 240 | . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
252 | 241 | . $this->config['digit_close']; |
@@ -274,8 +263,7 @@ discard block |
||
274 | 263 | for($i = $begin; $i <= $end; $i++){ |
275 | 264 | if ($i == $currentPageNumber){ |
276 | 265 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
277 | - } |
|
278 | - else{ |
|
266 | + } else{ |
|
279 | 267 | $navbar .= $this->config['digit_open'] |
280 | 268 | . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' |
281 | 269 | . $this->config['digit_close']; |
@@ -303,8 +291,7 @@ discard block |
||
303 | 291 | $navbar .= $this->config['active_link_open'] |
304 | 292 | . $currentPageNumber |
305 | 293 | . $this->config['active_link_close']; |
306 | - } |
|
307 | - else{ |
|
294 | + } else{ |
|
308 | 295 | $navbar .= $this->config['digit_open'] |
309 | 296 | . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' |
310 | 297 | . $this->config['digit_close']; |
@@ -1,335 +1,335 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | 26 | |
27 | - class Html{ |
|
27 | + class Html{ |
|
28 | 28 | |
29 | - /** |
|
30 | - * Generate the html anchor link |
|
31 | - * @param string $link the href attribute value |
|
32 | - * @param string $anchor the displayed anchor |
|
33 | - * @param array $attributes the additional attributes to be added |
|
34 | - * @param boolean $return whether need return the generated html or just display it directly |
|
35 | - * |
|
36 | - * @return string|void the anchor link generated html if $return is true or display it if not |
|
37 | - */ |
|
38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
39 | - $link = Url::site_url($link); |
|
40 | - if(! $anchor){ |
|
41 | - $anchor = $link; |
|
42 | - } |
|
43 | - $str = null; |
|
44 | - $str .= '<a href = "'.$link.'"'; |
|
45 | - $str .= attributes_to_string($attributes); |
|
46 | - $str .= '>'; |
|
47 | - $str .= $anchor; |
|
48 | - $str .= '</a>'; |
|
29 | + /** |
|
30 | + * Generate the html anchor link |
|
31 | + * @param string $link the href attribute value |
|
32 | + * @param string $anchor the displayed anchor |
|
33 | + * @param array $attributes the additional attributes to be added |
|
34 | + * @param boolean $return whether need return the generated html or just display it directly |
|
35 | + * |
|
36 | + * @return string|void the anchor link generated html if $return is true or display it if not |
|
37 | + */ |
|
38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
39 | + $link = Url::site_url($link); |
|
40 | + if(! $anchor){ |
|
41 | + $anchor = $link; |
|
42 | + } |
|
43 | + $str = null; |
|
44 | + $str .= '<a href = "'.$link.'"'; |
|
45 | + $str .= attributes_to_string($attributes); |
|
46 | + $str .= '>'; |
|
47 | + $str .= $anchor; |
|
48 | + $str .= '</a>'; |
|
49 | 49 | |
50 | - if($return){ |
|
51 | - return $str; |
|
52 | - } |
|
53 | - echo $str; |
|
54 | - } |
|
50 | + if($return){ |
|
51 | + return $str; |
|
52 | + } |
|
53 | + echo $str; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Generate an mailto anchor link |
|
58 | - * @param string $link the email address |
|
59 | - * @param string $anchor the displayed value of the link |
|
60 | - * @param array $attributes the additional attributes to be added |
|
61 | - * @param boolean $return whether need return the generated html or just display it directly |
|
62 | - * |
|
63 | - * @return string|void the generated html for mailto link if $return is true or display it if not |
|
64 | - */ |
|
65 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
66 | - if(! $anchor){ |
|
67 | - $anchor = $link; |
|
68 | - } |
|
69 | - $str = null; |
|
70 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
71 | - $str .= attributes_to_string($attributes); |
|
72 | - $str .= '>'; |
|
73 | - $str .= $anchor; |
|
74 | - $str .= '</a>'; |
|
56 | + /** |
|
57 | + * Generate an mailto anchor link |
|
58 | + * @param string $link the email address |
|
59 | + * @param string $anchor the displayed value of the link |
|
60 | + * @param array $attributes the additional attributes to be added |
|
61 | + * @param boolean $return whether need return the generated html or just display it directly |
|
62 | + * |
|
63 | + * @return string|void the generated html for mailto link if $return is true or display it if not |
|
64 | + */ |
|
65 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
66 | + if(! $anchor){ |
|
67 | + $anchor = $link; |
|
68 | + } |
|
69 | + $str = null; |
|
70 | + $str .= '<a href = "mailto:'.$link.'"'; |
|
71 | + $str .= attributes_to_string($attributes); |
|
72 | + $str .= '>'; |
|
73 | + $str .= $anchor; |
|
74 | + $str .= '</a>'; |
|
75 | 75 | |
76 | - if($return){ |
|
77 | - return $str; |
|
78 | - } |
|
79 | - echo $str; |
|
80 | - } |
|
76 | + if($return){ |
|
77 | + return $str; |
|
78 | + } |
|
79 | + echo $str; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Generate the html "br" tag |
|
84 | - * @param integer $nb the number of generated "<br />" tag |
|
85 | - * @param boolean $return whether need return the generated html or just display it directly |
|
86 | - * |
|
87 | - * @return string|void the generated "br" html if $return is true or display it if not |
|
88 | - */ |
|
89 | - public static function br($nb = 1, $return = true){ |
|
90 | - $nb = (int) $nb; |
|
91 | - $str = null; |
|
92 | - for ($i = 1; $i <= $nb; $i++) { |
|
93 | - $str .= '<br />'; |
|
94 | - } |
|
82 | + /** |
|
83 | + * Generate the html "br" tag |
|
84 | + * @param integer $nb the number of generated "<br />" tag |
|
85 | + * @param boolean $return whether need return the generated html or just display it directly |
|
86 | + * |
|
87 | + * @return string|void the generated "br" html if $return is true or display it if not |
|
88 | + */ |
|
89 | + public static function br($nb = 1, $return = true){ |
|
90 | + $nb = (int) $nb; |
|
91 | + $str = null; |
|
92 | + for ($i = 1; $i <= $nb; $i++) { |
|
93 | + $str .= '<br />'; |
|
94 | + } |
|
95 | 95 | |
96 | - if($return){ |
|
97 | - return $str; |
|
98 | - } |
|
99 | - echo $str; |
|
100 | - } |
|
96 | + if($return){ |
|
97 | + return $str; |
|
98 | + } |
|
99 | + echo $str; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Generate the html content for tag "hr" |
|
104 | - * @param integer $nb the number of generated "<hr />" tag |
|
105 | - * @param array $attributes the tag attributes |
|
106 | - * @param boolean $return whether need return the generated html or just display it directly |
|
107 | - * |
|
108 | - * @return string|void the generated "hr" html if $return is true or display it if not. |
|
109 | - */ |
|
110 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
111 | - $nb = (int) $nb; |
|
112 | - $str = null; |
|
113 | - for ($i = 1; $i <= $nb; $i++) { |
|
114 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
115 | - } |
|
116 | - if($return){ |
|
117 | - return $str; |
|
118 | - } |
|
119 | - echo $str; |
|
120 | - } |
|
102 | + /** |
|
103 | + * Generate the html content for tag "hr" |
|
104 | + * @param integer $nb the number of generated "<hr />" tag |
|
105 | + * @param array $attributes the tag attributes |
|
106 | + * @param boolean $return whether need return the generated html or just display it directly |
|
107 | + * |
|
108 | + * @return string|void the generated "hr" html if $return is true or display it if not. |
|
109 | + */ |
|
110 | + public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
111 | + $nb = (int) $nb; |
|
112 | + $str = null; |
|
113 | + for ($i = 1; $i <= $nb; $i++) { |
|
114 | + $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
115 | + } |
|
116 | + if($return){ |
|
117 | + return $str; |
|
118 | + } |
|
119 | + echo $str; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Generate the html content for tag like h1, h2, h3, h4, h5 and h6 |
|
124 | - * @param integer $type the tag type 1 mean h1, 2 h2, etc, |
|
125 | - * @param string $text the display text |
|
126 | - * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>" |
|
127 | - * @param array $attributes the tag attributes |
|
128 | - * @param boolean $return whether need return the generated html or just display it directly |
|
129 | - * |
|
130 | - * @return string|void the generated header html if $return is true or display it if not. |
|
131 | - */ |
|
132 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
133 | - $nb = (int) $nb; |
|
134 | - $type = (int) $type; |
|
135 | - if($type <= 0 || $type > 6){ |
|
136 | - $type = 1; |
|
137 | - } |
|
138 | - $str = null; |
|
139 | - for ($i = 1; $i <= $nb; $i++) { |
|
140 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
141 | - } |
|
142 | - if($return){ |
|
143 | - return $str; |
|
144 | - } |
|
145 | - echo $str; |
|
146 | - } |
|
122 | + /** |
|
123 | + * Generate the html content for tag like h1, h2, h3, h4, h5 and h6 |
|
124 | + * @param integer $type the tag type 1 mean h1, 2 h2, etc, |
|
125 | + * @param string $text the display text |
|
126 | + * @param integer $nb the number of generated "<h{1,2,3,4,5,6}>" |
|
127 | + * @param array $attributes the tag attributes |
|
128 | + * @param boolean $return whether need return the generated html or just display it directly |
|
129 | + * |
|
130 | + * @return string|void the generated header html if $return is true or display it if not. |
|
131 | + */ |
|
132 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
133 | + $nb = (int) $nb; |
|
134 | + $type = (int) $type; |
|
135 | + if($type <= 0 || $type > 6){ |
|
136 | + $type = 1; |
|
137 | + } |
|
138 | + $str = null; |
|
139 | + for ($i = 1; $i <= $nb; $i++) { |
|
140 | + $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
141 | + } |
|
142 | + if($return){ |
|
143 | + return $str; |
|
144 | + } |
|
145 | + echo $str; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Generate the html "ul" tag |
|
150 | - * @param array $data the data to use for each "li" tag |
|
151 | - * @param array $attributes the "ul" properties attribute use the array index below for each tag: |
|
152 | - * for ul "ul", for li "li". |
|
153 | - * @param boolean $return whether need return the generated html or just display it directly |
|
154 | - * |
|
155 | - * @return string|void the generated "ul" html if $return is true or display it if not. |
|
156 | - */ |
|
157 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
158 | - $data = (array) $data; |
|
159 | - $str = null; |
|
160 | - $ulAttributes = ''; |
|
161 | - if(! empty($attributes['ul'])){ |
|
162 | - $ulAttributes = ' ' . attributes_to_string($attributes['ul']); |
|
163 | - } |
|
164 | - $liAttributes = ''; |
|
165 | - if(! empty($attributes['li'])){ |
|
166 | - $liAttributes = ' ' . attributes_to_string($attributes['li']); |
|
167 | - } |
|
168 | - $str .= '<ul' . $ulAttributes . '>'; |
|
169 | - foreach ($data as $row) { |
|
170 | - $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
171 | - } |
|
172 | - $str .= '</ul>'; |
|
173 | - if($return){ |
|
174 | - return $str; |
|
175 | - } |
|
176 | - echo $str; |
|
177 | - } |
|
148 | + /** |
|
149 | + * Generate the html "ul" tag |
|
150 | + * @param array $data the data to use for each "li" tag |
|
151 | + * @param array $attributes the "ul" properties attribute use the array index below for each tag: |
|
152 | + * for ul "ul", for li "li". |
|
153 | + * @param boolean $return whether need return the generated html or just display it directly |
|
154 | + * |
|
155 | + * @return string|void the generated "ul" html if $return is true or display it if not. |
|
156 | + */ |
|
157 | + public static function ul($data = array(), $attributes = array(), $return = true){ |
|
158 | + $data = (array) $data; |
|
159 | + $str = null; |
|
160 | + $ulAttributes = ''; |
|
161 | + if(! empty($attributes['ul'])){ |
|
162 | + $ulAttributes = ' ' . attributes_to_string($attributes['ul']); |
|
163 | + } |
|
164 | + $liAttributes = ''; |
|
165 | + if(! empty($attributes['li'])){ |
|
166 | + $liAttributes = ' ' . attributes_to_string($attributes['li']); |
|
167 | + } |
|
168 | + $str .= '<ul' . $ulAttributes . '>'; |
|
169 | + foreach ($data as $row) { |
|
170 | + $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
171 | + } |
|
172 | + $str .= '</ul>'; |
|
173 | + if($return){ |
|
174 | + return $str; |
|
175 | + } |
|
176 | + echo $str; |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Generate the html "ol" tag |
|
181 | - * @param array $data the data to use for each "li" tag |
|
182 | - * @param array $attributes the "ol" properties attribute use the array index below for each tag: |
|
183 | - * for ol "ol", for li "li". |
|
184 | - * @param boolean $return whether need return the generated html or just display it directly |
|
185 | - * @return string|void the generated "ol" html if $return is true or display it if not. |
|
186 | - */ |
|
187 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
188 | - $data = (array) $data; |
|
189 | - $str = null; |
|
190 | - $olAttributes = ''; |
|
191 | - if(! empty($attributes['ol'])){ |
|
192 | - $olAttributes = ' ' . attributes_to_string($attributes['ol']); |
|
193 | - } |
|
194 | - $liAttributes = ''; |
|
195 | - if(! empty($attributes['li'])){ |
|
196 | - $liAttributes = ' ' . attributes_to_string($attributes['li']); |
|
197 | - } |
|
198 | - $str .= '<ol' . $olAttributes . '>'; |
|
199 | - foreach ($data as $row) { |
|
200 | - $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
201 | - } |
|
202 | - $str .= '</ol>'; |
|
203 | - if($return){ |
|
204 | - return $str; |
|
205 | - } |
|
206 | - echo $str; |
|
207 | - } |
|
179 | + /** |
|
180 | + * Generate the html "ol" tag |
|
181 | + * @param array $data the data to use for each "li" tag |
|
182 | + * @param array $attributes the "ol" properties attribute use the array index below for each tag: |
|
183 | + * for ol "ol", for li "li". |
|
184 | + * @param boolean $return whether need return the generated html or just display it directly |
|
185 | + * @return string|void the generated "ol" html if $return is true or display it if not. |
|
186 | + */ |
|
187 | + public static function ol($data = array(), $attributes = array(), $return = true){ |
|
188 | + $data = (array) $data; |
|
189 | + $str = null; |
|
190 | + $olAttributes = ''; |
|
191 | + if(! empty($attributes['ol'])){ |
|
192 | + $olAttributes = ' ' . attributes_to_string($attributes['ol']); |
|
193 | + } |
|
194 | + $liAttributes = ''; |
|
195 | + if(! empty($attributes['li'])){ |
|
196 | + $liAttributes = ' ' . attributes_to_string($attributes['li']); |
|
197 | + } |
|
198 | + $str .= '<ol' . $olAttributes . '>'; |
|
199 | + foreach ($data as $row) { |
|
200 | + $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
201 | + } |
|
202 | + $str .= '</ol>'; |
|
203 | + if($return){ |
|
204 | + return $str; |
|
205 | + } |
|
206 | + echo $str; |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Generate the html "table" tag |
|
211 | - * @param array $headers the table headers to use between (<thead>) |
|
212 | - * @param array $body the table body values between (<tbody>) |
|
213 | - * @param array $attributes the table properties attribute use the array index below for each tag: |
|
214 | - * for table "table", for thead "thead", for thead tr "thead_tr", |
|
215 | - * for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot", |
|
216 | - * for tfoot tr "tfoot_tr", for tfoot th "tfoot_th". |
|
217 | - * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values |
|
218 | - * @param boolean $return whether need return the generated html or just display it directly |
|
219 | - * @return string|void the generated "table" html if $return is true or display it if not. |
|
220 | - */ |
|
221 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
222 | - $headers = (array) $headers; |
|
223 | - $body = (array) $body; |
|
224 | - $str = null; |
|
225 | - $tableAttributes = ''; |
|
226 | - if(! empty($attributes['table'])){ |
|
227 | - $tableAttributes = ' ' . attributes_to_string($attributes['table']); |
|
228 | - } |
|
229 | - $str .= '<table' . $tableAttributes . '>'; |
|
230 | - $str .= self::buildTableHeader($headers, $attributes); |
|
231 | - $str .= self::buildTableBody($body, $attributes); |
|
209 | + /** |
|
210 | + * Generate the html "table" tag |
|
211 | + * @param array $headers the table headers to use between (<thead>) |
|
212 | + * @param array $body the table body values between (<tbody>) |
|
213 | + * @param array $attributes the table properties attribute use the array index below for each tag: |
|
214 | + * for table "table", for thead "thead", for thead tr "thead_tr", |
|
215 | + * for thead th "thead_th", for tbody "tbody", for tbody tr "tbody_tr", for tbody td "tbody_td", for tfoot "tfoot", |
|
216 | + * for tfoot tr "tfoot_tr", for tfoot th "tfoot_th". |
|
217 | + * @param boolean $use_footer whether need to generate table footer (<tfoot>) use the $headers values |
|
218 | + * @param boolean $return whether need return the generated html or just display it directly |
|
219 | + * @return string|void the generated "table" html if $return is true or display it if not. |
|
220 | + */ |
|
221 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
222 | + $headers = (array) $headers; |
|
223 | + $body = (array) $body; |
|
224 | + $str = null; |
|
225 | + $tableAttributes = ''; |
|
226 | + if(! empty($attributes['table'])){ |
|
227 | + $tableAttributes = ' ' . attributes_to_string($attributes['table']); |
|
228 | + } |
|
229 | + $str .= '<table' . $tableAttributes . '>'; |
|
230 | + $str .= self::buildTableHeader($headers, $attributes); |
|
231 | + $str .= self::buildTableBody($body, $attributes); |
|
232 | 232 | |
233 | - if($use_footer){ |
|
234 | - $str .= self::buildTableFooter($headers, $attributes); |
|
235 | - } |
|
236 | - $str .= '</table>'; |
|
237 | - if($return){ |
|
238 | - return $str; |
|
239 | - } |
|
240 | - echo $str; |
|
241 | - } |
|
233 | + if($use_footer){ |
|
234 | + $str .= self::buildTableFooter($headers, $attributes); |
|
235 | + } |
|
236 | + $str .= '</table>'; |
|
237 | + if($return){ |
|
238 | + return $str; |
|
239 | + } |
|
240 | + echo $str; |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * This method is used to build the header of the html table |
|
245 | - * @see Html::table |
|
246 | - * @return string|null |
|
247 | - */ |
|
248 | - protected static function buildTableHeader(array $headers, $attributes = array()){ |
|
249 | - $str = null; |
|
250 | - if(! empty($headers)){ |
|
251 | - $theadAttributes = ''; |
|
252 | - if(! empty($attributes['thead'])){ |
|
253 | - $theadAttributes = ' ' . attributes_to_string($attributes['thead']); |
|
254 | - } |
|
255 | - $theadtrAttributes = ''; |
|
256 | - if(! empty($attributes['thead_tr'])){ |
|
257 | - $theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']); |
|
258 | - } |
|
259 | - $thAttributes = ''; |
|
260 | - if(! empty($attributes['thead_th'])){ |
|
261 | - $thAttributes = ' ' . attributes_to_string($attributes['thead_th']); |
|
262 | - } |
|
263 | - $str .= '<thead' . $theadAttributes .'>'; |
|
264 | - $str .= '<tr' . $theadtrAttributes .'>'; |
|
265 | - foreach ($headers as $value) { |
|
266 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
267 | - } |
|
268 | - $str .= '</tr>'; |
|
269 | - $str .= '</thead>'; |
|
270 | - } |
|
271 | - return $str; |
|
272 | - } |
|
243 | + /** |
|
244 | + * This method is used to build the header of the html table |
|
245 | + * @see Html::table |
|
246 | + * @return string|null |
|
247 | + */ |
|
248 | + protected static function buildTableHeader(array $headers, $attributes = array()){ |
|
249 | + $str = null; |
|
250 | + if(! empty($headers)){ |
|
251 | + $theadAttributes = ''; |
|
252 | + if(! empty($attributes['thead'])){ |
|
253 | + $theadAttributes = ' ' . attributes_to_string($attributes['thead']); |
|
254 | + } |
|
255 | + $theadtrAttributes = ''; |
|
256 | + if(! empty($attributes['thead_tr'])){ |
|
257 | + $theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']); |
|
258 | + } |
|
259 | + $thAttributes = ''; |
|
260 | + if(! empty($attributes['thead_th'])){ |
|
261 | + $thAttributes = ' ' . attributes_to_string($attributes['thead_th']); |
|
262 | + } |
|
263 | + $str .= '<thead' . $theadAttributes .'>'; |
|
264 | + $str .= '<tr' . $theadtrAttributes .'>'; |
|
265 | + foreach ($headers as $value) { |
|
266 | + $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
267 | + } |
|
268 | + $str .= '</tr>'; |
|
269 | + $str .= '</thead>'; |
|
270 | + } |
|
271 | + return $str; |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * This method is used to build the body of the html table |
|
276 | - * @see Html::table |
|
277 | - * @return string|null |
|
278 | - */ |
|
279 | - protected static function buildTableBody(array $body, $attributes = array()){ |
|
280 | - $str = null; |
|
281 | - $tbodyAttributes = ''; |
|
282 | - if(! empty($attributes['tbody'])){ |
|
283 | - $tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']); |
|
284 | - } |
|
285 | - $tbodytrAttributes = ''; |
|
286 | - if(! empty($attributes['tbody_tr'])){ |
|
287 | - $tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']); |
|
288 | - } |
|
289 | - $tbodytdAttributes = ''; |
|
290 | - if(! empty($attributes['tbody_td'])){ |
|
291 | - $tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']); |
|
292 | - } |
|
293 | - $str .= '<tbody' . $tbodyAttributes .'>'; |
|
294 | - foreach ($body as $row) { |
|
295 | - if(is_array($row)){ |
|
296 | - $str .= '<tr' . $tbodytrAttributes .'>'; |
|
297 | - foreach ($row as $value) { |
|
298 | - $str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>'; |
|
299 | - } |
|
300 | - $str .= '</tr>'; |
|
301 | - } |
|
302 | - } |
|
303 | - $str .= '</tbody>'; |
|
304 | - return $str; |
|
305 | - } |
|
274 | + /** |
|
275 | + * This method is used to build the body of the html table |
|
276 | + * @see Html::table |
|
277 | + * @return string|null |
|
278 | + */ |
|
279 | + protected static function buildTableBody(array $body, $attributes = array()){ |
|
280 | + $str = null; |
|
281 | + $tbodyAttributes = ''; |
|
282 | + if(! empty($attributes['tbody'])){ |
|
283 | + $tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']); |
|
284 | + } |
|
285 | + $tbodytrAttributes = ''; |
|
286 | + if(! empty($attributes['tbody_tr'])){ |
|
287 | + $tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']); |
|
288 | + } |
|
289 | + $tbodytdAttributes = ''; |
|
290 | + if(! empty($attributes['tbody_td'])){ |
|
291 | + $tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']); |
|
292 | + } |
|
293 | + $str .= '<tbody' . $tbodyAttributes .'>'; |
|
294 | + foreach ($body as $row) { |
|
295 | + if(is_array($row)){ |
|
296 | + $str .= '<tr' . $tbodytrAttributes .'>'; |
|
297 | + foreach ($row as $value) { |
|
298 | + $str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>'; |
|
299 | + } |
|
300 | + $str .= '</tr>'; |
|
301 | + } |
|
302 | + } |
|
303 | + $str .= '</tbody>'; |
|
304 | + return $str; |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * This method is used to build the footer of the html table |
|
309 | - * @see Html::table |
|
310 | - * @return string|null |
|
311 | - */ |
|
312 | - protected static function buildTableFooter(array $footers, $attributes = array()){ |
|
313 | - $str = null; |
|
314 | - $tfootAttributes = ''; |
|
315 | - if(! empty($attributes['tfoot'])){ |
|
316 | - $tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']); |
|
317 | - } |
|
318 | - $tfoottrAttributes = ''; |
|
319 | - if(! empty($attributes['tfoot_tr'])){ |
|
320 | - $tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']); |
|
321 | - } |
|
322 | - $thAttributes = ''; |
|
323 | - if(! empty($attributes['tfoot_th'])){ |
|
324 | - $thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']); |
|
325 | - } |
|
326 | - $str .= '<tfoot' . $tfootAttributes .'>'; |
|
327 | - $str .= '<tr' . $tfoottrAttributes .'>'; |
|
328 | - foreach ($footers as $value) { |
|
329 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
330 | - } |
|
331 | - $str .= '</tr>'; |
|
332 | - $str .= '</tfoot>'; |
|
333 | - return $str; |
|
334 | - } |
|
335 | - } |
|
307 | + /** |
|
308 | + * This method is used to build the footer of the html table |
|
309 | + * @see Html::table |
|
310 | + * @return string|null |
|
311 | + */ |
|
312 | + protected static function buildTableFooter(array $footers, $attributes = array()){ |
|
313 | + $str = null; |
|
314 | + $tfootAttributes = ''; |
|
315 | + if(! empty($attributes['tfoot'])){ |
|
316 | + $tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']); |
|
317 | + } |
|
318 | + $tfoottrAttributes = ''; |
|
319 | + if(! empty($attributes['tfoot_tr'])){ |
|
320 | + $tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']); |
|
321 | + } |
|
322 | + $thAttributes = ''; |
|
323 | + if(! empty($attributes['tfoot_th'])){ |
|
324 | + $thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']); |
|
325 | + } |
|
326 | + $str .= '<tfoot' . $tfootAttributes .'>'; |
|
327 | + $str .= '<tr' . $tfoottrAttributes .'>'; |
|
328 | + foreach ($footers as $value) { |
|
329 | + $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
330 | + } |
|
331 | + $str .= '</tr>'; |
|
332 | + $str .= '</tfoot>'; |
|
333 | + return $str; |
|
334 | + } |
|
335 | + } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Html{ |
|
27 | + class Html { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Generate the html anchor link |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return string|void the anchor link generated html if $return is true or display it if not |
37 | 37 | */ |
38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true) { |
|
39 | 39 | $link = Url::site_url($link); |
40 | - if(! $anchor){ |
|
40 | + if (!$anchor) { |
|
41 | 41 | $anchor = $link; |
42 | 42 | } |
43 | 43 | $str = null; |
44 | - $str .= '<a href = "'.$link.'"'; |
|
44 | + $str .= '<a href = "' . $link . '"'; |
|
45 | 45 | $str .= attributes_to_string($attributes); |
46 | 46 | $str .= '>'; |
47 | 47 | $str .= $anchor; |
48 | 48 | $str .= '</a>'; |
49 | 49 | |
50 | - if($return){ |
|
50 | + if ($return) { |
|
51 | 51 | return $str; |
52 | 52 | } |
53 | 53 | echo $str; |
@@ -62,18 +62,18 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return string|void the generated html for mailto link if $return is true or display it if not |
64 | 64 | */ |
65 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
66 | - if(! $anchor){ |
|
65 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true) { |
|
66 | + if (!$anchor) { |
|
67 | 67 | $anchor = $link; |
68 | 68 | } |
69 | 69 | $str = null; |
70 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
70 | + $str .= '<a href = "mailto:' . $link . '"'; |
|
71 | 71 | $str .= attributes_to_string($attributes); |
72 | 72 | $str .= '>'; |
73 | 73 | $str .= $anchor; |
74 | 74 | $str .= '</a>'; |
75 | 75 | |
76 | - if($return){ |
|
76 | + if ($return) { |
|
77 | 77 | return $str; |
78 | 78 | } |
79 | 79 | echo $str; |
@@ -86,14 +86,14 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return string|void the generated "br" html if $return is true or display it if not |
88 | 88 | */ |
89 | - public static function br($nb = 1, $return = true){ |
|
89 | + public static function br($nb = 1, $return = true) { |
|
90 | 90 | $nb = (int) $nb; |
91 | 91 | $str = null; |
92 | 92 | for ($i = 1; $i <= $nb; $i++) { |
93 | 93 | $str .= '<br />'; |
94 | 94 | } |
95 | 95 | |
96 | - if($return){ |
|
96 | + if ($return) { |
|
97 | 97 | return $str; |
98 | 98 | } |
99 | 99 | echo $str; |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return string|void the generated "hr" html if $return is true or display it if not. |
109 | 109 | */ |
110 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
110 | + public static function hr($nb = 1, array $attributes = array(), $return = true) { |
|
111 | 111 | $nb = (int) $nb; |
112 | 112 | $str = null; |
113 | 113 | for ($i = 1; $i <= $nb; $i++) { |
114 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
114 | + $str .= '<hr' . attributes_to_string($attributes) . ' />'; |
|
115 | 115 | } |
116 | - if($return){ |
|
116 | + if ($return) { |
|
117 | 117 | return $str; |
118 | 118 | } |
119 | 119 | echo $str; |
@@ -129,17 +129,17 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return string|void the generated header html if $return is true or display it if not. |
131 | 131 | */ |
132 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
132 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true) { |
|
133 | 133 | $nb = (int) $nb; |
134 | 134 | $type = (int) $type; |
135 | - if($type <= 0 || $type > 6){ |
|
135 | + if ($type <= 0 || $type > 6) { |
|
136 | 136 | $type = 1; |
137 | 137 | } |
138 | 138 | $str = null; |
139 | 139 | for ($i = 1; $i <= $nb; $i++) { |
140 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
140 | + $str .= '<h' . $type . attributes_to_string($attributes) . '>' . $text . '</h' . $type . '>'; |
|
141 | 141 | } |
142 | - if($return){ |
|
142 | + if ($return) { |
|
143 | 143 | return $str; |
144 | 144 | } |
145 | 145 | echo $str; |
@@ -154,23 +154,23 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return string|void the generated "ul" html if $return is true or display it if not. |
156 | 156 | */ |
157 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
157 | + public static function ul($data = array(), $attributes = array(), $return = true) { |
|
158 | 158 | $data = (array) $data; |
159 | 159 | $str = null; |
160 | 160 | $ulAttributes = ''; |
161 | - if(! empty($attributes['ul'])){ |
|
161 | + if (!empty($attributes['ul'])) { |
|
162 | 162 | $ulAttributes = ' ' . attributes_to_string($attributes['ul']); |
163 | 163 | } |
164 | 164 | $liAttributes = ''; |
165 | - if(! empty($attributes['li'])){ |
|
165 | + if (!empty($attributes['li'])) { |
|
166 | 166 | $liAttributes = ' ' . attributes_to_string($attributes['li']); |
167 | 167 | } |
168 | 168 | $str .= '<ul' . $ulAttributes . '>'; |
169 | 169 | foreach ($data as $row) { |
170 | - $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
170 | + $str .= '<li' . $liAttributes . '>' . $row . '</li>'; |
|
171 | 171 | } |
172 | 172 | $str .= '</ul>'; |
173 | - if($return){ |
|
173 | + if ($return) { |
|
174 | 174 | return $str; |
175 | 175 | } |
176 | 176 | echo $str; |
@@ -184,23 +184,23 @@ discard block |
||
184 | 184 | * @param boolean $return whether need return the generated html or just display it directly |
185 | 185 | * @return string|void the generated "ol" html if $return is true or display it if not. |
186 | 186 | */ |
187 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
187 | + public static function ol($data = array(), $attributes = array(), $return = true) { |
|
188 | 188 | $data = (array) $data; |
189 | 189 | $str = null; |
190 | 190 | $olAttributes = ''; |
191 | - if(! empty($attributes['ol'])){ |
|
191 | + if (!empty($attributes['ol'])) { |
|
192 | 192 | $olAttributes = ' ' . attributes_to_string($attributes['ol']); |
193 | 193 | } |
194 | 194 | $liAttributes = ''; |
195 | - if(! empty($attributes['li'])){ |
|
195 | + if (!empty($attributes['li'])) { |
|
196 | 196 | $liAttributes = ' ' . attributes_to_string($attributes['li']); |
197 | 197 | } |
198 | 198 | $str .= '<ol' . $olAttributes . '>'; |
199 | 199 | foreach ($data as $row) { |
200 | - $str .= '<li' . $liAttributes .'>' .$row. '</li>'; |
|
200 | + $str .= '<li' . $liAttributes . '>' . $row . '</li>'; |
|
201 | 201 | } |
202 | 202 | $str .= '</ol>'; |
203 | - if($return){ |
|
203 | + if ($return) { |
|
204 | 204 | return $str; |
205 | 205 | } |
206 | 206 | echo $str; |
@@ -218,23 +218,23 @@ discard block |
||
218 | 218 | * @param boolean $return whether need return the generated html or just display it directly |
219 | 219 | * @return string|void the generated "table" html if $return is true or display it if not. |
220 | 220 | */ |
221 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
221 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true) { |
|
222 | 222 | $headers = (array) $headers; |
223 | 223 | $body = (array) $body; |
224 | 224 | $str = null; |
225 | 225 | $tableAttributes = ''; |
226 | - if(! empty($attributes['table'])){ |
|
226 | + if (!empty($attributes['table'])) { |
|
227 | 227 | $tableAttributes = ' ' . attributes_to_string($attributes['table']); |
228 | 228 | } |
229 | 229 | $str .= '<table' . $tableAttributes . '>'; |
230 | 230 | $str .= self::buildTableHeader($headers, $attributes); |
231 | 231 | $str .= self::buildTableBody($body, $attributes); |
232 | 232 | |
233 | - if($use_footer){ |
|
233 | + if ($use_footer) { |
|
234 | 234 | $str .= self::buildTableFooter($headers, $attributes); |
235 | 235 | } |
236 | 236 | $str .= '</table>'; |
237 | - if($return){ |
|
237 | + if ($return) { |
|
238 | 238 | return $str; |
239 | 239 | } |
240 | 240 | echo $str; |
@@ -245,25 +245,25 @@ discard block |
||
245 | 245 | * @see Html::table |
246 | 246 | * @return string|null |
247 | 247 | */ |
248 | - protected static function buildTableHeader(array $headers, $attributes = array()){ |
|
248 | + protected static function buildTableHeader(array $headers, $attributes = array()) { |
|
249 | 249 | $str = null; |
250 | - if(! empty($headers)){ |
|
250 | + if (!empty($headers)) { |
|
251 | 251 | $theadAttributes = ''; |
252 | - if(! empty($attributes['thead'])){ |
|
252 | + if (!empty($attributes['thead'])) { |
|
253 | 253 | $theadAttributes = ' ' . attributes_to_string($attributes['thead']); |
254 | 254 | } |
255 | 255 | $theadtrAttributes = ''; |
256 | - if(! empty($attributes['thead_tr'])){ |
|
256 | + if (!empty($attributes['thead_tr'])) { |
|
257 | 257 | $theadtrAttributes = ' ' . attributes_to_string($attributes['thead_tr']); |
258 | 258 | } |
259 | 259 | $thAttributes = ''; |
260 | - if(! empty($attributes['thead_th'])){ |
|
260 | + if (!empty($attributes['thead_th'])) { |
|
261 | 261 | $thAttributes = ' ' . attributes_to_string($attributes['thead_th']); |
262 | 262 | } |
263 | - $str .= '<thead' . $theadAttributes .'>'; |
|
264 | - $str .= '<tr' . $theadtrAttributes .'>'; |
|
263 | + $str .= '<thead' . $theadAttributes . '>'; |
|
264 | + $str .= '<tr' . $theadtrAttributes . '>'; |
|
265 | 265 | foreach ($headers as $value) { |
266 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
266 | + $str .= '<th' . $thAttributes . '>' . $value . '</th>'; |
|
267 | 267 | } |
268 | 268 | $str .= '</tr>'; |
269 | 269 | $str .= '</thead>'; |
@@ -276,26 +276,26 @@ discard block |
||
276 | 276 | * @see Html::table |
277 | 277 | * @return string|null |
278 | 278 | */ |
279 | - protected static function buildTableBody(array $body, $attributes = array()){ |
|
279 | + protected static function buildTableBody(array $body, $attributes = array()) { |
|
280 | 280 | $str = null; |
281 | 281 | $tbodyAttributes = ''; |
282 | - if(! empty($attributes['tbody'])){ |
|
282 | + if (!empty($attributes['tbody'])) { |
|
283 | 283 | $tbodyAttributes = ' ' . attributes_to_string($attributes['tbody']); |
284 | 284 | } |
285 | 285 | $tbodytrAttributes = ''; |
286 | - if(! empty($attributes['tbody_tr'])){ |
|
286 | + if (!empty($attributes['tbody_tr'])) { |
|
287 | 287 | $tbodytrAttributes = ' ' . attributes_to_string($attributes['tbody_tr']); |
288 | 288 | } |
289 | 289 | $tbodytdAttributes = ''; |
290 | - if(! empty($attributes['tbody_td'])){ |
|
290 | + if (!empty($attributes['tbody_td'])) { |
|
291 | 291 | $tbodytdAttributes = ' ' . attributes_to_string($attributes['tbody_td']); |
292 | 292 | } |
293 | - $str .= '<tbody' . $tbodyAttributes .'>'; |
|
293 | + $str .= '<tbody' . $tbodyAttributes . '>'; |
|
294 | 294 | foreach ($body as $row) { |
295 | - if(is_array($row)){ |
|
296 | - $str .= '<tr' . $tbodytrAttributes .'>'; |
|
295 | + if (is_array($row)) { |
|
296 | + $str .= '<tr' . $tbodytrAttributes . '>'; |
|
297 | 297 | foreach ($row as $value) { |
298 | - $str .= '<td' . $tbodytdAttributes .'>' .$value. '</td>'; |
|
298 | + $str .= '<td' . $tbodytdAttributes . '>' . $value . '</td>'; |
|
299 | 299 | } |
300 | 300 | $str .= '</tr>'; |
301 | 301 | } |
@@ -309,24 +309,24 @@ discard block |
||
309 | 309 | * @see Html::table |
310 | 310 | * @return string|null |
311 | 311 | */ |
312 | - protected static function buildTableFooter(array $footers, $attributes = array()){ |
|
312 | + protected static function buildTableFooter(array $footers, $attributes = array()) { |
|
313 | 313 | $str = null; |
314 | 314 | $tfootAttributes = ''; |
315 | - if(! empty($attributes['tfoot'])){ |
|
315 | + if (!empty($attributes['tfoot'])) { |
|
316 | 316 | $tfootAttributes = ' ' . attributes_to_string($attributes['tfoot']); |
317 | 317 | } |
318 | 318 | $tfoottrAttributes = ''; |
319 | - if(! empty($attributes['tfoot_tr'])){ |
|
319 | + if (!empty($attributes['tfoot_tr'])) { |
|
320 | 320 | $tfoottrAttributes = ' ' . attributes_to_string($attributes['tfoot_tr']); |
321 | 321 | } |
322 | 322 | $thAttributes = ''; |
323 | - if(! empty($attributes['tfoot_th'])){ |
|
323 | + if (!empty($attributes['tfoot_th'])) { |
|
324 | 324 | $thAttributes = ' ' . attributes_to_string($attributes['tfoot_th']); |
325 | 325 | } |
326 | - $str .= '<tfoot' . $tfootAttributes .'>'; |
|
327 | - $str .= '<tr' . $tfoottrAttributes .'>'; |
|
326 | + $str .= '<tfoot' . $tfootAttributes . '>'; |
|
327 | + $str .= '<tr' . $tfoottrAttributes . '>'; |
|
328 | 328 | foreach ($footers as $value) { |
329 | - $str .= '<th' . $thAttributes .'>' .$value. '</th>'; |
|
329 | + $str .= '<th' . $thAttributes . '>' . $value . '</th>'; |
|
330 | 330 | } |
331 | 331 | $str .= '</tr>'; |
332 | 332 | $str .= '</tfoot>'; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
3 | - /** |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | + /** |
|
4 | 4 | * TNH Framework |
5 | 5 | * |
6 | 6 | * A simple PHP framework using HMVC architecture |
@@ -22,308 +22,308 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | - */ |
|
25 | + */ |
|
26 | 26 | |
27 | - class Module{ |
|
27 | + class Module{ |
|
28 | 28 | |
29 | - /** |
|
30 | - * list of loaded module |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - private static $list = array(); |
|
29 | + /** |
|
30 | + * list of loaded module |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private static $list = array(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * logger instance |
|
37 | - * @var Log |
|
38 | - */ |
|
39 | - private static $logger; |
|
35 | + /** |
|
36 | + * logger instance |
|
37 | + * @var Log |
|
38 | + */ |
|
39 | + private static $logger; |
|
40 | 40 | |
41 | - /** |
|
42 | - * The signleton of the logger |
|
43 | - * @return Object the Log instance |
|
44 | - */ |
|
45 | - private static function getLogger(){ |
|
46 | - if(self::$logger == null){ |
|
47 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
48 | - self::$logger[0]->setLogger('Library::Module'); |
|
49 | - } |
|
50 | - return self::$logger[0]; |
|
51 | - } |
|
41 | + /** |
|
42 | + * The signleton of the logger |
|
43 | + * @return Object the Log instance |
|
44 | + */ |
|
45 | + private static function getLogger(){ |
|
46 | + if(self::$logger == null){ |
|
47 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
48 | + self::$logger[0]->setLogger('Library::Module'); |
|
49 | + } |
|
50 | + return self::$logger[0]; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Initialise the module list by scanning the directory MODULE_PATH |
|
55 | - */ |
|
56 | - public function init(){ |
|
57 | - $logger = self::getLogger(); |
|
58 | - $logger->debug('Check if the application contains the modules ...'); |
|
59 | - $moduleDir = opendir(MODULE_PATH); |
|
60 | - if(is_resource($moduleDir)){ |
|
61 | - while(($module = readdir($moduleDir)) !== false){ |
|
62 | - if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
63 | - self::$list[] = $module; |
|
64 | - } |
|
65 | - else{ |
|
66 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
67 | - } |
|
68 | - } |
|
69 | - closedir($moduleDir); |
|
70 | - } |
|
71 | - ksort(self::$list); |
|
53 | + /** |
|
54 | + * Initialise the module list by scanning the directory MODULE_PATH |
|
55 | + */ |
|
56 | + public function init(){ |
|
57 | + $logger = self::getLogger(); |
|
58 | + $logger->debug('Check if the application contains the modules ...'); |
|
59 | + $moduleDir = opendir(MODULE_PATH); |
|
60 | + if(is_resource($moduleDir)){ |
|
61 | + while(($module = readdir($moduleDir)) !== false){ |
|
62 | + if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
63 | + self::$list[] = $module; |
|
64 | + } |
|
65 | + else{ |
|
66 | + $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
67 | + } |
|
68 | + } |
|
69 | + closedir($moduleDir); |
|
70 | + } |
|
71 | + ksort(self::$list); |
|
72 | 72 | |
73 | - if(self::hasModule()){ |
|
74 | - $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
|
75 | - } |
|
76 | - } |
|
73 | + if(self::hasModule()){ |
|
74 | + $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get the list of the custom autoload configuration from module if exists |
|
80 | - * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
|
81 | - */ |
|
82 | - public static function getModulesAutoloadConfig(){ |
|
83 | - $logger = self::getLogger(); |
|
84 | - if(! self::hasModule()){ |
|
85 | - $logger->info('No module was loaded skipping.'); |
|
86 | - return false; |
|
87 | - } |
|
88 | - $autoloads = array(); |
|
89 | - $autoloads['libraries'] = array(); |
|
90 | - $autoloads['config'] = array(); |
|
91 | - $autoloads['models'] = array(); |
|
92 | - $autoloads['functions'] = array(); |
|
93 | - $autoloads['languages'] = array(); |
|
78 | + /** |
|
79 | + * Get the list of the custom autoload configuration from module if exists |
|
80 | + * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
|
81 | + */ |
|
82 | + public static function getModulesAutoloadConfig(){ |
|
83 | + $logger = self::getLogger(); |
|
84 | + if(! self::hasModule()){ |
|
85 | + $logger->info('No module was loaded skipping.'); |
|
86 | + return false; |
|
87 | + } |
|
88 | + $autoloads = array(); |
|
89 | + $autoloads['libraries'] = array(); |
|
90 | + $autoloads['config'] = array(); |
|
91 | + $autoloads['models'] = array(); |
|
92 | + $autoloads['functions'] = array(); |
|
93 | + $autoloads['languages'] = array(); |
|
94 | 94 | |
95 | - foreach (self::$list as $module) { |
|
96 | - $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
|
97 | - if(file_exists($file)){ |
|
98 | - $autoload = array(); |
|
99 | - require_once $file; |
|
100 | - if(! empty($autoload) && is_array($autoload)){ |
|
101 | - $autoloads = array_merge_recursive($autoloads, $autoload); |
|
102 | - unset($autoload); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - return $autoloads; |
|
107 | - } |
|
95 | + foreach (self::$list as $module) { |
|
96 | + $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
|
97 | + if(file_exists($file)){ |
|
98 | + $autoload = array(); |
|
99 | + require_once $file; |
|
100 | + if(! empty($autoload) && is_array($autoload)){ |
|
101 | + $autoloads = array_merge_recursive($autoloads, $autoload); |
|
102 | + unset($autoload); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + return $autoloads; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get the list of the custom routes configuration from module if exists |
|
111 | - * @return array|boolean the routes list or false if no module contains the routes configuration |
|
112 | - */ |
|
113 | - public static function getModulesRoutes(){ |
|
114 | - $logger = self::getLogger(); |
|
115 | - if(! self::hasModule()){ |
|
116 | - $logger->info('No module was loaded skipping.'); |
|
117 | - return false; |
|
118 | - } |
|
119 | - $routes = array(); |
|
120 | - foreach (self::$list as $module) { |
|
121 | - $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
|
122 | - if(file_exists($file)){ |
|
123 | - $route = array(); |
|
124 | - require_once $file; |
|
125 | - if(! empty($route) && is_array($route)){ |
|
126 | - $routes = array_merge($routes, $route); |
|
127 | - unset($route); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - return $routes; |
|
132 | - } |
|
109 | + /** |
|
110 | + * Get the list of the custom routes configuration from module if exists |
|
111 | + * @return array|boolean the routes list or false if no module contains the routes configuration |
|
112 | + */ |
|
113 | + public static function getModulesRoutes(){ |
|
114 | + $logger = self::getLogger(); |
|
115 | + if(! self::hasModule()){ |
|
116 | + $logger->info('No module was loaded skipping.'); |
|
117 | + return false; |
|
118 | + } |
|
119 | + $routes = array(); |
|
120 | + foreach (self::$list as $module) { |
|
121 | + $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
|
122 | + if(file_exists($file)){ |
|
123 | + $route = array(); |
|
124 | + require_once $file; |
|
125 | + if(! empty($route) && is_array($route)){ |
|
126 | + $routes = array_merge($routes, $route); |
|
127 | + unset($route); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + return $routes; |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * Check if in module list can have this controller |
|
137 | - * @param string $class the controller class |
|
138 | - * @param string $module the module name |
|
139 | - * @return boolean|string false or null if no module have this controller, path the full path of the controller |
|
140 | - */ |
|
141 | - public static function findControllerFullPath($class, $module = null){ |
|
142 | - $logger = self::getLogger(); |
|
143 | - if(! self::hasModule()){ |
|
144 | - $logger->info('No module was loaded skiping.'); |
|
145 | - return false; |
|
146 | - } |
|
147 | - $class = str_ireplace('.php', '', $class); |
|
148 | - $class = ucfirst($class); |
|
149 | - $classFile = $class.'.php'; |
|
150 | - $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
151 | - $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
|
152 | - if(file_exists($filePath)){ |
|
153 | - $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
154 | - return $filePath; |
|
155 | - } |
|
156 | - $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
157 | - return false; |
|
158 | - } |
|
135 | + /** |
|
136 | + * Check if in module list can have this controller |
|
137 | + * @param string $class the controller class |
|
138 | + * @param string $module the module name |
|
139 | + * @return boolean|string false or null if no module have this controller, path the full path of the controller |
|
140 | + */ |
|
141 | + public static function findControllerFullPath($class, $module = null){ |
|
142 | + $logger = self::getLogger(); |
|
143 | + if(! self::hasModule()){ |
|
144 | + $logger->info('No module was loaded skiping.'); |
|
145 | + return false; |
|
146 | + } |
|
147 | + $class = str_ireplace('.php', '', $class); |
|
148 | + $class = ucfirst($class); |
|
149 | + $classFile = $class.'.php'; |
|
150 | + $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
151 | + $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
|
152 | + if(file_exists($filePath)){ |
|
153 | + $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
154 | + return $filePath; |
|
155 | + } |
|
156 | + $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
157 | + return false; |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * Check if in module list can have this model |
|
162 | - * @param string $class the model class |
|
163 | - * @param string $module the module name |
|
164 | - * @return boolean|string false or null if no module have this model, return the full path of this model |
|
165 | - */ |
|
166 | - public static function findModelFullPath($class, $module = null){ |
|
167 | - $logger = self::getLogger(); |
|
168 | - if(! self::hasModule()){ |
|
169 | - $logger->info('No module was loaded skiping.'); |
|
170 | - return false; |
|
171 | - } |
|
172 | - $class = str_ireplace('.php', '', $class); |
|
173 | - $class = ucfirst($class); |
|
174 | - $classFile = $class.'.php'; |
|
175 | - $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
176 | - $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
|
177 | - if(file_exists($filePath)){ |
|
178 | - $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
179 | - return $filePath; |
|
180 | - } |
|
181 | - $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
182 | - return false; |
|
183 | - } |
|
160 | + /** |
|
161 | + * Check if in module list can have this model |
|
162 | + * @param string $class the model class |
|
163 | + * @param string $module the module name |
|
164 | + * @return boolean|string false or null if no module have this model, return the full path of this model |
|
165 | + */ |
|
166 | + public static function findModelFullPath($class, $module = null){ |
|
167 | + $logger = self::getLogger(); |
|
168 | + if(! self::hasModule()){ |
|
169 | + $logger->info('No module was loaded skiping.'); |
|
170 | + return false; |
|
171 | + } |
|
172 | + $class = str_ireplace('.php', '', $class); |
|
173 | + $class = ucfirst($class); |
|
174 | + $classFile = $class.'.php'; |
|
175 | + $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
176 | + $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
|
177 | + if(file_exists($filePath)){ |
|
178 | + $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
179 | + return $filePath; |
|
180 | + } |
|
181 | + $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
182 | + return false; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Check if in module list can have this config |
|
187 | - * @param string $configuration the config name |
|
188 | - * @param string $module the module name |
|
189 | - * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
|
190 | - */ |
|
191 | - public static function findConfigFullPath($configuration, $module = null){ |
|
192 | - $logger = self::getLogger(); |
|
193 | - if(! self::hasModule()){ |
|
194 | - $logger->info('No module was loaded skiping.'); |
|
195 | - return false; |
|
196 | - } |
|
197 | - $configuration = str_ireplace('.php', '', $configuration); |
|
198 | - $file = $configuration.'.php'; |
|
199 | - $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
200 | - $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
|
201 | - if(file_exists($filePath)){ |
|
202 | - $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
203 | - return $filePath; |
|
204 | - } |
|
205 | - $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
206 | - return false; |
|
207 | - } |
|
185 | + /** |
|
186 | + * Check if in module list can have this config |
|
187 | + * @param string $configuration the config name |
|
188 | + * @param string $module the module name |
|
189 | + * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
|
190 | + */ |
|
191 | + public static function findConfigFullPath($configuration, $module = null){ |
|
192 | + $logger = self::getLogger(); |
|
193 | + if(! self::hasModule()){ |
|
194 | + $logger->info('No module was loaded skiping.'); |
|
195 | + return false; |
|
196 | + } |
|
197 | + $configuration = str_ireplace('.php', '', $configuration); |
|
198 | + $file = $configuration.'.php'; |
|
199 | + $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
200 | + $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
|
201 | + if(file_exists($filePath)){ |
|
202 | + $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
203 | + return $filePath; |
|
204 | + } |
|
205 | + $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
206 | + return false; |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Check if in module list can have this helper |
|
211 | - * @param string $helper the helper name |
|
212 | - * @param string $module the module name |
|
213 | - * @return boolean|string false or null if no module have this helper, return the full path of this helper |
|
214 | - */ |
|
215 | - public static function findFunctionFullPath($helper, $module = null){ |
|
216 | - $logger = self::getLogger(); |
|
217 | - if(! self::hasModule()){ |
|
218 | - $logger->info('No module was loaded skiping.'); |
|
219 | - return false; |
|
220 | - } |
|
221 | - $helper = str_ireplace('.php', '', $helper); |
|
222 | - $helper = str_ireplace('function_', '', $helper); |
|
223 | - $file = 'function_'.$helper.'.php'; |
|
224 | - $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
225 | - $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
|
226 | - if(file_exists($filePath)){ |
|
227 | - $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
228 | - return $filePath; |
|
229 | - } |
|
230 | - $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
231 | - return false; |
|
209 | + /** |
|
210 | + * Check if in module list can have this helper |
|
211 | + * @param string $helper the helper name |
|
212 | + * @param string $module the module name |
|
213 | + * @return boolean|string false or null if no module have this helper, return the full path of this helper |
|
214 | + */ |
|
215 | + public static function findFunctionFullPath($helper, $module = null){ |
|
216 | + $logger = self::getLogger(); |
|
217 | + if(! self::hasModule()){ |
|
218 | + $logger->info('No module was loaded skiping.'); |
|
219 | + return false; |
|
220 | + } |
|
221 | + $helper = str_ireplace('.php', '', $helper); |
|
222 | + $helper = str_ireplace('function_', '', $helper); |
|
223 | + $file = 'function_'.$helper.'.php'; |
|
224 | + $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
225 | + $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
|
226 | + if(file_exists($filePath)){ |
|
227 | + $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
228 | + return $filePath; |
|
229 | + } |
|
230 | + $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
231 | + return false; |
|
232 | 232 | |
233 | - } |
|
233 | + } |
|
234 | 234 | |
235 | 235 | |
236 | - /** |
|
237 | - * Check if in module list can have this library |
|
238 | - * @param string $class the library name |
|
239 | - * @param string $module the module name |
|
240 | - * @return boolean|string false or null if no module have this library, return the full path of this library |
|
241 | - */ |
|
242 | - public static function findLibraryFullPath($class, $module = null){ |
|
243 | - $logger = self::getLogger(); |
|
244 | - if(! self::hasModule()){ |
|
245 | - $logger->info('No module was loaded skiping.'); |
|
246 | - return false; |
|
247 | - } |
|
248 | - $class = str_ireplace('.php', '', $class); |
|
249 | - $file = $class.'.php'; |
|
250 | - $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
251 | - $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
|
252 | - if(file_exists($filePath)){ |
|
253 | - $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
254 | - return $filePath; |
|
255 | - } |
|
256 | - $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
257 | - return false; |
|
258 | - } |
|
236 | + /** |
|
237 | + * Check if in module list can have this library |
|
238 | + * @param string $class the library name |
|
239 | + * @param string $module the module name |
|
240 | + * @return boolean|string false or null if no module have this library, return the full path of this library |
|
241 | + */ |
|
242 | + public static function findLibraryFullPath($class, $module = null){ |
|
243 | + $logger = self::getLogger(); |
|
244 | + if(! self::hasModule()){ |
|
245 | + $logger->info('No module was loaded skiping.'); |
|
246 | + return false; |
|
247 | + } |
|
248 | + $class = str_ireplace('.php', '', $class); |
|
249 | + $file = $class.'.php'; |
|
250 | + $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
251 | + $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
|
252 | + if(file_exists($filePath)){ |
|
253 | + $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
254 | + return $filePath; |
|
255 | + } |
|
256 | + $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
257 | + return false; |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * Check if in module list can have this view |
|
263 | - * @param string $view the view path |
|
264 | - * @param string $module the module name to check |
|
265 | - * @return boolean|string false or null if no module have this view, path the full path of the view |
|
266 | - */ |
|
267 | - public static function findViewFullPath($view, $module = null){ |
|
268 | - $logger = self::getLogger(); |
|
269 | - if(! self::hasModule()){ |
|
270 | - $logger->info('No module was loaded skiping.'); |
|
271 | - return false; |
|
272 | - } |
|
273 | - $view = str_ireplace('.php', '', $view); |
|
274 | - $view = trim($view, '/\\'); |
|
275 | - $view = str_ireplace('/', DS, $view); |
|
276 | - $viewFile = $view . '.php'; |
|
277 | - $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
278 | - $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
|
279 | - if(file_exists($filePath)){ |
|
280 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
281 | - return $filePath; |
|
282 | - } |
|
283 | - $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
284 | - return false; |
|
285 | - } |
|
261 | + /** |
|
262 | + * Check if in module list can have this view |
|
263 | + * @param string $view the view path |
|
264 | + * @param string $module the module name to check |
|
265 | + * @return boolean|string false or null if no module have this view, path the full path of the view |
|
266 | + */ |
|
267 | + public static function findViewFullPath($view, $module = null){ |
|
268 | + $logger = self::getLogger(); |
|
269 | + if(! self::hasModule()){ |
|
270 | + $logger->info('No module was loaded skiping.'); |
|
271 | + return false; |
|
272 | + } |
|
273 | + $view = str_ireplace('.php', '', $view); |
|
274 | + $view = trim($view, '/\\'); |
|
275 | + $view = str_ireplace('/', DS, $view); |
|
276 | + $viewFile = $view . '.php'; |
|
277 | + $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
278 | + $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
|
279 | + if(file_exists($filePath)){ |
|
280 | + $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
281 | + return $filePath; |
|
282 | + } |
|
283 | + $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
284 | + return false; |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * Check if in module list can have this language |
|
289 | - * @param string $language the language name |
|
290 | - * @param string $module the module name |
|
291 | - * @param string $appLang the application language like 'en', 'fr' |
|
292 | - * @return boolean|string false or null if no module have this language, return the full path of this language |
|
293 | - */ |
|
294 | - public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
295 | - $logger = self::getLogger(); |
|
296 | - if(! self::hasModule()){ |
|
297 | - $logger->info('No module was loaded skiping.'); |
|
298 | - return false; |
|
299 | - } |
|
300 | - $language = str_ireplace('.php', '', $language); |
|
301 | - $language = str_ireplace('lang_', '', $language); |
|
302 | - $file = 'lang_'.$language.'.php'; |
|
303 | - $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
304 | - $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
|
305 | - if(file_exists($filePath)){ |
|
306 | - $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
307 | - return $filePath; |
|
308 | - } |
|
309 | - $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
310 | - return false; |
|
311 | - } |
|
287 | + /** |
|
288 | + * Check if in module list can have this language |
|
289 | + * @param string $language the language name |
|
290 | + * @param string $module the module name |
|
291 | + * @param string $appLang the application language like 'en', 'fr' |
|
292 | + * @return boolean|string false or null if no module have this language, return the full path of this language |
|
293 | + */ |
|
294 | + public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
295 | + $logger = self::getLogger(); |
|
296 | + if(! self::hasModule()){ |
|
297 | + $logger->info('No module was loaded skiping.'); |
|
298 | + return false; |
|
299 | + } |
|
300 | + $language = str_ireplace('.php', '', $language); |
|
301 | + $language = str_ireplace('lang_', '', $language); |
|
302 | + $file = 'lang_'.$language.'.php'; |
|
303 | + $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
304 | + $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
|
305 | + if(file_exists($filePath)){ |
|
306 | + $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
307 | + return $filePath; |
|
308 | + } |
|
309 | + $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
310 | + return false; |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * Get the list of module loaded |
|
315 | - * @return array the module list |
|
316 | - */ |
|
317 | - public static function getModuleList(){ |
|
318 | - return self::$list; |
|
319 | - } |
|
313 | + /** |
|
314 | + * Get the list of module loaded |
|
315 | + * @return array the module list |
|
316 | + */ |
|
317 | + public static function getModuleList(){ |
|
318 | + return self::$list; |
|
319 | + } |
|
320 | 320 | |
321 | - /** |
|
322 | - * Check if the application has an module |
|
323 | - * @return boolean |
|
324 | - */ |
|
325 | - public static function hasModule(){ |
|
326 | - return !empty(self::$list); |
|
327 | - } |
|
321 | + /** |
|
322 | + * Check if the application has an module |
|
323 | + * @return boolean |
|
324 | + */ |
|
325 | + public static function hasModule(){ |
|
326 | + return !empty(self::$list); |
|
327 | + } |
|
328 | 328 | |
329 | - } |
|
329 | + } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Module{ |
|
27 | + class Module { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * list of loaded module |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * The signleton of the logger |
43 | 43 | * @return Object the Log instance |
44 | 44 | */ |
45 | - private static function getLogger(){ |
|
46 | - if(self::$logger == null){ |
|
47 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
45 | + private static function getLogger() { |
|
46 | + if (self::$logger == null) { |
|
47 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
48 | 48 | self::$logger[0]->setLogger('Library::Module'); |
49 | 49 | } |
50 | 50 | return self::$logger[0]; |
@@ -53,24 +53,24 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * Initialise the module list by scanning the directory MODULE_PATH |
55 | 55 | */ |
56 | - public function init(){ |
|
56 | + public function init() { |
|
57 | 57 | $logger = self::getLogger(); |
58 | 58 | $logger->debug('Check if the application contains the modules ...'); |
59 | 59 | $moduleDir = opendir(MODULE_PATH); |
60 | - if(is_resource($moduleDir)){ |
|
61 | - while(($module = readdir($moduleDir)) !== false){ |
|
62 | - if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
60 | + if (is_resource($moduleDir)) { |
|
61 | + while (($module = readdir($moduleDir)) !== false) { |
|
62 | + if (preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) { |
|
63 | 63 | self::$list[] = $module; |
64 | 64 | } |
65 | - else{ |
|
66 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
65 | + else { |
|
66 | + $logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name'); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | closedir($moduleDir); |
70 | 70 | } |
71 | 71 | ksort(self::$list); |
72 | 72 | |
73 | - if(self::hasModule()){ |
|
73 | + if (self::hasModule()) { |
|
74 | 74 | $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
75 | 75 | } |
76 | 76 | } |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * Get the list of the custom autoload configuration from module if exists |
80 | 80 | * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
81 | 81 | */ |
82 | - public static function getModulesAutoloadConfig(){ |
|
82 | + public static function getModulesAutoloadConfig() { |
|
83 | 83 | $logger = self::getLogger(); |
84 | - if(! self::hasModule()){ |
|
84 | + if (!self::hasModule()) { |
|
85 | 85 | $logger->info('No module was loaded skipping.'); |
86 | 86 | return false; |
87 | 87 | } |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | |
95 | 95 | foreach (self::$list as $module) { |
96 | 96 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
97 | - if(file_exists($file)){ |
|
97 | + if (file_exists($file)) { |
|
98 | 98 | $autoload = array(); |
99 | 99 | require_once $file; |
100 | - if(! empty($autoload) && is_array($autoload)){ |
|
100 | + if (!empty($autoload) && is_array($autoload)) { |
|
101 | 101 | $autoloads = array_merge_recursive($autoloads, $autoload); |
102 | 102 | unset($autoload); |
103 | 103 | } |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * Get the list of the custom routes configuration from module if exists |
111 | 111 | * @return array|boolean the routes list or false if no module contains the routes configuration |
112 | 112 | */ |
113 | - public static function getModulesRoutes(){ |
|
113 | + public static function getModulesRoutes() { |
|
114 | 114 | $logger = self::getLogger(); |
115 | - if(! self::hasModule()){ |
|
115 | + if (!self::hasModule()) { |
|
116 | 116 | $logger->info('No module was loaded skipping.'); |
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | $routes = array(); |
120 | 120 | foreach (self::$list as $module) { |
121 | 121 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
122 | - if(file_exists($file)){ |
|
122 | + if (file_exists($file)) { |
|
123 | 123 | $route = array(); |
124 | 124 | require_once $file; |
125 | - if(! empty($route) && is_array($route)){ |
|
125 | + if (!empty($route) && is_array($route)) { |
|
126 | 126 | $routes = array_merge($routes, $route); |
127 | 127 | unset($route); |
128 | 128 | } |
@@ -138,22 +138,22 @@ discard block |
||
138 | 138 | * @param string $module the module name |
139 | 139 | * @return boolean|string false or null if no module have this controller, path the full path of the controller |
140 | 140 | */ |
141 | - public static function findControllerFullPath($class, $module = null){ |
|
141 | + public static function findControllerFullPath($class, $module = null) { |
|
142 | 142 | $logger = self::getLogger(); |
143 | - if(! self::hasModule()){ |
|
143 | + if (!self::hasModule()) { |
|
144 | 144 | $logger->info('No module was loaded skiping.'); |
145 | 145 | return false; |
146 | 146 | } |
147 | 147 | $class = str_ireplace('.php', '', $class); |
148 | 148 | $class = ucfirst($class); |
149 | - $classFile = $class.'.php'; |
|
150 | - $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
149 | + $classFile = $class . '.php'; |
|
150 | + $logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...'); |
|
151 | 151 | $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
152 | - if(file_exists($filePath)){ |
|
153 | - $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
152 | + if (file_exists($filePath)) { |
|
153 | + $logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
154 | 154 | return $filePath; |
155 | 155 | } |
156 | - $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
156 | + $logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']'); |
|
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | |
@@ -163,22 +163,22 @@ discard block |
||
163 | 163 | * @param string $module the module name |
164 | 164 | * @return boolean|string false or null if no module have this model, return the full path of this model |
165 | 165 | */ |
166 | - public static function findModelFullPath($class, $module = null){ |
|
166 | + public static function findModelFullPath($class, $module = null) { |
|
167 | 167 | $logger = self::getLogger(); |
168 | - if(! self::hasModule()){ |
|
168 | + if (!self::hasModule()) { |
|
169 | 169 | $logger->info('No module was loaded skiping.'); |
170 | 170 | return false; |
171 | 171 | } |
172 | 172 | $class = str_ireplace('.php', '', $class); |
173 | 173 | $class = ucfirst($class); |
174 | - $classFile = $class.'.php'; |
|
175 | - $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
174 | + $classFile = $class . '.php'; |
|
175 | + $logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...'); |
|
176 | 176 | $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
177 | - if(file_exists($filePath)){ |
|
178 | - $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
177 | + if (file_exists($filePath)) { |
|
178 | + $logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
179 | 179 | return $filePath; |
180 | 180 | } |
181 | - $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
181 | + $logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']'); |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
@@ -188,21 +188,21 @@ discard block |
||
188 | 188 | * @param string $module the module name |
189 | 189 | * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
190 | 190 | */ |
191 | - public static function findConfigFullPath($configuration, $module = null){ |
|
191 | + public static function findConfigFullPath($configuration, $module = null) { |
|
192 | 192 | $logger = self::getLogger(); |
193 | - if(! self::hasModule()){ |
|
193 | + if (!self::hasModule()) { |
|
194 | 194 | $logger->info('No module was loaded skiping.'); |
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | $configuration = str_ireplace('.php', '', $configuration); |
198 | - $file = $configuration.'.php'; |
|
199 | - $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
198 | + $file = $configuration . '.php'; |
|
199 | + $logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...'); |
|
200 | 200 | $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
201 | - if(file_exists($filePath)){ |
|
202 | - $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
201 | + if (file_exists($filePath)) { |
|
202 | + $logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
203 | 203 | return $filePath; |
204 | 204 | } |
205 | - $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
205 | + $logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']'); |
|
206 | 206 | return false; |
207 | 207 | } |
208 | 208 | |
@@ -212,22 +212,22 @@ discard block |
||
212 | 212 | * @param string $module the module name |
213 | 213 | * @return boolean|string false or null if no module have this helper, return the full path of this helper |
214 | 214 | */ |
215 | - public static function findFunctionFullPath($helper, $module = null){ |
|
215 | + public static function findFunctionFullPath($helper, $module = null) { |
|
216 | 216 | $logger = self::getLogger(); |
217 | - if(! self::hasModule()){ |
|
217 | + if (!self::hasModule()) { |
|
218 | 218 | $logger->info('No module was loaded skiping.'); |
219 | 219 | return false; |
220 | 220 | } |
221 | 221 | $helper = str_ireplace('.php', '', $helper); |
222 | 222 | $helper = str_ireplace('function_', '', $helper); |
223 | - $file = 'function_'.$helper.'.php'; |
|
224 | - $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
223 | + $file = 'function_' . $helper . '.php'; |
|
224 | + $logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...'); |
|
225 | 225 | $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
226 | - if(file_exists($filePath)){ |
|
227 | - $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
226 | + if (file_exists($filePath)) { |
|
227 | + $logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
228 | 228 | return $filePath; |
229 | 229 | } |
230 | - $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
230 | + $logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']'); |
|
231 | 231 | return false; |
232 | 232 | |
233 | 233 | } |
@@ -239,21 +239,21 @@ discard block |
||
239 | 239 | * @param string $module the module name |
240 | 240 | * @return boolean|string false or null if no module have this library, return the full path of this library |
241 | 241 | */ |
242 | - public static function findLibraryFullPath($class, $module = null){ |
|
242 | + public static function findLibraryFullPath($class, $module = null) { |
|
243 | 243 | $logger = self::getLogger(); |
244 | - if(! self::hasModule()){ |
|
244 | + if (!self::hasModule()) { |
|
245 | 245 | $logger->info('No module was loaded skiping.'); |
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | $class = str_ireplace('.php', '', $class); |
249 | - $file = $class.'.php'; |
|
250 | - $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
249 | + $file = $class . '.php'; |
|
250 | + $logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...'); |
|
251 | 251 | $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
252 | - if(file_exists($filePath)){ |
|
253 | - $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
252 | + if (file_exists($filePath)) { |
|
253 | + $logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
254 | 254 | return $filePath; |
255 | 255 | } |
256 | - $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
256 | + $logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']'); |
|
257 | 257 | return false; |
258 | 258 | } |
259 | 259 | |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | * @param string $module the module name to check |
265 | 265 | * @return boolean|string false or null if no module have this view, path the full path of the view |
266 | 266 | */ |
267 | - public static function findViewFullPath($view, $module = null){ |
|
267 | + public static function findViewFullPath($view, $module = null) { |
|
268 | 268 | $logger = self::getLogger(); |
269 | - if(! self::hasModule()){ |
|
269 | + if (!self::hasModule()) { |
|
270 | 270 | $logger->info('No module was loaded skiping.'); |
271 | 271 | return false; |
272 | 272 | } |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | $view = trim($view, '/\\'); |
275 | 275 | $view = str_ireplace('/', DS, $view); |
276 | 276 | $viewFile = $view . '.php'; |
277 | - $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
277 | + $logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...'); |
|
278 | 278 | $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
279 | - if(file_exists($filePath)){ |
|
280 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
279 | + if (file_exists($filePath)) { |
|
280 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
281 | 281 | return $filePath; |
282 | 282 | } |
283 | - $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
283 | + $logger->info('View [' . $view . '] does not exist in the module [' . $module . ']'); |
|
284 | 284 | return false; |
285 | 285 | } |
286 | 286 | |
@@ -291,22 +291,22 @@ discard block |
||
291 | 291 | * @param string $appLang the application language like 'en', 'fr' |
292 | 292 | * @return boolean|string false or null if no module have this language, return the full path of this language |
293 | 293 | */ |
294 | - public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
294 | + public static function findLanguageFullPath($language, $module = null, $appLang) { |
|
295 | 295 | $logger = self::getLogger(); |
296 | - if(! self::hasModule()){ |
|
296 | + if (!self::hasModule()) { |
|
297 | 297 | $logger->info('No module was loaded skiping.'); |
298 | 298 | return false; |
299 | 299 | } |
300 | 300 | $language = str_ireplace('.php', '', $language); |
301 | 301 | $language = str_ireplace('lang_', '', $language); |
302 | - $file = 'lang_'.$language.'.php'; |
|
303 | - $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
302 | + $file = 'lang_' . $language . '.php'; |
|
303 | + $logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...'); |
|
304 | 304 | $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
305 | - if(file_exists($filePath)){ |
|
306 | - $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
305 | + if (file_exists($filePath)) { |
|
306 | + $logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
307 | 307 | return $filePath; |
308 | 308 | } |
309 | - $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
309 | + $logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']'); |
|
310 | 310 | return false; |
311 | 311 | } |
312 | 312 | |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * Get the list of module loaded |
315 | 315 | * @return array the module list |
316 | 316 | */ |
317 | - public static function getModuleList(){ |
|
317 | + public static function getModuleList() { |
|
318 | 318 | return self::$list; |
319 | 319 | } |
320 | 320 | |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * Check if the application has an module |
323 | 323 | * @return boolean |
324 | 324 | */ |
325 | - public static function hasModule(){ |
|
325 | + public static function hasModule() { |
|
326 | 326 | return !empty(self::$list); |
327 | 327 | } |
328 | 328 |
@@ -61,8 +61,7 @@ |
||
61 | 61 | while(($module = readdir($moduleDir)) !== false){ |
62 | 62 | if(preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
63 | 63 | self::$list[] = $module; |
64 | - } |
|
65 | - else{ |
|
64 | + } else{ |
|
66 | 65 | $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
67 | 66 | } |
68 | 67 | } |
@@ -1,190 +1,190 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | 26 | |
27 | - class Config{ |
|
27 | + class Config{ |
|
28 | 28 | |
29 | - /** |
|
30 | - * The list of loaded configuration |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - private static $config = array(); |
|
29 | + /** |
|
30 | + * The list of loaded configuration |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private static $config = array(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * The logger instance |
|
37 | - * @var object |
|
38 | - */ |
|
39 | - private static $logger; |
|
35 | + /** |
|
36 | + * The logger instance |
|
37 | + * @var object |
|
38 | + */ |
|
39 | + private static $logger; |
|
40 | 40 | |
41 | - /** |
|
42 | - * The signleton of the logger |
|
43 | - * @return Object the Log instance |
|
44 | - */ |
|
45 | - public static function getLogger(){ |
|
46 | - if(self::$logger == null){ |
|
47 | - $logger = array(); |
|
48 | - $logger[0] =& class_loader('Log', 'classes'); |
|
49 | - $logger[0]->setLogger('Library::Config'); |
|
50 | - self::$logger = $logger[0]; |
|
51 | - } |
|
52 | - return self::$logger; |
|
53 | - } |
|
41 | + /** |
|
42 | + * The signleton of the logger |
|
43 | + * @return Object the Log instance |
|
44 | + */ |
|
45 | + public static function getLogger(){ |
|
46 | + if(self::$logger == null){ |
|
47 | + $logger = array(); |
|
48 | + $logger[0] =& class_loader('Log', 'classes'); |
|
49 | + $logger[0]->setLogger('Library::Config'); |
|
50 | + self::$logger = $logger[0]; |
|
51 | + } |
|
52 | + return self::$logger; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Set the log instance for future use |
|
57 | - * @param object $logger the log object |
|
58 | - * @return object the log instance |
|
59 | - */ |
|
60 | - public static function setLogger($logger){ |
|
61 | - self::$logger = $logger; |
|
62 | - return self::$logger; |
|
63 | - } |
|
55 | + /** |
|
56 | + * Set the log instance for future use |
|
57 | + * @param object $logger the log object |
|
58 | + * @return object the log instance |
|
59 | + */ |
|
60 | + public static function setLogger($logger){ |
|
61 | + self::$logger = $logger; |
|
62 | + return self::$logger; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Initialize the configuration by loading all the configuration from config file |
|
67 | - */ |
|
68 | - public static function init(){ |
|
69 | - $logger = static::getLogger(); |
|
70 | - $logger->debug('Initialization of the configuration'); |
|
71 | - self::$config = & load_configurations(); |
|
72 | - self::setBaseUrlUsingServerVar(); |
|
73 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
74 | - $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
75 | - } |
|
76 | - $logger->info('Configuration initialized successfully'); |
|
77 | - $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
78 | - } |
|
65 | + /** |
|
66 | + * Initialize the configuration by loading all the configuration from config file |
|
67 | + */ |
|
68 | + public static function init(){ |
|
69 | + $logger = static::getLogger(); |
|
70 | + $logger->debug('Initialization of the configuration'); |
|
71 | + self::$config = & load_configurations(); |
|
72 | + self::setBaseUrlUsingServerVar(); |
|
73 | + if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
74 | + $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
75 | + } |
|
76 | + $logger->info('Configuration initialized successfully'); |
|
77 | + $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get the configuration item value |
|
82 | - * @param string $item the configuration item name to get |
|
83 | - * @param mixed $default the default value to use if can not find the config item in the list |
|
84 | - * @return mixed the config value if exist or the default value |
|
85 | - */ |
|
86 | - public static function get($item, $default = null){ |
|
87 | - $logger = static::getLogger(); |
|
88 | - if(array_key_exists($item, self::$config)){ |
|
89 | - return self::$config[$item]; |
|
90 | - } |
|
91 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
92 | - return $default; |
|
93 | - } |
|
80 | + /** |
|
81 | + * Get the configuration item value |
|
82 | + * @param string $item the configuration item name to get |
|
83 | + * @param mixed $default the default value to use if can not find the config item in the list |
|
84 | + * @return mixed the config value if exist or the default value |
|
85 | + */ |
|
86 | + public static function get($item, $default = null){ |
|
87 | + $logger = static::getLogger(); |
|
88 | + if(array_key_exists($item, self::$config)){ |
|
89 | + return self::$config[$item]; |
|
90 | + } |
|
91 | + $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
92 | + return $default; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Set the configuration item value |
|
97 | - * @param string $item the config item name to set |
|
98 | - * @param mixed $value the config item value |
|
99 | - */ |
|
100 | - public static function set($item, $value){ |
|
101 | - self::$config[$item] = $value; |
|
102 | - } |
|
95 | + /** |
|
96 | + * Set the configuration item value |
|
97 | + * @param string $item the config item name to set |
|
98 | + * @param mixed $value the config item value |
|
99 | + */ |
|
100 | + public static function set($item, $value){ |
|
101 | + self::$config[$item] = $value; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Get all the configuration values |
|
106 | - * @return array the config values |
|
107 | - */ |
|
108 | - public static function getAll(){ |
|
109 | - return self::$config; |
|
110 | - } |
|
104 | + /** |
|
105 | + * Get all the configuration values |
|
106 | + * @return array the config values |
|
107 | + */ |
|
108 | + public static function getAll(){ |
|
109 | + return self::$config; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Set the configuration values bu merged with the existing configuration |
|
114 | - * @param array $config the config values to add in the configuration list |
|
115 | - */ |
|
116 | - public static function setAll(array $config = array()){ |
|
117 | - self::$config = array_merge(self::$config, $config); |
|
118 | - } |
|
112 | + /** |
|
113 | + * Set the configuration values bu merged with the existing configuration |
|
114 | + * @param array $config the config values to add in the configuration list |
|
115 | + */ |
|
116 | + public static function setAll(array $config = array()){ |
|
117 | + self::$config = array_merge(self::$config, $config); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Delete the configuration item in the list |
|
122 | - * @param string $item the config item name to be deleted |
|
123 | - * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
124 | - */ |
|
125 | - public static function delete($item){ |
|
126 | - $logger = static::getLogger(); |
|
127 | - if(array_key_exists($item, self::$config)){ |
|
128 | - $logger->info('Delete config item ['.$item.']'); |
|
129 | - unset(self::$config[$item]); |
|
130 | - return true; |
|
131 | - } |
|
132 | - else{ |
|
133 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
134 | - return false; |
|
135 | - } |
|
136 | - } |
|
120 | + /** |
|
121 | + * Delete the configuration item in the list |
|
122 | + * @param string $item the config item name to be deleted |
|
123 | + * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
124 | + */ |
|
125 | + public static function delete($item){ |
|
126 | + $logger = static::getLogger(); |
|
127 | + if(array_key_exists($item, self::$config)){ |
|
128 | + $logger->info('Delete config item ['.$item.']'); |
|
129 | + unset(self::$config[$item]); |
|
130 | + return true; |
|
131 | + } |
|
132 | + else{ |
|
133 | + $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
134 | + return false; |
|
135 | + } |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * Load the configuration file. This an alias to Loader::config() |
|
140 | - * @param string $config the config name to be loaded |
|
141 | - */ |
|
142 | - public static function load($config){ |
|
143 | - Loader::config($config); |
|
144 | - } |
|
138 | + /** |
|
139 | + * Load the configuration file. This an alias to Loader::config() |
|
140 | + * @param string $config the config name to be loaded |
|
141 | + */ |
|
142 | + public static function load($config){ |
|
143 | + Loader::config($config); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Set the configuration for "base_url" if is not set in the configuration |
|
148 | - */ |
|
149 | - private static function setBaseUrlUsingServerVar(){ |
|
150 | - $logger = static::getLogger(); |
|
151 | - if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
152 | - if(ENVIRONMENT == 'production'){ |
|
153 | - $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
154 | - } |
|
155 | - $baseUrl = null; |
|
156 | - $protocol = 'http'; |
|
157 | - if(is_https()){ |
|
158 | - $protocol = 'https'; |
|
159 | - } |
|
160 | - $protocol .='://'; |
|
146 | + /** |
|
147 | + * Set the configuration for "base_url" if is not set in the configuration |
|
148 | + */ |
|
149 | + private static function setBaseUrlUsingServerVar(){ |
|
150 | + $logger = static::getLogger(); |
|
151 | + if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
152 | + if(ENVIRONMENT == 'production'){ |
|
153 | + $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
154 | + } |
|
155 | + $baseUrl = null; |
|
156 | + $protocol = 'http'; |
|
157 | + if(is_https()){ |
|
158 | + $protocol = 'https'; |
|
159 | + } |
|
160 | + $protocol .='://'; |
|
161 | 161 | |
162 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
163 | - $baseUrl = $_SERVER['SERVER_ADDR']; |
|
164 | - //check if the server is running under IPv6 |
|
165 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
166 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
167 | - } |
|
168 | - $serverPort = 80; |
|
169 | - if (isset($_SERVER['SERVER_PORT'])) { |
|
170 | - $serverPort = $_SERVER['SERVER_PORT']; |
|
171 | - } |
|
172 | - $port = ''; |
|
173 | - if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){ |
|
174 | - $port = ':'.$serverPort; |
|
175 | - } |
|
176 | - $baseUrl = $protocol . $baseUrl . $port . substr( |
|
177 | - $_SERVER['SCRIPT_NAME'], |
|
178 | - 0, |
|
179 | - strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
|
180 | - ); |
|
181 | - } |
|
182 | - else{ |
|
183 | - $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
184 | - $baseUrl = 'http://localhost/'; |
|
185 | - } |
|
186 | - self::set('base_url', $baseUrl); |
|
187 | - } |
|
188 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
189 | - } |
|
190 | - } |
|
162 | + if (isset($_SERVER['SERVER_ADDR'])){ |
|
163 | + $baseUrl = $_SERVER['SERVER_ADDR']; |
|
164 | + //check if the server is running under IPv6 |
|
165 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
166 | + $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
167 | + } |
|
168 | + $serverPort = 80; |
|
169 | + if (isset($_SERVER['SERVER_PORT'])) { |
|
170 | + $serverPort = $_SERVER['SERVER_PORT']; |
|
171 | + } |
|
172 | + $port = ''; |
|
173 | + if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){ |
|
174 | + $port = ':'.$serverPort; |
|
175 | + } |
|
176 | + $baseUrl = $protocol . $baseUrl . $port . substr( |
|
177 | + $_SERVER['SCRIPT_NAME'], |
|
178 | + 0, |
|
179 | + strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
|
180 | + ); |
|
181 | + } |
|
182 | + else{ |
|
183 | + $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
184 | + $baseUrl = 'http://localhost/'; |
|
185 | + } |
|
186 | + self::set('base_url', $baseUrl); |
|
187 | + } |
|
188 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
189 | + } |
|
190 | + } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Config{ |
|
27 | + class Config { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of loaded configuration |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * The signleton of the logger |
43 | 43 | * @return Object the Log instance |
44 | 44 | */ |
45 | - public static function getLogger(){ |
|
46 | - if(self::$logger == null){ |
|
45 | + public static function getLogger() { |
|
46 | + if (self::$logger == null) { |
|
47 | 47 | $logger = array(); |
48 | - $logger[0] =& class_loader('Log', 'classes'); |
|
48 | + $logger[0] = & class_loader('Log', 'classes'); |
|
49 | 49 | $logger[0]->setLogger('Library::Config'); |
50 | 50 | self::$logger = $logger[0]; |
51 | 51 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param object $logger the log object |
58 | 58 | * @return object the log instance |
59 | 59 | */ |
60 | - public static function setLogger($logger){ |
|
60 | + public static function setLogger($logger) { |
|
61 | 61 | self::$logger = $logger; |
62 | 62 | return self::$logger; |
63 | 63 | } |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Initialize the configuration by loading all the configuration from config file |
67 | 67 | */ |
68 | - public static function init(){ |
|
68 | + public static function init() { |
|
69 | 69 | $logger = static::getLogger(); |
70 | 70 | $logger->debug('Initialization of the configuration'); |
71 | 71 | self::$config = & load_configurations(); |
72 | 72 | self::setBaseUrlUsingServerVar(); |
73 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
73 | + if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) { |
|
74 | 74 | $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
75 | 75 | } |
76 | 76 | $logger->info('Configuration initialized successfully'); |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * @param mixed $default the default value to use if can not find the config item in the list |
84 | 84 | * @return mixed the config value if exist or the default value |
85 | 85 | */ |
86 | - public static function get($item, $default = null){ |
|
86 | + public static function get($item, $default = null) { |
|
87 | 87 | $logger = static::getLogger(); |
88 | - if(array_key_exists($item, self::$config)){ |
|
88 | + if (array_key_exists($item, self::$config)) { |
|
89 | 89 | return self::$config[$item]; |
90 | 90 | } |
91 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
91 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
92 | 92 | return $default; |
93 | 93 | } |
94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param string $item the config item name to set |
98 | 98 | * @param mixed $value the config item value |
99 | 99 | */ |
100 | - public static function set($item, $value){ |
|
100 | + public static function set($item, $value) { |
|
101 | 101 | self::$config[$item] = $value; |
102 | 102 | } |
103 | 103 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * Get all the configuration values |
106 | 106 | * @return array the config values |
107 | 107 | */ |
108 | - public static function getAll(){ |
|
108 | + public static function getAll() { |
|
109 | 109 | return self::$config; |
110 | 110 | } |
111 | 111 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * Set the configuration values bu merged with the existing configuration |
114 | 114 | * @param array $config the config values to add in the configuration list |
115 | 115 | */ |
116 | - public static function setAll(array $config = array()){ |
|
116 | + public static function setAll(array $config = array()) { |
|
117 | 117 | self::$config = array_merge(self::$config, $config); |
118 | 118 | } |
119 | 119 | |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | * @param string $item the config item name to be deleted |
123 | 123 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
124 | 124 | */ |
125 | - public static function delete($item){ |
|
125 | + public static function delete($item) { |
|
126 | 126 | $logger = static::getLogger(); |
127 | - if(array_key_exists($item, self::$config)){ |
|
128 | - $logger->info('Delete config item ['.$item.']'); |
|
127 | + if (array_key_exists($item, self::$config)) { |
|
128 | + $logger->info('Delete config item [' . $item . ']'); |
|
129 | 129 | unset(self::$config[$item]); |
130 | 130 | return true; |
131 | 131 | } |
132 | - else{ |
|
133 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
132 | + else { |
|
133 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
134 | 134 | return false; |
135 | 135 | } |
136 | 136 | } |
@@ -139,39 +139,39 @@ discard block |
||
139 | 139 | * Load the configuration file. This an alias to Loader::config() |
140 | 140 | * @param string $config the config name to be loaded |
141 | 141 | */ |
142 | - public static function load($config){ |
|
142 | + public static function load($config) { |
|
143 | 143 | Loader::config($config); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * Set the configuration for "base_url" if is not set in the configuration |
148 | 148 | */ |
149 | - private static function setBaseUrlUsingServerVar(){ |
|
149 | + private static function setBaseUrlUsingServerVar() { |
|
150 | 150 | $logger = static::getLogger(); |
151 | - if (! isset(self::$config['base_url']) || ! is_url(self::$config['base_url'])){ |
|
152 | - if(ENVIRONMENT == 'production'){ |
|
151 | + if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) { |
|
152 | + if (ENVIRONMENT == 'production') { |
|
153 | 153 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
154 | 154 | } |
155 | 155 | $baseUrl = null; |
156 | 156 | $protocol = 'http'; |
157 | - if(is_https()){ |
|
157 | + if (is_https()) { |
|
158 | 158 | $protocol = 'https'; |
159 | 159 | } |
160 | - $protocol .='://'; |
|
160 | + $protocol .= '://'; |
|
161 | 161 | |
162 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
162 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
163 | 163 | $baseUrl = $_SERVER['SERVER_ADDR']; |
164 | 164 | //check if the server is running under IPv6 |
165 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
166 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
165 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
166 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
167 | 167 | } |
168 | 168 | $serverPort = 80; |
169 | 169 | if (isset($_SERVER['SERVER_PORT'])) { |
170 | 170 | $serverPort = $_SERVER['SERVER_PORT']; |
171 | 171 | } |
172 | 172 | $port = ''; |
173 | - if($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))){ |
|
174 | - $port = ':'.$serverPort; |
|
173 | + if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) { |
|
174 | + $port = ':' . $serverPort; |
|
175 | 175 | } |
176 | 176 | $baseUrl = $protocol . $baseUrl . $port . substr( |
177 | 177 | $_SERVER['SCRIPT_NAME'], |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
180 | 180 | ); |
181 | 181 | } |
182 | - else{ |
|
182 | + else { |
|
183 | 183 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
184 | 184 | $baseUrl = 'http://localhost/'; |
185 | 185 | } |
186 | 186 | self::set('base_url', $baseUrl); |
187 | 187 | } |
188 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
188 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
|
189 | 189 | } |
190 | 190 | } |
@@ -1,538 +1,538 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') or exit('Access denied'); |
|
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
2 | + defined('ROOT_PATH') or exit('Access denied'); |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | 26 | |
27 | - class Response{ |
|
27 | + class Response{ |
|
28 | 28 | |
29 | - /** |
|
30 | - * The list of request header to send with response |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - private static $headers = array(); |
|
29 | + /** |
|
30 | + * The list of request header to send with response |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private static $headers = array(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * The logger instance |
|
37 | - * @var object |
|
38 | - */ |
|
39 | - private static $logger; |
|
35 | + /** |
|
36 | + * The logger instance |
|
37 | + * @var object |
|
38 | + */ |
|
39 | + private static $logger; |
|
40 | 40 | |
41 | - /** |
|
42 | - * The final page content to display to user |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - private $_pageRender = null; |
|
41 | + /** |
|
42 | + * The final page content to display to user |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + private $_pageRender = null; |
|
46 | 46 | |
47 | - /** |
|
48 | - * The current request URL |
|
49 | - * @var string |
|
50 | - */ |
|
51 | - private $_currentUrl = null; |
|
47 | + /** |
|
48 | + * The current request URL |
|
49 | + * @var string |
|
50 | + */ |
|
51 | + private $_currentUrl = null; |
|
52 | 52 | |
53 | - /** |
|
54 | - * The current request URL cache key |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - private $_currentUrlCacheKey = null; |
|
53 | + /** |
|
54 | + * The current request URL cache key |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + private $_currentUrlCacheKey = null; |
|
58 | 58 | |
59 | - /** |
|
60 | - * Whether we can compress the output using Gzip |
|
61 | - * @var boolean |
|
62 | - */ |
|
63 | - private static $_canCompressOutput = false; |
|
59 | + /** |
|
60 | + * Whether we can compress the output using Gzip |
|
61 | + * @var boolean |
|
62 | + */ |
|
63 | + private static $_canCompressOutput = false; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Construct new response instance |
|
67 | - */ |
|
68 | - public function __construct(){ |
|
69 | - $currentUrl = ''; |
|
70 | - if (! empty($_SERVER['REQUEST_URI'])){ |
|
71 | - $currentUrl = $_SERVER['REQUEST_URI']; |
|
72 | - } |
|
73 | - if (! empty($_SERVER['QUERY_STRING'])){ |
|
74 | - $currentUrl .= '?' . $_SERVER['QUERY_STRING']; |
|
75 | - } |
|
76 | - $this->_currentUrl = $currentUrl; |
|
65 | + /** |
|
66 | + * Construct new response instance |
|
67 | + */ |
|
68 | + public function __construct(){ |
|
69 | + $currentUrl = ''; |
|
70 | + if (! empty($_SERVER['REQUEST_URI'])){ |
|
71 | + $currentUrl = $_SERVER['REQUEST_URI']; |
|
72 | + } |
|
73 | + if (! empty($_SERVER['QUERY_STRING'])){ |
|
74 | + $currentUrl .= '?' . $_SERVER['QUERY_STRING']; |
|
75 | + } |
|
76 | + $this->_currentUrl = $currentUrl; |
|
77 | 77 | |
78 | - $this->_currentUrlCacheKey = md5($this->_currentUrl); |
|
78 | + $this->_currentUrlCacheKey = md5($this->_currentUrl); |
|
79 | 79 | |
80 | - self::$_canCompressOutput = get_config('compress_output') |
|
81 | - && isset($_SERVER['HTTP_ACCEPT_ENCODING']) |
|
82 | - && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false |
|
83 | - && extension_loaded('zlib') |
|
84 | - && (bool) ini_get('zlib.output_compression') === false; |
|
85 | - } |
|
80 | + self::$_canCompressOutput = get_config('compress_output') |
|
81 | + && isset($_SERVER['HTTP_ACCEPT_ENCODING']) |
|
82 | + && stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false |
|
83 | + && extension_loaded('zlib') |
|
84 | + && (bool) ini_get('zlib.output_compression') === false; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * The signleton of the logger |
|
90 | - * @return Object the Log instance |
|
91 | - */ |
|
92 | - public static function getLogger(){ |
|
93 | - if(self::$logger == null){ |
|
94 | - $logger = array(); |
|
95 | - $logger[0] =& class_loader('Log', 'classes'); |
|
96 | - $logger[0]->setLogger('Library::Response'); |
|
97 | - self::$logger = $logger[0]; |
|
98 | - } |
|
99 | - return self::$logger; |
|
100 | - } |
|
88 | + /** |
|
89 | + * The signleton of the logger |
|
90 | + * @return Object the Log instance |
|
91 | + */ |
|
92 | + public static function getLogger(){ |
|
93 | + if(self::$logger == null){ |
|
94 | + $logger = array(); |
|
95 | + $logger[0] =& class_loader('Log', 'classes'); |
|
96 | + $logger[0]->setLogger('Library::Response'); |
|
97 | + self::$logger = $logger[0]; |
|
98 | + } |
|
99 | + return self::$logger; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Set the log instance for future use |
|
104 | - * @param object $logger the log object |
|
105 | - * @return object the log instance |
|
106 | - */ |
|
107 | - public static function setLogger($logger){ |
|
108 | - self::$logger = $logger; |
|
109 | - return self::$logger; |
|
110 | - } |
|
102 | + /** |
|
103 | + * Set the log instance for future use |
|
104 | + * @param object $logger the log object |
|
105 | + * @return object the log instance |
|
106 | + */ |
|
107 | + public static function setLogger($logger){ |
|
108 | + self::$logger = $logger; |
|
109 | + return self::$logger; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * Send the HTTP Response headers |
|
115 | - * @param integer $httpCode the HTTP status code |
|
116 | - * @param array $headers the additional headers to add to the existing headers list |
|
117 | - */ |
|
118 | - public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
119 | - set_http_status_header($httpCode); |
|
120 | - self::setHeaders($headers); |
|
121 | - if(! headers_sent()){ |
|
122 | - foreach(self::getHeaders() as $key => $value){ |
|
123 | - header($key .': '.$value); |
|
124 | - } |
|
125 | - } |
|
126 | - } |
|
113 | + /** |
|
114 | + * Send the HTTP Response headers |
|
115 | + * @param integer $httpCode the HTTP status code |
|
116 | + * @param array $headers the additional headers to add to the existing headers list |
|
117 | + */ |
|
118 | + public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
119 | + set_http_status_header($httpCode); |
|
120 | + self::setHeaders($headers); |
|
121 | + if(! headers_sent()){ |
|
122 | + foreach(self::getHeaders() as $key => $value){ |
|
123 | + header($key .': '.$value); |
|
124 | + } |
|
125 | + } |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Get the list of the headers |
|
130 | - * @return array the headers list |
|
131 | - */ |
|
132 | - public static function getHeaders(){ |
|
133 | - return self::$headers; |
|
134 | - } |
|
128 | + /** |
|
129 | + * Get the list of the headers |
|
130 | + * @return array the headers list |
|
131 | + */ |
|
132 | + public static function getHeaders(){ |
|
133 | + return self::$headers; |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Get the header value for the given name |
|
138 | - * @param string $name the header name |
|
139 | - * @return string|null the header value |
|
140 | - */ |
|
141 | - public static function getHeader($name){ |
|
142 | - if(array_key_exists($name, self::$headers)){ |
|
143 | - return self::$headers[$name]; |
|
144 | - } |
|
145 | - return null; |
|
146 | - } |
|
136 | + /** |
|
137 | + * Get the header value for the given name |
|
138 | + * @param string $name the header name |
|
139 | + * @return string|null the header value |
|
140 | + */ |
|
141 | + public static function getHeader($name){ |
|
142 | + if(array_key_exists($name, self::$headers)){ |
|
143 | + return self::$headers[$name]; |
|
144 | + } |
|
145 | + return null; |
|
146 | + } |
|
147 | 147 | |
148 | 148 | |
149 | - /** |
|
150 | - * Set the header value for the specified name |
|
151 | - * @param string $name the header name |
|
152 | - * @param string $value the header value to be set |
|
153 | - */ |
|
154 | - public static function setHeader($name, $value){ |
|
155 | - self::$headers[$name] = $value; |
|
156 | - } |
|
149 | + /** |
|
150 | + * Set the header value for the specified name |
|
151 | + * @param string $name the header name |
|
152 | + * @param string $value the header value to be set |
|
153 | + */ |
|
154 | + public static function setHeader($name, $value){ |
|
155 | + self::$headers[$name] = $value; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Set the headers using array |
|
160 | - * @param array $headers the list of the headers to set. |
|
161 | - * Note: this will merge with the existing headers |
|
162 | - */ |
|
163 | - public static function setHeaders(array $headers){ |
|
164 | - self::$headers = array_merge(self::getHeaders(), $headers); |
|
165 | - } |
|
158 | + /** |
|
159 | + * Set the headers using array |
|
160 | + * @param array $headers the list of the headers to set. |
|
161 | + * Note: this will merge with the existing headers |
|
162 | + */ |
|
163 | + public static function setHeaders(array $headers){ |
|
164 | + self::$headers = array_merge(self::getHeaders(), $headers); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Redirect user to the specified page |
|
169 | - * @param string $path the URL or URI to be redirect to |
|
170 | - */ |
|
171 | - public static function redirect($path = ''){ |
|
172 | - $logger = self::getLogger(); |
|
173 | - $url = Url::site_url($path); |
|
174 | - $logger->info('Redirect to URL [' .$url. ']'); |
|
175 | - if(! headers_sent()){ |
|
176 | - header('Location: '.$url); |
|
177 | - exit; |
|
178 | - } |
|
179 | - echo '<script> |
|
167 | + /** |
|
168 | + * Redirect user to the specified page |
|
169 | + * @param string $path the URL or URI to be redirect to |
|
170 | + */ |
|
171 | + public static function redirect($path = ''){ |
|
172 | + $logger = self::getLogger(); |
|
173 | + $url = Url::site_url($path); |
|
174 | + $logger->info('Redirect to URL [' .$url. ']'); |
|
175 | + if(! headers_sent()){ |
|
176 | + header('Location: '.$url); |
|
177 | + exit; |
|
178 | + } |
|
179 | + echo '<script> |
|
180 | 180 | location.href = "'.$url.'"; |
181 | 181 | </script>'; |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Render the view to display later or return the content |
|
186 | - * @param string $view the view name or path |
|
187 | - * @param array|object $data the variable data to use in the view |
|
188 | - * @param boolean $return whether to return the view generated content or display it directly |
|
189 | - * @return void|string if $return is true will return the view content otherwise |
|
190 | - * will display the view content. |
|
191 | - */ |
|
192 | - public function render($view, $data = null, $return = false){ |
|
193 | - $logger = self::getLogger(); |
|
194 | - //convert data to an array |
|
195 | - $data = (array) $data; |
|
196 | - $view = str_ireplace('.php', '', $view); |
|
197 | - $view = trim($view, '/\\'); |
|
198 | - $viewFile = $view . '.php'; |
|
199 | - $path = APPS_VIEWS_PATH . $viewFile; |
|
184 | + /** |
|
185 | + * Render the view to display later or return the content |
|
186 | + * @param string $view the view name or path |
|
187 | + * @param array|object $data the variable data to use in the view |
|
188 | + * @param boolean $return whether to return the view generated content or display it directly |
|
189 | + * @return void|string if $return is true will return the view content otherwise |
|
190 | + * will display the view content. |
|
191 | + */ |
|
192 | + public function render($view, $data = null, $return = false){ |
|
193 | + $logger = self::getLogger(); |
|
194 | + //convert data to an array |
|
195 | + $data = (array) $data; |
|
196 | + $view = str_ireplace('.php', '', $view); |
|
197 | + $view = trim($view, '/\\'); |
|
198 | + $viewFile = $view . '.php'; |
|
199 | + $path = APPS_VIEWS_PATH . $viewFile; |
|
200 | 200 | |
201 | - //check in module first |
|
202 | - $logger->debug('Checking the view [' . $view . '] from module list ...'); |
|
203 | - $moduleInfo = self::getModuleInfoForView($view); |
|
204 | - $module = $moduleInfo['module']; |
|
205 | - $view = $moduleInfo['view']; |
|
206 | - if(! empty($moduleInfo['viewFile'])){ |
|
207 | - $viewFile = $moduleInfo['viewFile']; |
|
208 | - } |
|
209 | - $moduleViewPath = Module::findViewFullPath($view, $module); |
|
210 | - if($moduleViewPath){ |
|
211 | - $path = $moduleViewPath; |
|
212 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
213 | - } |
|
214 | - else{ |
|
215 | - $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location'); |
|
216 | - } |
|
201 | + //check in module first |
|
202 | + $logger->debug('Checking the view [' . $view . '] from module list ...'); |
|
203 | + $moduleInfo = self::getModuleInfoForView($view); |
|
204 | + $module = $moduleInfo['module']; |
|
205 | + $view = $moduleInfo['view']; |
|
206 | + if(! empty($moduleInfo['viewFile'])){ |
|
207 | + $viewFile = $moduleInfo['viewFile']; |
|
208 | + } |
|
209 | + $moduleViewPath = Module::findViewFullPath($view, $module); |
|
210 | + if($moduleViewPath){ |
|
211 | + $path = $moduleViewPath; |
|
212 | + $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
213 | + } |
|
214 | + else{ |
|
215 | + $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location'); |
|
216 | + } |
|
217 | 217 | |
218 | - $logger->info('The view file path to be loaded is [' . $path . ']'); |
|
218 | + $logger->info('The view file path to be loaded is [' . $path . ']'); |
|
219 | 219 | |
220 | - ///////// |
|
221 | - if($return){ |
|
222 | - return $this->loadView($path, $data, true); |
|
223 | - } |
|
224 | - $this->loadView($path, $data, false); |
|
225 | - } |
|
220 | + ///////// |
|
221 | + if($return){ |
|
222 | + return $this->loadView($path, $data, true); |
|
223 | + } |
|
224 | + $this->loadView($path, $data, false); |
|
225 | + } |
|
226 | 226 | |
227 | 227 | |
228 | - /** |
|
229 | - * Send the final page output to user |
|
230 | - */ |
|
231 | - public function renderFinalPage(){ |
|
232 | - $logger = self::getLogger(); |
|
233 | - $obj = & get_instance(); |
|
234 | - $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
|
235 | - $dispatcher = $obj->eventdispatcher; |
|
236 | - $content = $this->_pageRender; |
|
237 | - if(! $content){ |
|
238 | - $logger->warning('The final view content is empty.'); |
|
239 | - return; |
|
240 | - } |
|
241 | - //dispatch |
|
242 | - $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true)); |
|
243 | - $content = null; |
|
244 | - if(! empty($event->payload)){ |
|
245 | - $content = $event->payload; |
|
246 | - } |
|
247 | - if(empty($content)){ |
|
248 | - $logger->warning('The view content is empty after dispatch to event listeners.'); |
|
249 | - } |
|
228 | + /** |
|
229 | + * Send the final page output to user |
|
230 | + */ |
|
231 | + public function renderFinalPage(){ |
|
232 | + $logger = self::getLogger(); |
|
233 | + $obj = & get_instance(); |
|
234 | + $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
|
235 | + $dispatcher = $obj->eventdispatcher; |
|
236 | + $content = $this->_pageRender; |
|
237 | + if(! $content){ |
|
238 | + $logger->warning('The final view content is empty.'); |
|
239 | + return; |
|
240 | + } |
|
241 | + //dispatch |
|
242 | + $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true)); |
|
243 | + $content = null; |
|
244 | + if(! empty($event->payload)){ |
|
245 | + $content = $event->payload; |
|
246 | + } |
|
247 | + if(empty($content)){ |
|
248 | + $logger->warning('The view content is empty after dispatch to event listeners.'); |
|
249 | + } |
|
250 | 250 | |
251 | - //check whether need save the page into cache. |
|
252 | - if($cachePageStatus){ |
|
253 | - $this->savePageContentIntoCache($content); |
|
254 | - } |
|
251 | + //check whether need save the page into cache. |
|
252 | + if($cachePageStatus){ |
|
253 | + $this->savePageContentIntoCache($content); |
|
254 | + } |
|
255 | 255 | |
256 | - // Parse out the elapsed time and memory usage, |
|
257 | - // then swap the pseudo-variables with the data |
|
258 | - $elapsedTime = $obj->benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END'); |
|
259 | - $memoryUsage = round($obj->benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB'; |
|
260 | - $content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content); |
|
256 | + // Parse out the elapsed time and memory usage, |
|
257 | + // then swap the pseudo-variables with the data |
|
258 | + $elapsedTime = $obj->benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END'); |
|
259 | + $memoryUsage = round($obj->benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB'; |
|
260 | + $content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content); |
|
261 | 261 | |
262 | - //compress the output if is available |
|
263 | - $type = null; |
|
264 | - if (self::$_canCompressOutput){ |
|
265 | - $type = 'ob_gzhandler'; |
|
266 | - } |
|
267 | - ob_start($type); |
|
268 | - self::sendHeaders(200); |
|
269 | - echo $content; |
|
270 | - ob_end_flush(); |
|
271 | - } |
|
262 | + //compress the output if is available |
|
263 | + $type = null; |
|
264 | + if (self::$_canCompressOutput){ |
|
265 | + $type = 'ob_gzhandler'; |
|
266 | + } |
|
267 | + ob_start($type); |
|
268 | + self::sendHeaders(200); |
|
269 | + echo $content; |
|
270 | + ob_end_flush(); |
|
271 | + } |
|
272 | 272 | |
273 | 273 | |
274 | - /** |
|
275 | - * Send the final page output to user if is cached |
|
276 | - * @param object $cache the cache instance |
|
277 | - * |
|
278 | - * @return boolean whether the page content if available or not |
|
279 | - */ |
|
280 | - public function renderFinalPageFromCache(&$cache){ |
|
281 | - $logger = self::getLogger(); |
|
282 | - //the current page cache key for identification |
|
283 | - $pageCacheKey = $this->_currentUrlCacheKey; |
|
274 | + /** |
|
275 | + * Send the final page output to user if is cached |
|
276 | + * @param object $cache the cache instance |
|
277 | + * |
|
278 | + * @return boolean whether the page content if available or not |
|
279 | + */ |
|
280 | + public function renderFinalPageFromCache(&$cache){ |
|
281 | + $logger = self::getLogger(); |
|
282 | + //the current page cache key for identification |
|
283 | + $pageCacheKey = $this->_currentUrlCacheKey; |
|
284 | 284 | |
285 | - $logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...'); |
|
286 | - //get the cache information to prepare header to send to browser |
|
287 | - $cacheInfo = $cache->getInfo($pageCacheKey); |
|
288 | - if($cacheInfo){ |
|
289 | - $status = $this->sendCacheNotYetExpireInfo($cacheInfo); |
|
290 | - if($status === false){ |
|
291 | - return $this->sendPageContentToBrowser($cache); |
|
292 | - } |
|
293 | - } |
|
294 | - return false; |
|
295 | - } |
|
285 | + $logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...'); |
|
286 | + //get the cache information to prepare header to send to browser |
|
287 | + $cacheInfo = $cache->getInfo($pageCacheKey); |
|
288 | + if($cacheInfo){ |
|
289 | + $status = $this->sendCacheNotYetExpireInfo($cacheInfo); |
|
290 | + if($status === false){ |
|
291 | + return $this->sendPageContentToBrowser($cache); |
|
292 | + } |
|
293 | + } |
|
294 | + return false; |
|
295 | + } |
|
296 | 296 | |
297 | 297 | |
298 | - /** |
|
299 | - * Get the final page to be rendered |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function getFinalPageRendered(){ |
|
303 | - return $this->_pageRender; |
|
304 | - } |
|
298 | + /** |
|
299 | + * Get the final page to be rendered |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function getFinalPageRendered(){ |
|
303 | + return $this->_pageRender; |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
307 | - * Send the HTTP 404 error if can not found the |
|
308 | - * routing information for the current request |
|
309 | - */ |
|
310 | - public static function send404(){ |
|
311 | - /********* for logs **************/ |
|
312 | - //can't use $obj = & get_instance() here because the global super object will be available until |
|
313 | - //the main controller is loaded even for Loader::library('xxxx'); |
|
314 | - $logger = self::getLogger(); |
|
315 | - $request =& class_loader('Request', 'classes'); |
|
316 | - $userAgent =& class_loader('Browser'); |
|
317 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
306 | + /** |
|
307 | + * Send the HTTP 404 error if can not found the |
|
308 | + * routing information for the current request |
|
309 | + */ |
|
310 | + public static function send404(){ |
|
311 | + /********* for logs **************/ |
|
312 | + //can't use $obj = & get_instance() here because the global super object will be available until |
|
313 | + //the main controller is loaded even for Loader::library('xxxx'); |
|
314 | + $logger = self::getLogger(); |
|
315 | + $request =& class_loader('Request', 'classes'); |
|
316 | + $userAgent =& class_loader('Browser'); |
|
317 | + $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
318 | 318 | |
319 | - //here can't use Loader::functions just include the helper manually |
|
320 | - require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
319 | + //here can't use Loader::functions just include the helper manually |
|
320 | + require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
321 | 321 | |
322 | - $str = '[404 page not found] : '; |
|
323 | - $str .= ' Unable to find the request page [' . $request->requestUri() . ']. The visitor IP address [' . get_ip() . '], browser [' . $browser . ']'; |
|
324 | - $logger->error($str); |
|
325 | - /***********************************/ |
|
326 | - $path = CORE_VIEWS_PATH . '404.php'; |
|
327 | - if(file_exists($path)){ |
|
328 | - //compress the output if is available |
|
329 | - $type = null; |
|
330 | - if (self::$_canCompressOutput){ |
|
331 | - $type = 'ob_gzhandler'; |
|
332 | - } |
|
333 | - ob_start($type); |
|
334 | - require_once $path; |
|
335 | - $output = ob_get_clean(); |
|
336 | - self::sendHeaders(404); |
|
337 | - echo $output; |
|
338 | - } |
|
339 | - else{ |
|
340 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
341 | - } |
|
342 | - } |
|
322 | + $str = '[404 page not found] : '; |
|
323 | + $str .= ' Unable to find the request page [' . $request->requestUri() . ']. The visitor IP address [' . get_ip() . '], browser [' . $browser . ']'; |
|
324 | + $logger->error($str); |
|
325 | + /***********************************/ |
|
326 | + $path = CORE_VIEWS_PATH . '404.php'; |
|
327 | + if(file_exists($path)){ |
|
328 | + //compress the output if is available |
|
329 | + $type = null; |
|
330 | + if (self::$_canCompressOutput){ |
|
331 | + $type = 'ob_gzhandler'; |
|
332 | + } |
|
333 | + ob_start($type); |
|
334 | + require_once $path; |
|
335 | + $output = ob_get_clean(); |
|
336 | + self::sendHeaders(404); |
|
337 | + echo $output; |
|
338 | + } |
|
339 | + else{ |
|
340 | + show_error('The 404 view [' .$path. '] does not exist'); |
|
341 | + } |
|
342 | + } |
|
343 | 343 | |
344 | - /** |
|
345 | - * Display the error to user |
|
346 | - * @param array $data the error information |
|
347 | - */ |
|
348 | - public static function sendError(array $data = array()){ |
|
349 | - $path = CORE_VIEWS_PATH . 'errors.php'; |
|
350 | - if(file_exists($path)){ |
|
351 | - //compress the output if is available |
|
352 | - $type = null; |
|
353 | - if (self::$_canCompressOutput){ |
|
354 | - $type = 'ob_gzhandler'; |
|
355 | - } |
|
356 | - ob_start($type); |
|
357 | - extract($data); |
|
358 | - require_once $path; |
|
359 | - $output = ob_get_clean(); |
|
360 | - self::sendHeaders(503); |
|
361 | - echo $output; |
|
362 | - } |
|
363 | - else{ |
|
364 | - //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
|
365 | - set_http_status_header(503); |
|
366 | - echo 'The error view [' . $path . '] does not exist'; |
|
367 | - } |
|
368 | - } |
|
344 | + /** |
|
345 | + * Display the error to user |
|
346 | + * @param array $data the error information |
|
347 | + */ |
|
348 | + public static function sendError(array $data = array()){ |
|
349 | + $path = CORE_VIEWS_PATH . 'errors.php'; |
|
350 | + if(file_exists($path)){ |
|
351 | + //compress the output if is available |
|
352 | + $type = null; |
|
353 | + if (self::$_canCompressOutput){ |
|
354 | + $type = 'ob_gzhandler'; |
|
355 | + } |
|
356 | + ob_start($type); |
|
357 | + extract($data); |
|
358 | + require_once $path; |
|
359 | + $output = ob_get_clean(); |
|
360 | + self::sendHeaders(503); |
|
361 | + echo $output; |
|
362 | + } |
|
363 | + else{ |
|
364 | + //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
|
365 | + set_http_status_header(503); |
|
366 | + echo 'The error view [' . $path . '] does not exist'; |
|
367 | + } |
|
368 | + } |
|
369 | 369 | |
370 | - /** |
|
371 | - * Send the cache not yet expire to browser |
|
372 | - * @param array $cacheInfo the cache information |
|
373 | - * @return boolean true if the information is sent otherwise false |
|
374 | - */ |
|
375 | - protected function sendCacheNotYetExpireInfo($cacheInfo){ |
|
376 | - if(! empty($cacheInfo)){ |
|
377 | - $logger = self::getLogger(); |
|
378 | - $lastModified = $cacheInfo['mtime']; |
|
379 | - $expire = $cacheInfo['expire']; |
|
380 | - $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
|
381 | - self::setHeader('Pragma', 'public'); |
|
382 | - self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
|
383 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
384 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
385 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
386 | - $logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser'); |
|
387 | - self::sendHeaders(304); |
|
388 | - return true; |
|
389 | - } |
|
390 | - } |
|
391 | - return false; |
|
392 | - } |
|
370 | + /** |
|
371 | + * Send the cache not yet expire to browser |
|
372 | + * @param array $cacheInfo the cache information |
|
373 | + * @return boolean true if the information is sent otherwise false |
|
374 | + */ |
|
375 | + protected function sendCacheNotYetExpireInfo($cacheInfo){ |
|
376 | + if(! empty($cacheInfo)){ |
|
377 | + $logger = self::getLogger(); |
|
378 | + $lastModified = $cacheInfo['mtime']; |
|
379 | + $expire = $cacheInfo['expire']; |
|
380 | + $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
|
381 | + self::setHeader('Pragma', 'public'); |
|
382 | + self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
|
383 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
384 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
385 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
386 | + $logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser'); |
|
387 | + self::sendHeaders(304); |
|
388 | + return true; |
|
389 | + } |
|
390 | + } |
|
391 | + return false; |
|
392 | + } |
|
393 | 393 | |
394 | - /** |
|
395 | - * Send the page content from cache to browser |
|
396 | - * @param object $cache the cache instance |
|
397 | - * @return boolean the status of the operation |
|
398 | - */ |
|
399 | - protected function sendPageContentToBrowser(&$cache){ |
|
400 | - $logger = self::getLogger(); |
|
401 | - $logger->info('The cache page content is expired or the browser doesn\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser'); |
|
402 | - self::sendHeaders(200); |
|
403 | - //current page cache key |
|
404 | - $pageCacheKey = $this->_currentUrlCacheKey; |
|
405 | - //get the cache content |
|
406 | - $content = $cache->get($pageCacheKey); |
|
407 | - if($content){ |
|
408 | - $logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it'); |
|
409 | - //load benchmark class |
|
410 | - $benchmark = & class_loader('Benchmark'); |
|
394 | + /** |
|
395 | + * Send the page content from cache to browser |
|
396 | + * @param object $cache the cache instance |
|
397 | + * @return boolean the status of the operation |
|
398 | + */ |
|
399 | + protected function sendPageContentToBrowser(&$cache){ |
|
400 | + $logger = self::getLogger(); |
|
401 | + $logger->info('The cache page content is expired or the browser doesn\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser'); |
|
402 | + self::sendHeaders(200); |
|
403 | + //current page cache key |
|
404 | + $pageCacheKey = $this->_currentUrlCacheKey; |
|
405 | + //get the cache content |
|
406 | + $content = $cache->get($pageCacheKey); |
|
407 | + if($content){ |
|
408 | + $logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it'); |
|
409 | + //load benchmark class |
|
410 | + $benchmark = & class_loader('Benchmark'); |
|
411 | 411 | |
412 | - // Parse out the elapsed time and memory usage, |
|
413 | - // then swap the pseudo-variables with the data |
|
414 | - $elapsedTime = $benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END'); |
|
415 | - $memoryUsage = round($benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB'; |
|
416 | - $content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content); |
|
412 | + // Parse out the elapsed time and memory usage, |
|
413 | + // then swap the pseudo-variables with the data |
|
414 | + $elapsedTime = $benchmark->elapsedTime('APP_EXECUTION_START', 'APP_EXECUTION_END'); |
|
415 | + $memoryUsage = round($benchmark->memoryUsage('APP_EXECUTION_START', 'APP_EXECUTION_END') / 1024 / 1024, 6) . 'MB'; |
|
416 | + $content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content); |
|
417 | 417 | |
418 | - ///display the final output |
|
419 | - //compress the output if is available |
|
420 | - $type = null; |
|
421 | - if (self::$_canCompressOutput){ |
|
422 | - $type = 'ob_gzhandler'; |
|
423 | - } |
|
424 | - ob_start($type); |
|
425 | - echo $content; |
|
426 | - ob_end_flush(); |
|
427 | - return true; |
|
428 | - } |
|
429 | - $logger->info('The page cache content for the URL [' . $this->_currentUrl . '] is not valid may be already expired'); |
|
430 | - $cache->delete($pageCacheKey); |
|
431 | - return false; |
|
432 | - } |
|
418 | + ///display the final output |
|
419 | + //compress the output if is available |
|
420 | + $type = null; |
|
421 | + if (self::$_canCompressOutput){ |
|
422 | + $type = 'ob_gzhandler'; |
|
423 | + } |
|
424 | + ob_start($type); |
|
425 | + echo $content; |
|
426 | + ob_end_flush(); |
|
427 | + return true; |
|
428 | + } |
|
429 | + $logger->info('The page cache content for the URL [' . $this->_currentUrl . '] is not valid may be already expired'); |
|
430 | + $cache->delete($pageCacheKey); |
|
431 | + return false; |
|
432 | + } |
|
433 | 433 | |
434 | - /** |
|
435 | - * Save the content of page into cache |
|
436 | - * @param string $content the page content to be saved |
|
437 | - * @return void |
|
438 | - */ |
|
439 | - protected function savePageContentIntoCache($content){ |
|
440 | - $obj = & get_instance(); |
|
441 | - $logger = self::getLogger(); |
|
434 | + /** |
|
435 | + * Save the content of page into cache |
|
436 | + * @param string $content the page content to be saved |
|
437 | + * @return void |
|
438 | + */ |
|
439 | + protected function savePageContentIntoCache($content){ |
|
440 | + $obj = & get_instance(); |
|
441 | + $logger = self::getLogger(); |
|
442 | 442 | |
443 | - //current page URL |
|
444 | - $url = $this->_currentUrl; |
|
445 | - //Cache view Time to live in second |
|
446 | - $viewCacheTtl = get_config('cache_ttl'); |
|
447 | - if (!empty($obj->view_cache_ttl)){ |
|
448 | - $viewCacheTtl = $obj->view_cache_ttl; |
|
449 | - } |
|
450 | - //the cache handler instance |
|
451 | - $cacheInstance = $obj->cache; |
|
452 | - //the current page cache key for identification |
|
453 | - $cacheKey = $this->_currentUrlCacheKey; |
|
443 | + //current page URL |
|
444 | + $url = $this->_currentUrl; |
|
445 | + //Cache view Time to live in second |
|
446 | + $viewCacheTtl = get_config('cache_ttl'); |
|
447 | + if (!empty($obj->view_cache_ttl)){ |
|
448 | + $viewCacheTtl = $obj->view_cache_ttl; |
|
449 | + } |
|
450 | + //the cache handler instance |
|
451 | + $cacheInstance = $obj->cache; |
|
452 | + //the current page cache key for identification |
|
453 | + $cacheKey = $this->_currentUrlCacheKey; |
|
454 | 454 | |
455 | - $logger->debug('Save the page content for URL [' . $url . '] into the cache ...'); |
|
456 | - $cacheInstance->set($cacheKey, $content, $viewCacheTtl); |
|
455 | + $logger->debug('Save the page content for URL [' . $url . '] into the cache ...'); |
|
456 | + $cacheInstance->set($cacheKey, $content, $viewCacheTtl); |
|
457 | 457 | |
458 | - //get the cache information to prepare header to send to browser |
|
459 | - $cacheInfo = $cacheInstance->getInfo($cacheKey); |
|
460 | - if($cacheInfo){ |
|
461 | - $lastModified = $cacheInfo['mtime']; |
|
462 | - $expire = $cacheInfo['expire']; |
|
463 | - $maxAge = $expire - time(); |
|
464 | - self::setHeader('Pragma', 'public'); |
|
465 | - self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
|
466 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
467 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
468 | - } |
|
469 | - } |
|
458 | + //get the cache information to prepare header to send to browser |
|
459 | + $cacheInfo = $cacheInstance->getInfo($cacheKey); |
|
460 | + if($cacheInfo){ |
|
461 | + $lastModified = $cacheInfo['mtime']; |
|
462 | + $expire = $cacheInfo['expire']; |
|
463 | + $maxAge = $expire - time(); |
|
464 | + self::setHeader('Pragma', 'public'); |
|
465 | + self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
|
466 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
467 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
468 | + } |
|
469 | + } |
|
470 | 470 | |
471 | 471 | |
472 | - /** |
|
473 | - * Get the module information for the view to load |
|
474 | - * @param string $view the view name like moduleName/viewName, viewName |
|
475 | - * |
|
476 | - * @return array the module information |
|
477 | - * array( |
|
478 | - * 'module'=> 'module_name' |
|
479 | - * 'view' => 'view_name' |
|
480 | - * 'viewFile' => 'view_file' |
|
481 | - * ) |
|
482 | - */ |
|
483 | - protected function getModuleInfoForView($view){ |
|
484 | - $module = null; |
|
485 | - $viewFile = null; |
|
486 | - $obj = & get_instance(); |
|
487 | - //check if the request class contains module name |
|
488 | - if(strpos($view, '/') !== false){ |
|
489 | - $viewPath = explode('/', $view); |
|
490 | - if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
491 | - $module = $viewPath[0]; |
|
492 | - array_shift($viewPath); |
|
493 | - $view = implode('/', $viewPath); |
|
494 | - $viewFile = $view . '.php'; |
|
495 | - } |
|
496 | - } |
|
497 | - if(! $module && !empty($obj->moduleName)){ |
|
498 | - $module = $obj->moduleName; |
|
499 | - } |
|
500 | - return array( |
|
501 | - 'view' => $view, |
|
502 | - 'module' => $module, |
|
503 | - 'viewFile' => $viewFile |
|
504 | - ); |
|
505 | - } |
|
472 | + /** |
|
473 | + * Get the module information for the view to load |
|
474 | + * @param string $view the view name like moduleName/viewName, viewName |
|
475 | + * |
|
476 | + * @return array the module information |
|
477 | + * array( |
|
478 | + * 'module'=> 'module_name' |
|
479 | + * 'view' => 'view_name' |
|
480 | + * 'viewFile' => 'view_file' |
|
481 | + * ) |
|
482 | + */ |
|
483 | + protected function getModuleInfoForView($view){ |
|
484 | + $module = null; |
|
485 | + $viewFile = null; |
|
486 | + $obj = & get_instance(); |
|
487 | + //check if the request class contains module name |
|
488 | + if(strpos($view, '/') !== false){ |
|
489 | + $viewPath = explode('/', $view); |
|
490 | + if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
491 | + $module = $viewPath[0]; |
|
492 | + array_shift($viewPath); |
|
493 | + $view = implode('/', $viewPath); |
|
494 | + $viewFile = $view . '.php'; |
|
495 | + } |
|
496 | + } |
|
497 | + if(! $module && !empty($obj->moduleName)){ |
|
498 | + $module = $obj->moduleName; |
|
499 | + } |
|
500 | + return array( |
|
501 | + 'view' => $view, |
|
502 | + 'module' => $module, |
|
503 | + 'viewFile' => $viewFile |
|
504 | + ); |
|
505 | + } |
|
506 | 506 | |
507 | - /** |
|
508 | - * Render the view page |
|
509 | - * @see Response::render |
|
510 | - * @return void|string |
|
511 | - */ |
|
512 | - protected function loadView($path, array $data = array(), $return = false){ |
|
513 | - $found = false; |
|
514 | - if(file_exists($path)){ |
|
515 | - //super instance |
|
516 | - $obj = & get_instance(); |
|
517 | - foreach(get_object_vars($obj) as $key => $value){ |
|
518 | - if(! isset($this->{$key})){ |
|
519 | - $this->{$key} = & $obj->{$key}; |
|
520 | - } |
|
521 | - } |
|
522 | - ob_start(); |
|
523 | - extract($data); |
|
524 | - //need use require() instead of require_once because can load this view many time |
|
525 | - require $path; |
|
526 | - $content = ob_get_clean(); |
|
527 | - if($return){ |
|
528 | - return $content; |
|
529 | - } |
|
530 | - $this->_pageRender .= $content; |
|
531 | - $found = true; |
|
532 | - } |
|
533 | - if(! $found){ |
|
534 | - show_error('Unable to find view [' .$view . ']'); |
|
535 | - } |
|
536 | - } |
|
507 | + /** |
|
508 | + * Render the view page |
|
509 | + * @see Response::render |
|
510 | + * @return void|string |
|
511 | + */ |
|
512 | + protected function loadView($path, array $data = array(), $return = false){ |
|
513 | + $found = false; |
|
514 | + if(file_exists($path)){ |
|
515 | + //super instance |
|
516 | + $obj = & get_instance(); |
|
517 | + foreach(get_object_vars($obj) as $key => $value){ |
|
518 | + if(! isset($this->{$key})){ |
|
519 | + $this->{$key} = & $obj->{$key}; |
|
520 | + } |
|
521 | + } |
|
522 | + ob_start(); |
|
523 | + extract($data); |
|
524 | + //need use require() instead of require_once because can load this view many time |
|
525 | + require $path; |
|
526 | + $content = ob_get_clean(); |
|
527 | + if($return){ |
|
528 | + return $content; |
|
529 | + } |
|
530 | + $this->_pageRender .= $content; |
|
531 | + $found = true; |
|
532 | + } |
|
533 | + if(! $found){ |
|
534 | + show_error('Unable to find view [' .$view . ']'); |
|
535 | + } |
|
536 | + } |
|
537 | 537 | |
538 | - } |
|
538 | + } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Response{ |
|
27 | + class Response { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of request header to send with response |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Construct new response instance |
67 | 67 | */ |
68 | - public function __construct(){ |
|
68 | + public function __construct() { |
|
69 | 69 | $currentUrl = ''; |
70 | - if (! empty($_SERVER['REQUEST_URI'])){ |
|
70 | + if (!empty($_SERVER['REQUEST_URI'])) { |
|
71 | 71 | $currentUrl = $_SERVER['REQUEST_URI']; |
72 | 72 | } |
73 | - if (! empty($_SERVER['QUERY_STRING'])){ |
|
73 | + if (!empty($_SERVER['QUERY_STRING'])) { |
|
74 | 74 | $currentUrl .= '?' . $_SERVER['QUERY_STRING']; |
75 | 75 | } |
76 | - $this->_currentUrl = $currentUrl; |
|
76 | + $this->_currentUrl = $currentUrl; |
|
77 | 77 | |
78 | 78 | $this->_currentUrlCacheKey = md5($this->_currentUrl); |
79 | 79 | |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * The signleton of the logger |
90 | 90 | * @return Object the Log instance |
91 | 91 | */ |
92 | - public static function getLogger(){ |
|
93 | - if(self::$logger == null){ |
|
92 | + public static function getLogger() { |
|
93 | + if (self::$logger == null) { |
|
94 | 94 | $logger = array(); |
95 | - $logger[0] =& class_loader('Log', 'classes'); |
|
95 | + $logger[0] = & class_loader('Log', 'classes'); |
|
96 | 96 | $logger[0]->setLogger('Library::Response'); |
97 | 97 | self::$logger = $logger[0]; |
98 | 98 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param object $logger the log object |
105 | 105 | * @return object the log instance |
106 | 106 | */ |
107 | - public static function setLogger($logger){ |
|
107 | + public static function setLogger($logger) { |
|
108 | 108 | self::$logger = $logger; |
109 | 109 | return self::$logger; |
110 | 110 | } |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * @param integer $httpCode the HTTP status code |
116 | 116 | * @param array $headers the additional headers to add to the existing headers list |
117 | 117 | */ |
118 | - public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
118 | + public static function sendHeaders($httpCode = 200, array $headers = array()) { |
|
119 | 119 | set_http_status_header($httpCode); |
120 | 120 | self::setHeaders($headers); |
121 | - if(! headers_sent()){ |
|
122 | - foreach(self::getHeaders() as $key => $value){ |
|
123 | - header($key .': '.$value); |
|
121 | + if (!headers_sent()) { |
|
122 | + foreach (self::getHeaders() as $key => $value) { |
|
123 | + header($key . ': ' . $value); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * Get the list of the headers |
130 | 130 | * @return array the headers list |
131 | 131 | */ |
132 | - public static function getHeaders(){ |
|
132 | + public static function getHeaders() { |
|
133 | 133 | return self::$headers; |
134 | 134 | } |
135 | 135 | |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | * @param string $name the header name |
139 | 139 | * @return string|null the header value |
140 | 140 | */ |
141 | - public static function getHeader($name){ |
|
142 | - if(array_key_exists($name, self::$headers)){ |
|
141 | + public static function getHeader($name) { |
|
142 | + if (array_key_exists($name, self::$headers)) { |
|
143 | 143 | return self::$headers[$name]; |
144 | 144 | } |
145 | 145 | return null; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param string $name the header name |
152 | 152 | * @param string $value the header value to be set |
153 | 153 | */ |
154 | - public static function setHeader($name, $value){ |
|
154 | + public static function setHeader($name, $value) { |
|
155 | 155 | self::$headers[$name] = $value; |
156 | 156 | } |
157 | 157 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param array $headers the list of the headers to set. |
161 | 161 | * Note: this will merge with the existing headers |
162 | 162 | */ |
163 | - public static function setHeaders(array $headers){ |
|
163 | + public static function setHeaders(array $headers) { |
|
164 | 164 | self::$headers = array_merge(self::getHeaders(), $headers); |
165 | 165 | } |
166 | 166 | |
@@ -168,16 +168,16 @@ discard block |
||
168 | 168 | * Redirect user to the specified page |
169 | 169 | * @param string $path the URL or URI to be redirect to |
170 | 170 | */ |
171 | - public static function redirect($path = ''){ |
|
171 | + public static function redirect($path = '') { |
|
172 | 172 | $logger = self::getLogger(); |
173 | 173 | $url = Url::site_url($path); |
174 | - $logger->info('Redirect to URL [' .$url. ']'); |
|
175 | - if(! headers_sent()){ |
|
176 | - header('Location: '.$url); |
|
174 | + $logger->info('Redirect to URL [' . $url . ']'); |
|
175 | + if (!headers_sent()) { |
|
176 | + header('Location: ' . $url); |
|
177 | 177 | exit; |
178 | 178 | } |
179 | 179 | echo '<script> |
180 | - location.href = "'.$url.'"; |
|
180 | + location.href = "'.$url . '"; |
|
181 | 181 | </script>'; |
182 | 182 | } |
183 | 183 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return void|string if $return is true will return the view content otherwise |
190 | 190 | * will display the view content. |
191 | 191 | */ |
192 | - public function render($view, $data = null, $return = false){ |
|
192 | + public function render($view, $data = null, $return = false) { |
|
193 | 193 | $logger = self::getLogger(); |
194 | 194 | //convert data to an array |
195 | 195 | $data = (array) $data; |
@@ -202,23 +202,23 @@ discard block |
||
202 | 202 | $logger->debug('Checking the view [' . $view . '] from module list ...'); |
203 | 203 | $moduleInfo = self::getModuleInfoForView($view); |
204 | 204 | $module = $moduleInfo['module']; |
205 | - $view = $moduleInfo['view']; |
|
206 | - if(! empty($moduleInfo['viewFile'])){ |
|
205 | + $view = $moduleInfo['view']; |
|
206 | + if (!empty($moduleInfo['viewFile'])) { |
|
207 | 207 | $viewFile = $moduleInfo['viewFile']; |
208 | 208 | } |
209 | 209 | $moduleViewPath = Module::findViewFullPath($view, $module); |
210 | - if($moduleViewPath){ |
|
210 | + if ($moduleViewPath) { |
|
211 | 211 | $path = $moduleViewPath; |
212 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
212 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $moduleViewPath . '] we will used it'); |
|
213 | 213 | } |
214 | - else{ |
|
215 | - $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location'); |
|
214 | + else { |
|
215 | + $logger->info('Cannot find view [' . $view . '] in module [' . $module . '] using the default location'); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | $logger->info('The view file path to be loaded is [' . $path . ']'); |
219 | 219 | |
220 | 220 | ///////// |
221 | - if($return){ |
|
221 | + if ($return) { |
|
222 | 222 | return $this->loadView($path, $data, true); |
223 | 223 | } |
224 | 224 | $this->loadView($path, $data, false); |
@@ -228,28 +228,28 @@ discard block |
||
228 | 228 | /** |
229 | 229 | * Send the final page output to user |
230 | 230 | */ |
231 | - public function renderFinalPage(){ |
|
231 | + public function renderFinalPage() { |
|
232 | 232 | $logger = self::getLogger(); |
233 | 233 | $obj = & get_instance(); |
234 | 234 | $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
235 | 235 | $dispatcher = $obj->eventdispatcher; |
236 | 236 | $content = $this->_pageRender; |
237 | - if(! $content){ |
|
237 | + if (!$content) { |
|
238 | 238 | $logger->warning('The final view content is empty.'); |
239 | 239 | return; |
240 | 240 | } |
241 | 241 | //dispatch |
242 | 242 | $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true)); |
243 | 243 | $content = null; |
244 | - if(! empty($event->payload)){ |
|
244 | + if (!empty($event->payload)) { |
|
245 | 245 | $content = $event->payload; |
246 | 246 | } |
247 | - if(empty($content)){ |
|
247 | + if (empty($content)) { |
|
248 | 248 | $logger->warning('The view content is empty after dispatch to event listeners.'); |
249 | 249 | } |
250 | 250 | |
251 | 251 | //check whether need save the page into cache. |
252 | - if($cachePageStatus){ |
|
252 | + if ($cachePageStatus) { |
|
253 | 253 | $this->savePageContentIntoCache($content); |
254 | 254 | } |
255 | 255 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | |
262 | 262 | //compress the output if is available |
263 | 263 | $type = null; |
264 | - if (self::$_canCompressOutput){ |
|
264 | + if (self::$_canCompressOutput) { |
|
265 | 265 | $type = 'ob_gzhandler'; |
266 | 266 | } |
267 | 267 | ob_start($type); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * |
278 | 278 | * @return boolean whether the page content if available or not |
279 | 279 | */ |
280 | - public function renderFinalPageFromCache(&$cache){ |
|
280 | + public function renderFinalPageFromCache(&$cache) { |
|
281 | 281 | $logger = self::getLogger(); |
282 | 282 | //the current page cache key for identification |
283 | 283 | $pageCacheKey = $this->_currentUrlCacheKey; |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | $logger->debug('Checking if the page content for the URL [' . $this->_currentUrl . '] is cached ...'); |
286 | 286 | //get the cache information to prepare header to send to browser |
287 | 287 | $cacheInfo = $cache->getInfo($pageCacheKey); |
288 | - if($cacheInfo){ |
|
288 | + if ($cacheInfo) { |
|
289 | 289 | $status = $this->sendCacheNotYetExpireInfo($cacheInfo); |
290 | - if($status === false){ |
|
290 | + if ($status === false) { |
|
291 | 291 | return $this->sendPageContentToBrowser($cache); |
292 | 292 | } |
293 | 293 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * Get the final page to be rendered |
300 | 300 | * @return string |
301 | 301 | */ |
302 | - public function getFinalPageRendered(){ |
|
302 | + public function getFinalPageRendered() { |
|
303 | 303 | return $this->_pageRender; |
304 | 304 | } |
305 | 305 | |
@@ -307,14 +307,14 @@ discard block |
||
307 | 307 | * Send the HTTP 404 error if can not found the |
308 | 308 | * routing information for the current request |
309 | 309 | */ |
310 | - public static function send404(){ |
|
310 | + public static function send404() { |
|
311 | 311 | /********* for logs **************/ |
312 | 312 | //can't use $obj = & get_instance() here because the global super object will be available until |
313 | 313 | //the main controller is loaded even for Loader::library('xxxx'); |
314 | 314 | $logger = self::getLogger(); |
315 | - $request =& class_loader('Request', 'classes'); |
|
316 | - $userAgent =& class_loader('Browser'); |
|
317 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
315 | + $request = & class_loader('Request', 'classes'); |
|
316 | + $userAgent = & class_loader('Browser'); |
|
317 | + $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion(); |
|
318 | 318 | |
319 | 319 | //here can't use Loader::functions just include the helper manually |
320 | 320 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | $logger->error($str); |
325 | 325 | /***********************************/ |
326 | 326 | $path = CORE_VIEWS_PATH . '404.php'; |
327 | - if(file_exists($path)){ |
|
327 | + if (file_exists($path)) { |
|
328 | 328 | //compress the output if is available |
329 | 329 | $type = null; |
330 | - if (self::$_canCompressOutput){ |
|
330 | + if (self::$_canCompressOutput) { |
|
331 | 331 | $type = 'ob_gzhandler'; |
332 | 332 | } |
333 | 333 | ob_start($type); |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | self::sendHeaders(404); |
337 | 337 | echo $output; |
338 | 338 | } |
339 | - else{ |
|
340 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
339 | + else { |
|
340 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
@@ -345,12 +345,12 @@ discard block |
||
345 | 345 | * Display the error to user |
346 | 346 | * @param array $data the error information |
347 | 347 | */ |
348 | - public static function sendError(array $data = array()){ |
|
348 | + public static function sendError(array $data = array()) { |
|
349 | 349 | $path = CORE_VIEWS_PATH . 'errors.php'; |
350 | - if(file_exists($path)){ |
|
350 | + if (file_exists($path)) { |
|
351 | 351 | //compress the output if is available |
352 | 352 | $type = null; |
353 | - if (self::$_canCompressOutput){ |
|
353 | + if (self::$_canCompressOutput) { |
|
354 | 354 | $type = 'ob_gzhandler'; |
355 | 355 | } |
356 | 356 | ob_start($type); |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | self::sendHeaders(503); |
361 | 361 | echo $output; |
362 | 362 | } |
363 | - else{ |
|
363 | + else { |
|
364 | 364 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
365 | 365 | set_http_status_header(503); |
366 | 366 | echo 'The error view [' . $path . '] does not exist'; |
@@ -372,17 +372,17 @@ discard block |
||
372 | 372 | * @param array $cacheInfo the cache information |
373 | 373 | * @return boolean true if the information is sent otherwise false |
374 | 374 | */ |
375 | - protected function sendCacheNotYetExpireInfo($cacheInfo){ |
|
376 | - if(! empty($cacheInfo)){ |
|
375 | + protected function sendCacheNotYetExpireInfo($cacheInfo) { |
|
376 | + if (!empty($cacheInfo)) { |
|
377 | 377 | $logger = self::getLogger(); |
378 | 378 | $lastModified = $cacheInfo['mtime']; |
379 | 379 | $expire = $cacheInfo['expire']; |
380 | 380 | $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
381 | 381 | self::setHeader('Pragma', 'public'); |
382 | 382 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
383 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
384 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
385 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
383 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
384 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
385 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { |
|
386 | 386 | $logger->info('The cache page content is not yet expire for the URL [' . $this->_currentUrl . '] send 304 header to browser'); |
387 | 387 | self::sendHeaders(304); |
388 | 388 | return true; |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @param object $cache the cache instance |
397 | 397 | * @return boolean the status of the operation |
398 | 398 | */ |
399 | - protected function sendPageContentToBrowser(&$cache){ |
|
399 | + protected function sendPageContentToBrowser(&$cache) { |
|
400 | 400 | $logger = self::getLogger(); |
401 | 401 | $logger->info('The cache page content is expired or the browser doesn\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $this->_currentUrl . '] send cache headers to tell the browser'); |
402 | 402 | self::sendHeaders(200); |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | $pageCacheKey = $this->_currentUrlCacheKey; |
405 | 405 | //get the cache content |
406 | 406 | $content = $cache->get($pageCacheKey); |
407 | - if($content){ |
|
407 | + if ($content) { |
|
408 | 408 | $logger->info('The page content for the URL [' . $this->_currentUrl . '] already cached just display it'); |
409 | 409 | //load benchmark class |
410 | 410 | $benchmark = & class_loader('Benchmark'); |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | ///display the final output |
419 | 419 | //compress the output if is available |
420 | 420 | $type = null; |
421 | - if (self::$_canCompressOutput){ |
|
421 | + if (self::$_canCompressOutput) { |
|
422 | 422 | $type = 'ob_gzhandler'; |
423 | 423 | } |
424 | 424 | ob_start($type); |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * @param string $content the page content to be saved |
437 | 437 | * @return void |
438 | 438 | */ |
439 | - protected function savePageContentIntoCache($content){ |
|
439 | + protected function savePageContentIntoCache($content) { |
|
440 | 440 | $obj = & get_instance(); |
441 | 441 | $logger = self::getLogger(); |
442 | 442 | |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $url = $this->_currentUrl; |
445 | 445 | //Cache view Time to live in second |
446 | 446 | $viewCacheTtl = get_config('cache_ttl'); |
447 | - if (!empty($obj->view_cache_ttl)){ |
|
447 | + if (!empty($obj->view_cache_ttl)) { |
|
448 | 448 | $viewCacheTtl = $obj->view_cache_ttl; |
449 | 449 | } |
450 | 450 | //the cache handler instance |
@@ -457,14 +457,14 @@ discard block |
||
457 | 457 | |
458 | 458 | //get the cache information to prepare header to send to browser |
459 | 459 | $cacheInfo = $cacheInstance->getInfo($cacheKey); |
460 | - if($cacheInfo){ |
|
460 | + if ($cacheInfo) { |
|
461 | 461 | $lastModified = $cacheInfo['mtime']; |
462 | 462 | $expire = $cacheInfo['expire']; |
463 | 463 | $maxAge = $expire - time(); |
464 | 464 | self::setHeader('Pragma', 'public'); |
465 | 465 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
466 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
467 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
466 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
467 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
@@ -480,21 +480,21 @@ discard block |
||
480 | 480 | * 'viewFile' => 'view_file' |
481 | 481 | * ) |
482 | 482 | */ |
483 | - protected function getModuleInfoForView($view){ |
|
483 | + protected function getModuleInfoForView($view) { |
|
484 | 484 | $module = null; |
485 | 485 | $viewFile = null; |
486 | 486 | $obj = & get_instance(); |
487 | 487 | //check if the request class contains module name |
488 | - if(strpos($view, '/') !== false){ |
|
488 | + if (strpos($view, '/') !== false) { |
|
489 | 489 | $viewPath = explode('/', $view); |
490 | - if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
490 | + if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) { |
|
491 | 491 | $module = $viewPath[0]; |
492 | 492 | array_shift($viewPath); |
493 | 493 | $view = implode('/', $viewPath); |
494 | 494 | $viewFile = $view . '.php'; |
495 | 495 | } |
496 | 496 | } |
497 | - if(! $module && !empty($obj->moduleName)){ |
|
497 | + if (!$module && !empty($obj->moduleName)) { |
|
498 | 498 | $module = $obj->moduleName; |
499 | 499 | } |
500 | 500 | return array( |
@@ -509,13 +509,13 @@ discard block |
||
509 | 509 | * @see Response::render |
510 | 510 | * @return void|string |
511 | 511 | */ |
512 | - protected function loadView($path, array $data = array(), $return = false){ |
|
512 | + protected function loadView($path, array $data = array(), $return = false) { |
|
513 | 513 | $found = false; |
514 | - if(file_exists($path)){ |
|
514 | + if (file_exists($path)) { |
|
515 | 515 | //super instance |
516 | 516 | $obj = & get_instance(); |
517 | - foreach(get_object_vars($obj) as $key => $value){ |
|
518 | - if(! isset($this->{$key})){ |
|
517 | + foreach (get_object_vars($obj) as $key => $value) { |
|
518 | + if (!isset($this->{$key})) { |
|
519 | 519 | $this->{$key} = & $obj->{$key}; |
520 | 520 | } |
521 | 521 | } |
@@ -524,14 +524,14 @@ discard block |
||
524 | 524 | //need use require() instead of require_once because can load this view many time |
525 | 525 | require $path; |
526 | 526 | $content = ob_get_clean(); |
527 | - if($return){ |
|
527 | + if ($return) { |
|
528 | 528 | return $content; |
529 | 529 | } |
530 | 530 | $this->_pageRender .= $content; |
531 | 531 | $found = true; |
532 | 532 | } |
533 | - if(! $found){ |
|
534 | - show_error('Unable to find view [' .$view . ']'); |
|
533 | + if (!$found) { |
|
534 | + show_error('Unable to find view [' . $view . ']'); |
|
535 | 535 | } |
536 | 536 | } |
537 | 537 |
@@ -210,8 +210,7 @@ discard block |
||
210 | 210 | if($moduleViewPath){ |
211 | 211 | $path = $moduleViewPath; |
212 | 212 | $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$moduleViewPath. '] we will used it'); |
213 | - } |
|
214 | - else{ |
|
213 | + } else{ |
|
215 | 214 | $logger->info('Cannot find view [' . $view . '] in module [' .$module. '] using the default location'); |
216 | 215 | } |
217 | 216 | |
@@ -335,8 +334,7 @@ discard block |
||
335 | 334 | $output = ob_get_clean(); |
336 | 335 | self::sendHeaders(404); |
337 | 336 | echo $output; |
338 | - } |
|
339 | - else{ |
|
337 | + } else{ |
|
340 | 338 | show_error('The 404 view [' .$path. '] does not exist'); |
341 | 339 | } |
342 | 340 | } |
@@ -359,8 +357,7 @@ discard block |
||
359 | 357 | $output = ob_get_clean(); |
360 | 358 | self::sendHeaders(503); |
361 | 359 | echo $output; |
362 | - } |
|
363 | - else{ |
|
360 | + } else{ |
|
364 | 361 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
365 | 362 | set_http_status_header(503); |
366 | 363 | echo 'The error view [' . $path . '] does not exist'; |
@@ -1,657 +1,657 @@ |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
3 | - /** |
|
4 | - * TNH Framework |
|
5 | - * |
|
6 | - * A simple PHP framework using HMVC architecture |
|
7 | - * |
|
8 | - * This content is released under the GNU GPL License (GPL) |
|
9 | - * |
|
10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
11 | - * |
|
12 | - * This program is free software; you can redistribute it and/or |
|
13 | - * modify it under the terms of the GNU General Public License |
|
14 | - * as published by the Free Software Foundation; either version 3 |
|
15 | - * of the License, or (at your option) any later version. |
|
16 | - * |
|
17 | - * This program is distributed in the hope that it will be useful, |
|
18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | - * GNU General Public License for more details. |
|
21 | - * |
|
22 | - * You should have received a copy of the GNU General Public License |
|
23 | - * along with this program; if not, write to the Free Software |
|
24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | - */ |
|
26 | - class Loader{ |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | + /** |
|
4 | + * TNH Framework |
|
5 | + * |
|
6 | + * A simple PHP framework using HMVC architecture |
|
7 | + * |
|
8 | + * This content is released under the GNU GPL License (GPL) |
|
9 | + * |
|
10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
11 | + * |
|
12 | + * This program is free software; you can redistribute it and/or |
|
13 | + * modify it under the terms of the GNU General Public License |
|
14 | + * as published by the Free Software Foundation; either version 3 |
|
15 | + * of the License, or (at your option) any later version. |
|
16 | + * |
|
17 | + * This program is distributed in the hope that it will be useful, |
|
18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | + * GNU General Public License for more details. |
|
21 | + * |
|
22 | + * You should have received a copy of the GNU General Public License |
|
23 | + * along with this program; if not, write to the Free Software |
|
24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
25 | + */ |
|
26 | + class Loader{ |
|
27 | 27 | |
28 | - /** |
|
29 | - * List of loaded resources |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - public static $loaded = array(); |
|
28 | + /** |
|
29 | + * List of loaded resources |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + public static $loaded = array(); |
|
33 | 33 | |
34 | - /** |
|
35 | - * The logger instance |
|
36 | - * @var object |
|
37 | - */ |
|
38 | - private static $logger; |
|
34 | + /** |
|
35 | + * The logger instance |
|
36 | + * @var object |
|
37 | + */ |
|
38 | + private static $logger; |
|
39 | 39 | |
40 | 40 | |
41 | - public function __construct(){ |
|
42 | - //add the resources already loaded during application bootstrap |
|
43 | - //in the list to prevent duplicate or loading the resources again. |
|
44 | - static::$loaded = class_loaded(); |
|
41 | + public function __construct(){ |
|
42 | + //add the resources already loaded during application bootstrap |
|
43 | + //in the list to prevent duplicate or loading the resources again. |
|
44 | + static::$loaded = class_loaded(); |
|
45 | 45 | |
46 | - //Load resources from autoload configuration |
|
47 | - $this->loadResourcesFromAutoloadConfig(); |
|
48 | - } |
|
46 | + //Load resources from autoload configuration |
|
47 | + $this->loadResourcesFromAutoloadConfig(); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * The signleton of the logger |
|
52 | - * @return object the Log instance |
|
53 | - */ |
|
54 | - public static function getLogger(){ |
|
55 | - if(self::$logger == null){ |
|
56 | - $logger = array(); |
|
57 | - $logger[0] =& class_loader('Log', 'classes'); |
|
58 | - $logger[0]->setLogger('Library::Loader'); |
|
59 | - self::$logger = $logger[0]; |
|
60 | - } |
|
61 | - return self::$logger; |
|
62 | - } |
|
50 | + /** |
|
51 | + * The signleton of the logger |
|
52 | + * @return object the Log instance |
|
53 | + */ |
|
54 | + public static function getLogger(){ |
|
55 | + if(self::$logger == null){ |
|
56 | + $logger = array(); |
|
57 | + $logger[0] =& class_loader('Log', 'classes'); |
|
58 | + $logger[0]->setLogger('Library::Loader'); |
|
59 | + self::$logger = $logger[0]; |
|
60 | + } |
|
61 | + return self::$logger; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Set the log instance for future use |
|
66 | - * @param object $logger the log object |
|
67 | - * @return object the log instance |
|
68 | - */ |
|
69 | - public static function setLogger($logger){ |
|
70 | - self::$logger = $logger; |
|
71 | - return self::$logger; |
|
72 | - } |
|
64 | + /** |
|
65 | + * Set the log instance for future use |
|
66 | + * @param object $logger the log object |
|
67 | + * @return object the log instance |
|
68 | + */ |
|
69 | + public static function setLogger($logger){ |
|
70 | + self::$logger = $logger; |
|
71 | + return self::$logger; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * Load the model class |
|
77 | - * |
|
78 | - * @param string $class the class name to be loaded |
|
79 | - * @param string $instance the name of the instance to use in super object |
|
80 | - * |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public static function model($class, $instance = null){ |
|
84 | - $logger = static::getLogger(); |
|
85 | - $class = str_ireplace('.php', '', $class); |
|
86 | - $class = trim($class, '/\\'); |
|
87 | - $file = ucfirst($class).'.php'; |
|
88 | - $logger->debug('Loading model [' . $class . '] ...'); |
|
89 | - //************ |
|
90 | - if (! $instance){ |
|
91 | - $instance = self::getModelLibraryInstanceName($class); |
|
92 | - } |
|
93 | - //**************** |
|
94 | - if (isset(static::$loaded[$instance])){ |
|
95 | - $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
96 | - return; |
|
97 | - } |
|
98 | - $classFilePath = APPS_MODEL_PATH . $file; |
|
99 | - //first check if this model is in the module |
|
100 | - $logger->debug('Checking model [' . $class . '] from module list ...'); |
|
101 | - //check if the request class contains module name |
|
102 | - $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
103 | - $module = $moduleInfo['module']; |
|
104 | - $class = $moduleInfo['class']; |
|
75 | + /** |
|
76 | + * Load the model class |
|
77 | + * |
|
78 | + * @param string $class the class name to be loaded |
|
79 | + * @param string $instance the name of the instance to use in super object |
|
80 | + * |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public static function model($class, $instance = null){ |
|
84 | + $logger = static::getLogger(); |
|
85 | + $class = str_ireplace('.php', '', $class); |
|
86 | + $class = trim($class, '/\\'); |
|
87 | + $file = ucfirst($class).'.php'; |
|
88 | + $logger->debug('Loading model [' . $class . '] ...'); |
|
89 | + //************ |
|
90 | + if (! $instance){ |
|
91 | + $instance = self::getModelLibraryInstanceName($class); |
|
92 | + } |
|
93 | + //**************** |
|
94 | + if (isset(static::$loaded[$instance])){ |
|
95 | + $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
96 | + return; |
|
97 | + } |
|
98 | + $classFilePath = APPS_MODEL_PATH . $file; |
|
99 | + //first check if this model is in the module |
|
100 | + $logger->debug('Checking model [' . $class . '] from module list ...'); |
|
101 | + //check if the request class contains module name |
|
102 | + $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
103 | + $module = $moduleInfo['module']; |
|
104 | + $class = $moduleInfo['class']; |
|
105 | 105 | |
106 | - $moduleModelFilePath = Module::findModelFullPath($class, $module); |
|
107 | - if ($moduleModelFilePath){ |
|
108 | - $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
109 | - $classFilePath = $moduleModelFilePath; |
|
110 | - } |
|
111 | - else{ |
|
112 | - $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
|
113 | - } |
|
114 | - $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
|
115 | - if (file_exists($classFilePath)){ |
|
116 | - require_once $classFilePath; |
|
117 | - if (class_exists($class)){ |
|
118 | - $c = new $class(); |
|
119 | - $obj = & get_instance(); |
|
120 | - $obj->{$instance} = $c; |
|
121 | - static::$loaded[$instance] = $class; |
|
122 | - $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
|
123 | - } |
|
124 | - else{ |
|
125 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
126 | - } |
|
127 | - } |
|
128 | - else{ |
|
129 | - show_error('Unable to find the model [' . $class . ']'); |
|
130 | - } |
|
131 | - } |
|
106 | + $moduleModelFilePath = Module::findModelFullPath($class, $module); |
|
107 | + if ($moduleModelFilePath){ |
|
108 | + $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
109 | + $classFilePath = $moduleModelFilePath; |
|
110 | + } |
|
111 | + else{ |
|
112 | + $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
|
113 | + } |
|
114 | + $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
|
115 | + if (file_exists($classFilePath)){ |
|
116 | + require_once $classFilePath; |
|
117 | + if (class_exists($class)){ |
|
118 | + $c = new $class(); |
|
119 | + $obj = & get_instance(); |
|
120 | + $obj->{$instance} = $c; |
|
121 | + static::$loaded[$instance] = $class; |
|
122 | + $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
|
123 | + } |
|
124 | + else{ |
|
125 | + show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
126 | + } |
|
127 | + } |
|
128 | + else{ |
|
129 | + show_error('Unable to find the model [' . $class . ']'); |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | 133 | |
134 | - /** |
|
135 | - * Load the library class |
|
136 | - * |
|
137 | - * @param string $class the library class name to be loaded |
|
138 | - * @param string $instance the instance name to use in super object |
|
139 | - * @param mixed $params the arguments to pass to the constructor |
|
140 | - * |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - public static function library($class, $instance = null, array $params = array()){ |
|
144 | - $logger = static::getLogger(); |
|
145 | - $class = str_ireplace('.php', '', $class); |
|
146 | - $class = trim($class, '/\\'); |
|
147 | - $file = ucfirst($class) .'.php'; |
|
148 | - $logger->debug('Loading library [' . $class . '] ...'); |
|
149 | - if (! $instance){ |
|
150 | - $instance = self::getModelLibraryInstanceName($class); |
|
151 | - } |
|
152 | - if (isset(static::$loaded[$instance])){ |
|
153 | - $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
154 | - return; |
|
155 | - } |
|
156 | - $obj = & get_instance(); |
|
157 | - //Check and load Database library |
|
158 | - if (strtolower($class) == 'database'){ |
|
159 | - $logger->info('This is the Database library ...'); |
|
160 | - $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
|
161 | - static::$loaded[$instance] = $class; |
|
162 | - $logger->info('Library Database loaded successfully.'); |
|
163 | - return; |
|
164 | - } |
|
165 | - $libraryFilePath = null; |
|
166 | - $logger->debug('Check if this is a system library ...'); |
|
167 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
168 | - $libraryFilePath = CORE_LIBRARY_PATH . $file; |
|
169 | - $class = ucfirst($class); |
|
170 | - $logger->info('This library is a system library'); |
|
171 | - } |
|
172 | - else{ |
|
173 | - $logger->info('This library is not a system library'); |
|
174 | - //first check if this library is in the module |
|
175 | - $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
|
176 | - //*************** |
|
177 | - } |
|
178 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
179 | - $libraryFilePath = LIBRARY_PATH . $file; |
|
180 | - } |
|
181 | - $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
|
182 | - //************************* |
|
183 | - self::loadLibrary($libraryFilePath, $class, $instance, $params); |
|
184 | - } |
|
134 | + /** |
|
135 | + * Load the library class |
|
136 | + * |
|
137 | + * @param string $class the library class name to be loaded |
|
138 | + * @param string $instance the instance name to use in super object |
|
139 | + * @param mixed $params the arguments to pass to the constructor |
|
140 | + * |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + public static function library($class, $instance = null, array $params = array()){ |
|
144 | + $logger = static::getLogger(); |
|
145 | + $class = str_ireplace('.php', '', $class); |
|
146 | + $class = trim($class, '/\\'); |
|
147 | + $file = ucfirst($class) .'.php'; |
|
148 | + $logger->debug('Loading library [' . $class . '] ...'); |
|
149 | + if (! $instance){ |
|
150 | + $instance = self::getModelLibraryInstanceName($class); |
|
151 | + } |
|
152 | + if (isset(static::$loaded[$instance])){ |
|
153 | + $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
154 | + return; |
|
155 | + } |
|
156 | + $obj = & get_instance(); |
|
157 | + //Check and load Database library |
|
158 | + if (strtolower($class) == 'database'){ |
|
159 | + $logger->info('This is the Database library ...'); |
|
160 | + $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
|
161 | + static::$loaded[$instance] = $class; |
|
162 | + $logger->info('Library Database loaded successfully.'); |
|
163 | + return; |
|
164 | + } |
|
165 | + $libraryFilePath = null; |
|
166 | + $logger->debug('Check if this is a system library ...'); |
|
167 | + if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
168 | + $libraryFilePath = CORE_LIBRARY_PATH . $file; |
|
169 | + $class = ucfirst($class); |
|
170 | + $logger->info('This library is a system library'); |
|
171 | + } |
|
172 | + else{ |
|
173 | + $logger->info('This library is not a system library'); |
|
174 | + //first check if this library is in the module |
|
175 | + $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
|
176 | + //*************** |
|
177 | + } |
|
178 | + if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
179 | + $libraryFilePath = LIBRARY_PATH . $file; |
|
180 | + } |
|
181 | + $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
|
182 | + //************************* |
|
183 | + self::loadLibrary($libraryFilePath, $class, $instance, $params); |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Load the helper |
|
188 | - * |
|
189 | - * @param string $function the helper name to be loaded |
|
190 | - * |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public static function functions($function){ |
|
194 | - $logger = static::getLogger(); |
|
195 | - $function = str_ireplace('.php', '', $function); |
|
196 | - $function = trim($function, '/\\'); |
|
197 | - $function = str_ireplace('function_', '', $function); |
|
198 | - $file = 'function_'.$function.'.php'; |
|
199 | - $logger->debug('Loading helper [' . $function . '] ...'); |
|
200 | - if (isset(static::$loaded['function_' . $function])){ |
|
201 | - $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
|
202 | - return; |
|
203 | - } |
|
204 | - $functionFilePath = null; |
|
205 | - //first check if this helper is in the module |
|
206 | - $logger->debug('Checking helper [' . $function . '] from module list ...'); |
|
207 | - $moduleInfo = self::getModuleInfoForFunction($function); |
|
208 | - $module = $moduleInfo['module']; |
|
209 | - $function = $moduleInfo['function']; |
|
210 | - if(! empty($moduleInfo['file'])){ |
|
211 | - $file = $moduleInfo['file']; |
|
212 | - } |
|
213 | - $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
|
214 | - if ($moduleFunctionPath){ |
|
215 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
216 | - $functionFilePath = $moduleFunctionPath; |
|
217 | - } |
|
218 | - else{ |
|
219 | - $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
|
220 | - } |
|
221 | - if (! $functionFilePath){ |
|
222 | - $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
|
223 | - foreach($searchDir as $dir){ |
|
224 | - $filePath = $dir . $file; |
|
225 | - if (file_exists($filePath)){ |
|
226 | - $functionFilePath = $filePath; |
|
227 | - //is already found not to continue |
|
228 | - break; |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
232 | - $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
|
233 | - if ($functionFilePath){ |
|
234 | - require_once $functionFilePath; |
|
235 | - static::$loaded['function_' . $function] = $functionFilePath; |
|
236 | - $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
|
237 | - } |
|
238 | - else{ |
|
239 | - show_error('Unable to find helper file [' . $file . ']'); |
|
240 | - } |
|
241 | - } |
|
186 | + /** |
|
187 | + * Load the helper |
|
188 | + * |
|
189 | + * @param string $function the helper name to be loaded |
|
190 | + * |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public static function functions($function){ |
|
194 | + $logger = static::getLogger(); |
|
195 | + $function = str_ireplace('.php', '', $function); |
|
196 | + $function = trim($function, '/\\'); |
|
197 | + $function = str_ireplace('function_', '', $function); |
|
198 | + $file = 'function_'.$function.'.php'; |
|
199 | + $logger->debug('Loading helper [' . $function . '] ...'); |
|
200 | + if (isset(static::$loaded['function_' . $function])){ |
|
201 | + $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
|
202 | + return; |
|
203 | + } |
|
204 | + $functionFilePath = null; |
|
205 | + //first check if this helper is in the module |
|
206 | + $logger->debug('Checking helper [' . $function . '] from module list ...'); |
|
207 | + $moduleInfo = self::getModuleInfoForFunction($function); |
|
208 | + $module = $moduleInfo['module']; |
|
209 | + $function = $moduleInfo['function']; |
|
210 | + if(! empty($moduleInfo['file'])){ |
|
211 | + $file = $moduleInfo['file']; |
|
212 | + } |
|
213 | + $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
|
214 | + if ($moduleFunctionPath){ |
|
215 | + $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
216 | + $functionFilePath = $moduleFunctionPath; |
|
217 | + } |
|
218 | + else{ |
|
219 | + $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
|
220 | + } |
|
221 | + if (! $functionFilePath){ |
|
222 | + $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
|
223 | + foreach($searchDir as $dir){ |
|
224 | + $filePath = $dir . $file; |
|
225 | + if (file_exists($filePath)){ |
|
226 | + $functionFilePath = $filePath; |
|
227 | + //is already found not to continue |
|
228 | + break; |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | + $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
|
233 | + if ($functionFilePath){ |
|
234 | + require_once $functionFilePath; |
|
235 | + static::$loaded['function_' . $function] = $functionFilePath; |
|
236 | + $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
|
237 | + } |
|
238 | + else{ |
|
239 | + show_error('Unable to find helper file [' . $file . ']'); |
|
240 | + } |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Load the configuration file |
|
245 | - * |
|
246 | - * @param string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config |
|
247 | - * |
|
248 | - * @return void |
|
249 | - */ |
|
250 | - public static function config($filename){ |
|
251 | - $logger = static::getLogger(); |
|
252 | - $filename = str_ireplace('.php', '', $filename); |
|
253 | - $filename = trim($filename, '/\\'); |
|
254 | - $filename = str_ireplace('config_', '', $filename); |
|
255 | - $file = 'config_'.$filename.'.php'; |
|
256 | - $logger->debug('Loading configuration [' . $filename . '] ...'); |
|
257 | - if (isset(static::$loaded['config_' . $filename])){ |
|
258 | - $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
|
259 | - return; |
|
260 | - } |
|
261 | - $configFilePath = CONFIG_PATH . $file; |
|
262 | - //first check if this config is in the module |
|
263 | - $logger->debug('Checking config [' . $filename . '] from module list ...'); |
|
264 | - $moduleInfo = self::getModuleInfoForConfig($filename); |
|
265 | - $module = $moduleInfo['module']; |
|
266 | - $filename = $moduleInfo['filename']; |
|
267 | - $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
|
268 | - if ($moduleConfigPath){ |
|
269 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
270 | - $configFilePath = $moduleConfigPath; |
|
271 | - } |
|
272 | - else{ |
|
273 | - $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
|
274 | - } |
|
275 | - $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
|
276 | - $config = array(); |
|
277 | - if (file_exists($configFilePath)){ |
|
278 | - require_once $configFilePath; |
|
279 | - if (! empty($config) && is_array($config)){ |
|
280 | - Config::setAll($config); |
|
281 | - static::$loaded['config_' . $filename] = $configFilePath; |
|
282 | - $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
|
283 | - $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
|
284 | - unset($config); |
|
285 | - } |
|
286 | - } |
|
287 | - else{ |
|
288 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
289 | - } |
|
290 | - } |
|
243 | + /** |
|
244 | + * Load the configuration file |
|
245 | + * |
|
246 | + * @param string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config |
|
247 | + * |
|
248 | + * @return void |
|
249 | + */ |
|
250 | + public static function config($filename){ |
|
251 | + $logger = static::getLogger(); |
|
252 | + $filename = str_ireplace('.php', '', $filename); |
|
253 | + $filename = trim($filename, '/\\'); |
|
254 | + $filename = str_ireplace('config_', '', $filename); |
|
255 | + $file = 'config_'.$filename.'.php'; |
|
256 | + $logger->debug('Loading configuration [' . $filename . '] ...'); |
|
257 | + if (isset(static::$loaded['config_' . $filename])){ |
|
258 | + $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
|
259 | + return; |
|
260 | + } |
|
261 | + $configFilePath = CONFIG_PATH . $file; |
|
262 | + //first check if this config is in the module |
|
263 | + $logger->debug('Checking config [' . $filename . '] from module list ...'); |
|
264 | + $moduleInfo = self::getModuleInfoForConfig($filename); |
|
265 | + $module = $moduleInfo['module']; |
|
266 | + $filename = $moduleInfo['filename']; |
|
267 | + $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
|
268 | + if ($moduleConfigPath){ |
|
269 | + $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
270 | + $configFilePath = $moduleConfigPath; |
|
271 | + } |
|
272 | + else{ |
|
273 | + $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
|
274 | + } |
|
275 | + $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
|
276 | + $config = array(); |
|
277 | + if (file_exists($configFilePath)){ |
|
278 | + require_once $configFilePath; |
|
279 | + if (! empty($config) && is_array($config)){ |
|
280 | + Config::setAll($config); |
|
281 | + static::$loaded['config_' . $filename] = $configFilePath; |
|
282 | + $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
|
283 | + $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
|
284 | + unset($config); |
|
285 | + } |
|
286 | + } |
|
287 | + else{ |
|
288 | + show_error('Unable to find config file ['. $configFilePath . ']'); |
|
289 | + } |
|
290 | + } |
|
291 | 291 | |
292 | 292 | |
293 | - /** |
|
294 | - * Load the language |
|
295 | - * |
|
296 | - * @param string $language the language name to be loaded |
|
297 | - * |
|
298 | - * @return void |
|
299 | - */ |
|
300 | - public static function lang($language){ |
|
301 | - $logger = static::getLogger(); |
|
302 | - $language = str_ireplace('.php', '', $language); |
|
303 | - $language = trim($language, '/\\'); |
|
304 | - $language = str_ireplace('lang_', '', $language); |
|
305 | - $file = 'lang_'.$language.'.php'; |
|
306 | - $logger->debug('Loading language [' . $language . '] ...'); |
|
307 | - if (isset(static::$loaded['lang_' . $language])){ |
|
308 | - $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
|
309 | - return; |
|
310 | - } |
|
311 | - //get the current language |
|
312 | - $appLang = self::getAppLang(); |
|
313 | - $languageFilePath = null; |
|
314 | - //first check if this language is in the module |
|
315 | - $logger->debug('Checking language [' . $language . '] from module list ...'); |
|
316 | - $moduleInfo = self::getModuleInfoForLanguage($language); |
|
317 | - $module = $moduleInfo['module']; |
|
318 | - $language = $moduleInfo['language']; |
|
319 | - if(! empty($moduleInfo['file'])){ |
|
320 | - $file = $moduleInfo['file']; |
|
321 | - } |
|
322 | - $moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang); |
|
323 | - if ($moduleLanguagePath){ |
|
324 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
325 | - $languageFilePath = $moduleLanguagePath; |
|
326 | - } |
|
327 | - else{ |
|
328 | - $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
|
329 | - } |
|
330 | - if (! $languageFilePath){ |
|
331 | - $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
|
332 | - foreach($searchDir as $dir){ |
|
333 | - $filePath = $dir . $appLang . DS . $file; |
|
334 | - if (file_exists($filePath)){ |
|
335 | - $languageFilePath = $filePath; |
|
336 | - //already found no need continue |
|
337 | - break; |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
|
342 | - self::loadLanguage($languageFilePath, $language); |
|
343 | - } |
|
293 | + /** |
|
294 | + * Load the language |
|
295 | + * |
|
296 | + * @param string $language the language name to be loaded |
|
297 | + * |
|
298 | + * @return void |
|
299 | + */ |
|
300 | + public static function lang($language){ |
|
301 | + $logger = static::getLogger(); |
|
302 | + $language = str_ireplace('.php', '', $language); |
|
303 | + $language = trim($language, '/\\'); |
|
304 | + $language = str_ireplace('lang_', '', $language); |
|
305 | + $file = 'lang_'.$language.'.php'; |
|
306 | + $logger->debug('Loading language [' . $language . '] ...'); |
|
307 | + if (isset(static::$loaded['lang_' . $language])){ |
|
308 | + $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
|
309 | + return; |
|
310 | + } |
|
311 | + //get the current language |
|
312 | + $appLang = self::getAppLang(); |
|
313 | + $languageFilePath = null; |
|
314 | + //first check if this language is in the module |
|
315 | + $logger->debug('Checking language [' . $language . '] from module list ...'); |
|
316 | + $moduleInfo = self::getModuleInfoForLanguage($language); |
|
317 | + $module = $moduleInfo['module']; |
|
318 | + $language = $moduleInfo['language']; |
|
319 | + if(! empty($moduleInfo['file'])){ |
|
320 | + $file = $moduleInfo['file']; |
|
321 | + } |
|
322 | + $moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang); |
|
323 | + if ($moduleLanguagePath){ |
|
324 | + $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
325 | + $languageFilePath = $moduleLanguagePath; |
|
326 | + } |
|
327 | + else{ |
|
328 | + $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
|
329 | + } |
|
330 | + if (! $languageFilePath){ |
|
331 | + $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
|
332 | + foreach($searchDir as $dir){ |
|
333 | + $filePath = $dir . $appLang . DS . $file; |
|
334 | + if (file_exists($filePath)){ |
|
335 | + $languageFilePath = $filePath; |
|
336 | + //already found no need continue |
|
337 | + break; |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
|
342 | + self::loadLanguage($languageFilePath, $language); |
|
343 | + } |
|
344 | 344 | |
345 | - /** |
|
346 | - * Return the current app language by default will use the value from cookie |
|
347 | - * if can not found will use the default value from configuration |
|
348 | - * @return string the app language like "en", "fr" |
|
349 | - */ |
|
350 | - protected static function getAppLang(){ |
|
351 | - //determine the current language |
|
352 | - $appLang = get_config('default_language'); |
|
353 | - //if the language exists in the cookie use it |
|
354 | - $cfgKey = get_config('language_cookie_name'); |
|
355 | - $objCookie = & class_loader('Cookie'); |
|
356 | - $cookieLang = $objCookie->get($cfgKey); |
|
357 | - if ($cookieLang){ |
|
358 | - $appLang = $cookieLang; |
|
359 | - } |
|
360 | - return $appLang; |
|
361 | - } |
|
362 | - /** |
|
363 | - * Get the module information for the model and library to load |
|
364 | - * @param string $class the full class name like moduleName/className, className, |
|
365 | - * @return array the module information |
|
366 | - * array( |
|
367 | - * 'module'=> 'module_name' |
|
368 | - * 'class' => 'class_name' |
|
369 | - * ) |
|
370 | - */ |
|
371 | - protected static function getModuleInfoForModelLibrary($class){ |
|
372 | - $module = null; |
|
373 | - $obj = & get_instance(); |
|
374 | - if (strpos($class, '/') !== false){ |
|
375 | - $path = explode('/', $class); |
|
376 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
377 | - $module = $path[0]; |
|
378 | - $class = ucfirst($path[1]); |
|
379 | - } |
|
380 | - } |
|
381 | - else{ |
|
382 | - $class = ucfirst($class); |
|
383 | - } |
|
384 | - if (! $module && !empty($obj->moduleName)){ |
|
385 | - $module = $obj->moduleName; |
|
386 | - } |
|
387 | - return array( |
|
388 | - 'class' => $class, |
|
389 | - 'module' => $module |
|
390 | - ); |
|
391 | - } |
|
345 | + /** |
|
346 | + * Return the current app language by default will use the value from cookie |
|
347 | + * if can not found will use the default value from configuration |
|
348 | + * @return string the app language like "en", "fr" |
|
349 | + */ |
|
350 | + protected static function getAppLang(){ |
|
351 | + //determine the current language |
|
352 | + $appLang = get_config('default_language'); |
|
353 | + //if the language exists in the cookie use it |
|
354 | + $cfgKey = get_config('language_cookie_name'); |
|
355 | + $objCookie = & class_loader('Cookie'); |
|
356 | + $cookieLang = $objCookie->get($cfgKey); |
|
357 | + if ($cookieLang){ |
|
358 | + $appLang = $cookieLang; |
|
359 | + } |
|
360 | + return $appLang; |
|
361 | + } |
|
362 | + /** |
|
363 | + * Get the module information for the model and library to load |
|
364 | + * @param string $class the full class name like moduleName/className, className, |
|
365 | + * @return array the module information |
|
366 | + * array( |
|
367 | + * 'module'=> 'module_name' |
|
368 | + * 'class' => 'class_name' |
|
369 | + * ) |
|
370 | + */ |
|
371 | + protected static function getModuleInfoForModelLibrary($class){ |
|
372 | + $module = null; |
|
373 | + $obj = & get_instance(); |
|
374 | + if (strpos($class, '/') !== false){ |
|
375 | + $path = explode('/', $class); |
|
376 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
377 | + $module = $path[0]; |
|
378 | + $class = ucfirst($path[1]); |
|
379 | + } |
|
380 | + } |
|
381 | + else{ |
|
382 | + $class = ucfirst($class); |
|
383 | + } |
|
384 | + if (! $module && !empty($obj->moduleName)){ |
|
385 | + $module = $obj->moduleName; |
|
386 | + } |
|
387 | + return array( |
|
388 | + 'class' => $class, |
|
389 | + 'module' => $module |
|
390 | + ); |
|
391 | + } |
|
392 | 392 | |
393 | - /** |
|
394 | - * Get the module information for the function to load |
|
395 | - * @param string $function the function name like moduleName/functionName, functionName, |
|
396 | - * @return array the module information |
|
397 | - * array( |
|
398 | - * 'module'=> 'module_name' |
|
399 | - * 'function' => 'function' |
|
400 | - * 'file' => 'file' |
|
401 | - * ) |
|
402 | - */ |
|
403 | - protected static function getModuleInfoForFunction($function){ |
|
404 | - $module = null; |
|
405 | - $file = null; |
|
406 | - $obj = & get_instance(); |
|
407 | - //check if the request class contains module name |
|
408 | - if (strpos($function, '/') !== false){ |
|
409 | - $path = explode('/', $function); |
|
410 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
411 | - $module = $path[0]; |
|
412 | - $function = 'function_' . $path[1]; |
|
413 | - $file = $path[0] . DS . $function.'.php'; |
|
414 | - } |
|
415 | - } |
|
416 | - if (! $module && !empty($obj->moduleName)){ |
|
417 | - $module = $obj->moduleName; |
|
418 | - } |
|
419 | - return array( |
|
420 | - 'function' => $function, |
|
421 | - 'module' => $module, |
|
422 | - 'file' => $file |
|
423 | - ); |
|
424 | - } |
|
393 | + /** |
|
394 | + * Get the module information for the function to load |
|
395 | + * @param string $function the function name like moduleName/functionName, functionName, |
|
396 | + * @return array the module information |
|
397 | + * array( |
|
398 | + * 'module'=> 'module_name' |
|
399 | + * 'function' => 'function' |
|
400 | + * 'file' => 'file' |
|
401 | + * ) |
|
402 | + */ |
|
403 | + protected static function getModuleInfoForFunction($function){ |
|
404 | + $module = null; |
|
405 | + $file = null; |
|
406 | + $obj = & get_instance(); |
|
407 | + //check if the request class contains module name |
|
408 | + if (strpos($function, '/') !== false){ |
|
409 | + $path = explode('/', $function); |
|
410 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
411 | + $module = $path[0]; |
|
412 | + $function = 'function_' . $path[1]; |
|
413 | + $file = $path[0] . DS . $function.'.php'; |
|
414 | + } |
|
415 | + } |
|
416 | + if (! $module && !empty($obj->moduleName)){ |
|
417 | + $module = $obj->moduleName; |
|
418 | + } |
|
419 | + return array( |
|
420 | + 'function' => $function, |
|
421 | + 'module' => $module, |
|
422 | + 'file' => $file |
|
423 | + ); |
|
424 | + } |
|
425 | 425 | |
426 | - /** |
|
427 | - * Get the module information for the language to load |
|
428 | - * @param string $language the language name like moduleName/languageName, languageName, |
|
429 | - * @return array the module information |
|
430 | - * array( |
|
431 | - * 'module'=> 'module_name' |
|
432 | - * 'language' => 'language' |
|
433 | - * 'file' => 'file' |
|
434 | - * ) |
|
435 | - */ |
|
436 | - protected static function getModuleInfoForLanguage($language){ |
|
437 | - $module = null; |
|
438 | - $file = null; |
|
439 | - $obj = & get_instance(); |
|
440 | - //check if the request class contains module name |
|
441 | - if (strpos($language, '/') !== false){ |
|
442 | - $path = explode('/', $language); |
|
443 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
444 | - $module = $path[0]; |
|
445 | - $language = 'lang_' . $path[1] . '.php'; |
|
446 | - $file = $path[0] . DS .$language; |
|
447 | - } |
|
448 | - } |
|
449 | - if (! $module && !empty($obj->moduleName)){ |
|
450 | - $module = $obj->moduleName; |
|
451 | - } |
|
452 | - return array( |
|
453 | - 'language' => $language, |
|
454 | - 'module' => $module, |
|
455 | - 'file' => $file |
|
456 | - ); |
|
457 | - } |
|
426 | + /** |
|
427 | + * Get the module information for the language to load |
|
428 | + * @param string $language the language name like moduleName/languageName, languageName, |
|
429 | + * @return array the module information |
|
430 | + * array( |
|
431 | + * 'module'=> 'module_name' |
|
432 | + * 'language' => 'language' |
|
433 | + * 'file' => 'file' |
|
434 | + * ) |
|
435 | + */ |
|
436 | + protected static function getModuleInfoForLanguage($language){ |
|
437 | + $module = null; |
|
438 | + $file = null; |
|
439 | + $obj = & get_instance(); |
|
440 | + //check if the request class contains module name |
|
441 | + if (strpos($language, '/') !== false){ |
|
442 | + $path = explode('/', $language); |
|
443 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
444 | + $module = $path[0]; |
|
445 | + $language = 'lang_' . $path[1] . '.php'; |
|
446 | + $file = $path[0] . DS .$language; |
|
447 | + } |
|
448 | + } |
|
449 | + if (! $module && !empty($obj->moduleName)){ |
|
450 | + $module = $obj->moduleName; |
|
451 | + } |
|
452 | + return array( |
|
453 | + 'language' => $language, |
|
454 | + 'module' => $module, |
|
455 | + 'file' => $file |
|
456 | + ); |
|
457 | + } |
|
458 | 458 | |
459 | 459 | |
460 | - /** |
|
461 | - * Get the module information for the config to load |
|
462 | - * @param string $filename the filename of the configuration file, |
|
463 | - * @return array the module information |
|
464 | - * array( |
|
465 | - * 'module'=> 'module_name' |
|
466 | - * 'filename' => 'filename' |
|
467 | - * ) |
|
468 | - */ |
|
469 | - protected static function getModuleInfoForConfig($filename){ |
|
470 | - $module = null; |
|
471 | - $obj = & get_instance(); |
|
472 | - //check if the request class contains module name |
|
473 | - if (strpos($filename, '/') !== false){ |
|
474 | - $path = explode('/', $filename); |
|
475 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
476 | - $module = $path[0]; |
|
477 | - $filename = $path[1] . '.php'; |
|
478 | - } |
|
479 | - } |
|
480 | - if (! $module && !empty($obj->moduleName)){ |
|
481 | - $module = $obj->moduleName; |
|
482 | - } |
|
483 | - return array( |
|
484 | - 'filename' => $filename, |
|
485 | - 'module' => $module |
|
486 | - ); |
|
487 | - } |
|
460 | + /** |
|
461 | + * Get the module information for the config to load |
|
462 | + * @param string $filename the filename of the configuration file, |
|
463 | + * @return array the module information |
|
464 | + * array( |
|
465 | + * 'module'=> 'module_name' |
|
466 | + * 'filename' => 'filename' |
|
467 | + * ) |
|
468 | + */ |
|
469 | + protected static function getModuleInfoForConfig($filename){ |
|
470 | + $module = null; |
|
471 | + $obj = & get_instance(); |
|
472 | + //check if the request class contains module name |
|
473 | + if (strpos($filename, '/') !== false){ |
|
474 | + $path = explode('/', $filename); |
|
475 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
476 | + $module = $path[0]; |
|
477 | + $filename = $path[1] . '.php'; |
|
478 | + } |
|
479 | + } |
|
480 | + if (! $module && !empty($obj->moduleName)){ |
|
481 | + $module = $obj->moduleName; |
|
482 | + } |
|
483 | + return array( |
|
484 | + 'filename' => $filename, |
|
485 | + 'module' => $module |
|
486 | + ); |
|
487 | + } |
|
488 | 488 | |
489 | - /** |
|
490 | - * Get the name of model or library instance if is null |
|
491 | - * @param string $class the class name to determine the instance |
|
492 | - * @return string the instance name |
|
493 | - */ |
|
494 | - protected static function getModelLibraryInstanceName($class){ |
|
495 | - //for module |
|
496 | - $instance = null; |
|
497 | - if (strpos($class, '/') !== false){ |
|
498 | - $path = explode('/', $class); |
|
499 | - if (isset($path[1])){ |
|
500 | - $instance = strtolower($path[1]); |
|
501 | - } |
|
502 | - } |
|
503 | - else{ |
|
504 | - $instance = strtolower($class); |
|
505 | - } |
|
506 | - return $instance; |
|
507 | - } |
|
489 | + /** |
|
490 | + * Get the name of model or library instance if is null |
|
491 | + * @param string $class the class name to determine the instance |
|
492 | + * @return string the instance name |
|
493 | + */ |
|
494 | + protected static function getModelLibraryInstanceName($class){ |
|
495 | + //for module |
|
496 | + $instance = null; |
|
497 | + if (strpos($class, '/') !== false){ |
|
498 | + $path = explode('/', $class); |
|
499 | + if (isset($path[1])){ |
|
500 | + $instance = strtolower($path[1]); |
|
501 | + } |
|
502 | + } |
|
503 | + else{ |
|
504 | + $instance = strtolower($class); |
|
505 | + } |
|
506 | + return $instance; |
|
507 | + } |
|
508 | 508 | |
509 | - /** |
|
510 | - * Get the library file path using the module information |
|
511 | - * @param string $class the class name |
|
512 | - * @return string|null the library file path otherwise null will be returned |
|
513 | - */ |
|
514 | - protected static function getLibraryPathUsingModuleInfo($class){ |
|
515 | - $logger = static::getLogger(); |
|
516 | - $libraryFilePath = null; |
|
517 | - $logger->debug('Checking library [' . $class . '] from module list ...'); |
|
518 | - $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
519 | - $module = $moduleInfo['module']; |
|
520 | - $class = $moduleInfo['class']; |
|
521 | - $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
|
522 | - if ($moduleLibraryPath){ |
|
523 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
524 | - $libraryFilePath = $moduleLibraryPath; |
|
525 | - } |
|
526 | - else{ |
|
527 | - $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
|
528 | - } |
|
529 | - return $libraryFilePath; |
|
530 | - } |
|
509 | + /** |
|
510 | + * Get the library file path using the module information |
|
511 | + * @param string $class the class name |
|
512 | + * @return string|null the library file path otherwise null will be returned |
|
513 | + */ |
|
514 | + protected static function getLibraryPathUsingModuleInfo($class){ |
|
515 | + $logger = static::getLogger(); |
|
516 | + $libraryFilePath = null; |
|
517 | + $logger->debug('Checking library [' . $class . '] from module list ...'); |
|
518 | + $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
519 | + $module = $moduleInfo['module']; |
|
520 | + $class = $moduleInfo['class']; |
|
521 | + $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
|
522 | + if ($moduleLibraryPath){ |
|
523 | + $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
524 | + $libraryFilePath = $moduleLibraryPath; |
|
525 | + } |
|
526 | + else{ |
|
527 | + $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
|
528 | + } |
|
529 | + return $libraryFilePath; |
|
530 | + } |
|
531 | 531 | |
532 | - /** |
|
533 | - * Load the library |
|
534 | - * @param string $libraryFilePath the file path of the library to load |
|
535 | - * @param string $class the class name |
|
536 | - * @param string $instance the instance |
|
537 | - * @param array $params the parameter to use |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
541 | - if ($libraryFilePath){ |
|
542 | - $logger = static::getLogger(); |
|
543 | - require_once $libraryFilePath; |
|
544 | - if (class_exists($class)){ |
|
545 | - $c = $params ? new $class($params) : new $class(); |
|
546 | - $obj = & get_instance(); |
|
547 | - $obj->{$instance} = $c; |
|
548 | - static::$loaded[$instance] = $class; |
|
549 | - $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
|
550 | - } |
|
551 | - else{ |
|
552 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
553 | - } |
|
554 | - } |
|
555 | - else{ |
|
556 | - show_error('Unable to find library class [' . $class . ']'); |
|
557 | - } |
|
558 | - } |
|
532 | + /** |
|
533 | + * Load the library |
|
534 | + * @param string $libraryFilePath the file path of the library to load |
|
535 | + * @param string $class the class name |
|
536 | + * @param string $instance the instance |
|
537 | + * @param array $params the parameter to use |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
541 | + if ($libraryFilePath){ |
|
542 | + $logger = static::getLogger(); |
|
543 | + require_once $libraryFilePath; |
|
544 | + if (class_exists($class)){ |
|
545 | + $c = $params ? new $class($params) : new $class(); |
|
546 | + $obj = & get_instance(); |
|
547 | + $obj->{$instance} = $c; |
|
548 | + static::$loaded[$instance] = $class; |
|
549 | + $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
|
550 | + } |
|
551 | + else{ |
|
552 | + show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
553 | + } |
|
554 | + } |
|
555 | + else{ |
|
556 | + show_error('Unable to find library class [' . $class . ']'); |
|
557 | + } |
|
558 | + } |
|
559 | 559 | |
560 | - /** |
|
561 | - * Load the language |
|
562 | - * @param string $languageFilePath the file path of the language to load |
|
563 | - * @param string $language the language name |
|
564 | - * @return void |
|
565 | - */ |
|
566 | - protected static function loadLanguage($languageFilePath, $language){ |
|
567 | - if ($languageFilePath){ |
|
568 | - $logger = static::getLogger(); |
|
569 | - $lang = array(); |
|
570 | - require_once $languageFilePath; |
|
571 | - if (! empty($lang) && is_array($lang)){ |
|
572 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
573 | - //Note: may be here the class 'Lang' not yet loaded |
|
574 | - $langObj =& class_loader('Lang', 'classes'); |
|
575 | - $langObj->addLangMessages($lang); |
|
576 | - //free the memory |
|
577 | - unset($lang); |
|
578 | - } |
|
579 | - static::$loaded['lang_' . $language] = $languageFilePath; |
|
580 | - $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
|
581 | - } |
|
582 | - else{ |
|
583 | - show_error('Unable to find language [' . $language . ']'); |
|
584 | - } |
|
585 | - } |
|
560 | + /** |
|
561 | + * Load the language |
|
562 | + * @param string $languageFilePath the file path of the language to load |
|
563 | + * @param string $language the language name |
|
564 | + * @return void |
|
565 | + */ |
|
566 | + protected static function loadLanguage($languageFilePath, $language){ |
|
567 | + if ($languageFilePath){ |
|
568 | + $logger = static::getLogger(); |
|
569 | + $lang = array(); |
|
570 | + require_once $languageFilePath; |
|
571 | + if (! empty($lang) && is_array($lang)){ |
|
572 | + $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
573 | + //Note: may be here the class 'Lang' not yet loaded |
|
574 | + $langObj =& class_loader('Lang', 'classes'); |
|
575 | + $langObj->addLangMessages($lang); |
|
576 | + //free the memory |
|
577 | + unset($lang); |
|
578 | + } |
|
579 | + static::$loaded['lang_' . $language] = $languageFilePath; |
|
580 | + $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
|
581 | + } |
|
582 | + else{ |
|
583 | + show_error('Unable to find language [' . $language . ']'); |
|
584 | + } |
|
585 | + } |
|
586 | 586 | |
587 | - /** |
|
588 | - * Get all the autoload using the configuration file |
|
589 | - * @return array |
|
590 | - */ |
|
591 | - private function getResourcesFromAutoloadConfig(){ |
|
592 | - $autoloads = array(); |
|
593 | - $autoloads['config'] = array(); |
|
594 | - $autoloads['languages'] = array(); |
|
595 | - $autoloads['libraries'] = array(); |
|
596 | - $autoloads['models'] = array(); |
|
597 | - $autoloads['functions'] = array(); |
|
598 | - //loading of the resources from autoload configuration file |
|
599 | - if (file_exists(CONFIG_PATH . 'autoload.php')){ |
|
600 | - $autoload = array(); |
|
601 | - require_once CONFIG_PATH . 'autoload.php'; |
|
602 | - if (! empty($autoload) && is_array($autoload)){ |
|
603 | - $autoloads = array_merge($autoloads, $autoload); |
|
604 | - unset($autoload); |
|
605 | - } |
|
606 | - } |
|
607 | - //loading autoload configuration for modules |
|
608 | - $modulesAutoloads = Module::getModulesAutoloadConfig(); |
|
609 | - if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){ |
|
610 | - $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
|
611 | - } |
|
612 | - return $autoloads; |
|
613 | - } |
|
587 | + /** |
|
588 | + * Get all the autoload using the configuration file |
|
589 | + * @return array |
|
590 | + */ |
|
591 | + private function getResourcesFromAutoloadConfig(){ |
|
592 | + $autoloads = array(); |
|
593 | + $autoloads['config'] = array(); |
|
594 | + $autoloads['languages'] = array(); |
|
595 | + $autoloads['libraries'] = array(); |
|
596 | + $autoloads['models'] = array(); |
|
597 | + $autoloads['functions'] = array(); |
|
598 | + //loading of the resources from autoload configuration file |
|
599 | + if (file_exists(CONFIG_PATH . 'autoload.php')){ |
|
600 | + $autoload = array(); |
|
601 | + require_once CONFIG_PATH . 'autoload.php'; |
|
602 | + if (! empty($autoload) && is_array($autoload)){ |
|
603 | + $autoloads = array_merge($autoloads, $autoload); |
|
604 | + unset($autoload); |
|
605 | + } |
|
606 | + } |
|
607 | + //loading autoload configuration for modules |
|
608 | + $modulesAutoloads = Module::getModulesAutoloadConfig(); |
|
609 | + if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){ |
|
610 | + $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
|
611 | + } |
|
612 | + return $autoloads; |
|
613 | + } |
|
614 | 614 | |
615 | - /** |
|
616 | - * Load the autoload configuration |
|
617 | - * @return void |
|
618 | - */ |
|
619 | - private function loadResourcesFromAutoloadConfig(){ |
|
620 | - $autoloads = array(); |
|
621 | - $autoloads['config'] = array(); |
|
622 | - $autoloads['languages'] = array(); |
|
623 | - $autoloads['libraries'] = array(); |
|
624 | - $autoloads['models'] = array(); |
|
625 | - $autoloads['functions'] = array(); |
|
615 | + /** |
|
616 | + * Load the autoload configuration |
|
617 | + * @return void |
|
618 | + */ |
|
619 | + private function loadResourcesFromAutoloadConfig(){ |
|
620 | + $autoloads = array(); |
|
621 | + $autoloads['config'] = array(); |
|
622 | + $autoloads['languages'] = array(); |
|
623 | + $autoloads['libraries'] = array(); |
|
624 | + $autoloads['models'] = array(); |
|
625 | + $autoloads['functions'] = array(); |
|
626 | 626 | |
627 | - $list = $this->getResourcesFromAutoloadConfig(); |
|
628 | - $autoloads = array_merge($autoloads, $list); |
|
627 | + $list = $this->getResourcesFromAutoloadConfig(); |
|
628 | + $autoloads = array_merge($autoloads, $list); |
|
629 | 629 | |
630 | - //config autoload |
|
631 | - $this->loadAutoloadResourcesArray('config', $autoloads['config']); |
|
630 | + //config autoload |
|
631 | + $this->loadAutoloadResourcesArray('config', $autoloads['config']); |
|
632 | 632 | |
633 | - //languages autoload |
|
634 | - $this->loadAutoloadResourcesArray('lang', $autoloads['languages']); |
|
633 | + //languages autoload |
|
634 | + $this->loadAutoloadResourcesArray('lang', $autoloads['languages']); |
|
635 | 635 | |
636 | - //libraries autoload |
|
637 | - $this->loadAutoloadResourcesArray('library', $autoloads['libraries']); |
|
636 | + //libraries autoload |
|
637 | + $this->loadAutoloadResourcesArray('library', $autoloads['libraries']); |
|
638 | 638 | |
639 | - //models autoload |
|
640 | - $this->loadAutoloadResourcesArray('model', $autoloads['models']); |
|
639 | + //models autoload |
|
640 | + $this->loadAutoloadResourcesArray('model', $autoloads['models']); |
|
641 | 641 | |
642 | - //functions autoload |
|
643 | - $this->loadAutoloadResourcesArray('functions', $autoloads['functions']); |
|
644 | - } |
|
642 | + //functions autoload |
|
643 | + $this->loadAutoloadResourcesArray('functions', $autoloads['functions']); |
|
644 | + } |
|
645 | 645 | |
646 | - /** |
|
647 | - * Load the resources autoload array |
|
648 | - * @param string $method this object method name to call |
|
649 | - * @param array $resources the resource to load |
|
650 | - * @return void |
|
651 | - */ |
|
652 | - private function loadAutoloadResourcesArray($method, array $resources){ |
|
653 | - foreach ($resources as $name) { |
|
654 | - $this->{$method}($name); |
|
655 | - } |
|
656 | - } |
|
657 | - } |
|
646 | + /** |
|
647 | + * Load the resources autoload array |
|
648 | + * @param string $method this object method name to call |
|
649 | + * @param array $resources the resource to load |
|
650 | + * @return void |
|
651 | + */ |
|
652 | + private function loadAutoloadResourcesArray($method, array $resources){ |
|
653 | + foreach ($resources as $name) { |
|
654 | + $this->{$method}($name); |
|
655 | + } |
|
656 | + } |
|
657 | + } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Loader{ |
|
26 | + class Loader { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * List of loaded resources |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | private static $logger; |
39 | 39 | |
40 | 40 | |
41 | - public function __construct(){ |
|
41 | + public function __construct() { |
|
42 | 42 | //add the resources already loaded during application bootstrap |
43 | 43 | //in the list to prevent duplicate or loading the resources again. |
44 | 44 | static::$loaded = class_loaded(); |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * The signleton of the logger |
52 | 52 | * @return object the Log instance |
53 | 53 | */ |
54 | - public static function getLogger(){ |
|
55 | - if(self::$logger == null){ |
|
54 | + public static function getLogger() { |
|
55 | + if (self::$logger == null) { |
|
56 | 56 | $logger = array(); |
57 | - $logger[0] =& class_loader('Log', 'classes'); |
|
57 | + $logger[0] = & class_loader('Log', 'classes'); |
|
58 | 58 | $logger[0]->setLogger('Library::Loader'); |
59 | 59 | self::$logger = $logger[0]; |
60 | 60 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param object $logger the log object |
67 | 67 | * @return object the log instance |
68 | 68 | */ |
69 | - public static function setLogger($logger){ |
|
69 | + public static function setLogger($logger) { |
|
70 | 70 | self::$logger = $logger; |
71 | 71 | return self::$logger; |
72 | 72 | } |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return void |
82 | 82 | */ |
83 | - public static function model($class, $instance = null){ |
|
83 | + public static function model($class, $instance = null) { |
|
84 | 84 | $logger = static::getLogger(); |
85 | 85 | $class = str_ireplace('.php', '', $class); |
86 | 86 | $class = trim($class, '/\\'); |
87 | - $file = ucfirst($class).'.php'; |
|
87 | + $file = ucfirst($class) . '.php'; |
|
88 | 88 | $logger->debug('Loading model [' . $class . '] ...'); |
89 | 89 | //************ |
90 | - if (! $instance){ |
|
90 | + if (!$instance) { |
|
91 | 91 | $instance = self::getModelLibraryInstanceName($class); |
92 | 92 | } |
93 | 93 | //**************** |
94 | - if (isset(static::$loaded[$instance])){ |
|
94 | + if (isset(static::$loaded[$instance])) { |
|
95 | 95 | $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
96 | 96 | return; |
97 | 97 | } |
@@ -104,28 +104,28 @@ discard block |
||
104 | 104 | $class = $moduleInfo['class']; |
105 | 105 | |
106 | 106 | $moduleModelFilePath = Module::findModelFullPath($class, $module); |
107 | - if ($moduleModelFilePath){ |
|
108 | - $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
107 | + if ($moduleModelFilePath) { |
|
108 | + $logger->info('Found model [' . $class . '] from module [' . $module . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
109 | 109 | $classFilePath = $moduleModelFilePath; |
110 | 110 | } |
111 | - else{ |
|
111 | + else { |
|
112 | 112 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
113 | 113 | } |
114 | 114 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
115 | - if (file_exists($classFilePath)){ |
|
115 | + if (file_exists($classFilePath)) { |
|
116 | 116 | require_once $classFilePath; |
117 | - if (class_exists($class)){ |
|
117 | + if (class_exists($class)) { |
|
118 | 118 | $c = new $class(); |
119 | 119 | $obj = & get_instance(); |
120 | 120 | $obj->{$instance} = $c; |
121 | 121 | static::$loaded[$instance] = $class; |
122 | 122 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
123 | 123 | } |
124 | - else{ |
|
125 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
124 | + else { |
|
125 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
126 | 126 | } |
127 | 127 | } |
128 | - else{ |
|
128 | + else { |
|
129 | 129 | show_error('Unable to find the model [' . $class . ']'); |
130 | 130 | } |
131 | 131 | } |
@@ -140,22 +140,22 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return void |
142 | 142 | */ |
143 | - public static function library($class, $instance = null, array $params = array()){ |
|
143 | + public static function library($class, $instance = null, array $params = array()) { |
|
144 | 144 | $logger = static::getLogger(); |
145 | 145 | $class = str_ireplace('.php', '', $class); |
146 | 146 | $class = trim($class, '/\\'); |
147 | - $file = ucfirst($class) .'.php'; |
|
147 | + $file = ucfirst($class) . '.php'; |
|
148 | 148 | $logger->debug('Loading library [' . $class . '] ...'); |
149 | - if (! $instance){ |
|
149 | + if (!$instance) { |
|
150 | 150 | $instance = self::getModelLibraryInstanceName($class); |
151 | 151 | } |
152 | - if (isset(static::$loaded[$instance])){ |
|
152 | + if (isset(static::$loaded[$instance])) { |
|
153 | 153 | $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
154 | 154 | return; |
155 | 155 | } |
156 | 156 | $obj = & get_instance(); |
157 | 157 | //Check and load Database library |
158 | - if (strtolower($class) == 'database'){ |
|
158 | + if (strtolower($class) == 'database') { |
|
159 | 159 | $logger->info('This is the Database library ...'); |
160 | 160 | $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
161 | 161 | static::$loaded[$instance] = $class; |
@@ -164,18 +164,18 @@ discard block |
||
164 | 164 | } |
165 | 165 | $libraryFilePath = null; |
166 | 166 | $logger->debug('Check if this is a system library ...'); |
167 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
167 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
168 | 168 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
169 | 169 | $class = ucfirst($class); |
170 | 170 | $logger->info('This library is a system library'); |
171 | 171 | } |
172 | - else{ |
|
172 | + else { |
|
173 | 173 | $logger->info('This library is not a system library'); |
174 | 174 | //first check if this library is in the module |
175 | 175 | $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
176 | 176 | //*************** |
177 | 177 | } |
178 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
178 | + if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) { |
|
179 | 179 | $libraryFilePath = LIBRARY_PATH . $file; |
180 | 180 | } |
181 | 181 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return void |
192 | 192 | */ |
193 | - public static function functions($function){ |
|
193 | + public static function functions($function) { |
|
194 | 194 | $logger = static::getLogger(); |
195 | 195 | $function = str_ireplace('.php', '', $function); |
196 | 196 | $function = trim($function, '/\\'); |
197 | 197 | $function = str_ireplace('function_', '', $function); |
198 | - $file = 'function_'.$function.'.php'; |
|
198 | + $file = 'function_' . $function . '.php'; |
|
199 | 199 | $logger->debug('Loading helper [' . $function . '] ...'); |
200 | - if (isset(static::$loaded['function_' . $function])){ |
|
200 | + if (isset(static::$loaded['function_' . $function])) { |
|
201 | 201 | $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
202 | 202 | return; |
203 | 203 | } |
@@ -207,22 +207,22 @@ discard block |
||
207 | 207 | $moduleInfo = self::getModuleInfoForFunction($function); |
208 | 208 | $module = $moduleInfo['module']; |
209 | 209 | $function = $moduleInfo['function']; |
210 | - if(! empty($moduleInfo['file'])){ |
|
210 | + if (!empty($moduleInfo['file'])) { |
|
211 | 211 | $file = $moduleInfo['file']; |
212 | 212 | } |
213 | 213 | $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
214 | - if ($moduleFunctionPath){ |
|
215 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
214 | + if ($moduleFunctionPath) { |
|
215 | + $logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
216 | 216 | $functionFilePath = $moduleFunctionPath; |
217 | 217 | } |
218 | - else{ |
|
218 | + else { |
|
219 | 219 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
220 | 220 | } |
221 | - if (! $functionFilePath){ |
|
221 | + if (!$functionFilePath) { |
|
222 | 222 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
223 | - foreach($searchDir as $dir){ |
|
223 | + foreach ($searchDir as $dir) { |
|
224 | 224 | $filePath = $dir . $file; |
225 | - if (file_exists($filePath)){ |
|
225 | + if (file_exists($filePath)) { |
|
226 | 226 | $functionFilePath = $filePath; |
227 | 227 | //is already found not to continue |
228 | 228 | break; |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | } |
231 | 231 | } |
232 | 232 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
233 | - if ($functionFilePath){ |
|
233 | + if ($functionFilePath) { |
|
234 | 234 | require_once $functionFilePath; |
235 | 235 | static::$loaded['function_' . $function] = $functionFilePath; |
236 | 236 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
237 | 237 | } |
238 | - else{ |
|
238 | + else { |
|
239 | 239 | show_error('Unable to find helper file [' . $file . ']'); |
240 | 240 | } |
241 | 241 | } |
@@ -247,14 +247,14 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return void |
249 | 249 | */ |
250 | - public static function config($filename){ |
|
250 | + public static function config($filename) { |
|
251 | 251 | $logger = static::getLogger(); |
252 | 252 | $filename = str_ireplace('.php', '', $filename); |
253 | 253 | $filename = trim($filename, '/\\'); |
254 | 254 | $filename = str_ireplace('config_', '', $filename); |
255 | - $file = 'config_'.$filename.'.php'; |
|
255 | + $file = 'config_' . $filename . '.php'; |
|
256 | 256 | $logger->debug('Loading configuration [' . $filename . '] ...'); |
257 | - if (isset(static::$loaded['config_' . $filename])){ |
|
257 | + if (isset(static::$loaded['config_' . $filename])) { |
|
258 | 258 | $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
259 | 259 | return; |
260 | 260 | } |
@@ -265,18 +265,18 @@ discard block |
||
265 | 265 | $module = $moduleInfo['module']; |
266 | 266 | $filename = $moduleInfo['filename']; |
267 | 267 | $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
268 | - if ($moduleConfigPath){ |
|
269 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
268 | + if ($moduleConfigPath) { |
|
269 | + $logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
270 | 270 | $configFilePath = $moduleConfigPath; |
271 | 271 | } |
272 | - else{ |
|
272 | + else { |
|
273 | 273 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
274 | 274 | } |
275 | 275 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
276 | 276 | $config = array(); |
277 | - if (file_exists($configFilePath)){ |
|
277 | + if (file_exists($configFilePath)) { |
|
278 | 278 | require_once $configFilePath; |
279 | - if (! empty($config) && is_array($config)){ |
|
279 | + if (!empty($config) && is_array($config)) { |
|
280 | 280 | Config::setAll($config); |
281 | 281 | static::$loaded['config_' . $filename] = $configFilePath; |
282 | 282 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | unset($config); |
285 | 285 | } |
286 | 286 | } |
287 | - else{ |
|
288 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
287 | + else { |
|
288 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
289 | 289 | } |
290 | 290 | } |
291 | 291 | |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @return void |
299 | 299 | */ |
300 | - public static function lang($language){ |
|
300 | + public static function lang($language) { |
|
301 | 301 | $logger = static::getLogger(); |
302 | 302 | $language = str_ireplace('.php', '', $language); |
303 | 303 | $language = trim($language, '/\\'); |
304 | 304 | $language = str_ireplace('lang_', '', $language); |
305 | - $file = 'lang_'.$language.'.php'; |
|
305 | + $file = 'lang_' . $language . '.php'; |
|
306 | 306 | $logger->debug('Loading language [' . $language . '] ...'); |
307 | - if (isset(static::$loaded['lang_' . $language])){ |
|
307 | + if (isset(static::$loaded['lang_' . $language])) { |
|
308 | 308 | $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
309 | 309 | return; |
310 | 310 | } |
@@ -316,22 +316,22 @@ discard block |
||
316 | 316 | $moduleInfo = self::getModuleInfoForLanguage($language); |
317 | 317 | $module = $moduleInfo['module']; |
318 | 318 | $language = $moduleInfo['language']; |
319 | - if(! empty($moduleInfo['file'])){ |
|
319 | + if (!empty($moduleInfo['file'])) { |
|
320 | 320 | $file = $moduleInfo['file']; |
321 | 321 | } |
322 | 322 | $moduleLanguagePath = Module::findLanguageFullPath($language, $module, $appLang); |
323 | - if ($moduleLanguagePath){ |
|
324 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
323 | + if ($moduleLanguagePath) { |
|
324 | + $logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
325 | 325 | $languageFilePath = $moduleLanguagePath; |
326 | 326 | } |
327 | - else{ |
|
327 | + else { |
|
328 | 328 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
329 | 329 | } |
330 | - if (! $languageFilePath){ |
|
330 | + if (!$languageFilePath) { |
|
331 | 331 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
332 | - foreach($searchDir as $dir){ |
|
332 | + foreach ($searchDir as $dir) { |
|
333 | 333 | $filePath = $dir . $appLang . DS . $file; |
334 | - if (file_exists($filePath)){ |
|
334 | + if (file_exists($filePath)) { |
|
335 | 335 | $languageFilePath = $filePath; |
336 | 336 | //already found no need continue |
337 | 337 | break; |
@@ -347,14 +347,14 @@ discard block |
||
347 | 347 | * if can not found will use the default value from configuration |
348 | 348 | * @return string the app language like "en", "fr" |
349 | 349 | */ |
350 | - protected static function getAppLang(){ |
|
350 | + protected static function getAppLang() { |
|
351 | 351 | //determine the current language |
352 | 352 | $appLang = get_config('default_language'); |
353 | 353 | //if the language exists in the cookie use it |
354 | 354 | $cfgKey = get_config('language_cookie_name'); |
355 | 355 | $objCookie = & class_loader('Cookie'); |
356 | 356 | $cookieLang = $objCookie->get($cfgKey); |
357 | - if ($cookieLang){ |
|
357 | + if ($cookieLang) { |
|
358 | 358 | $appLang = $cookieLang; |
359 | 359 | } |
360 | 360 | return $appLang; |
@@ -368,20 +368,20 @@ discard block |
||
368 | 368 | * 'class' => 'class_name' |
369 | 369 | * ) |
370 | 370 | */ |
371 | - protected static function getModuleInfoForModelLibrary($class){ |
|
371 | + protected static function getModuleInfoForModelLibrary($class) { |
|
372 | 372 | $module = null; |
373 | 373 | $obj = & get_instance(); |
374 | - if (strpos($class, '/') !== false){ |
|
374 | + if (strpos($class, '/') !== false) { |
|
375 | 375 | $path = explode('/', $class); |
376 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
376 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
377 | 377 | $module = $path[0]; |
378 | 378 | $class = ucfirst($path[1]); |
379 | 379 | } |
380 | 380 | } |
381 | - else{ |
|
381 | + else { |
|
382 | 382 | $class = ucfirst($class); |
383 | 383 | } |
384 | - if (! $module && !empty($obj->moduleName)){ |
|
384 | + if (!$module && !empty($obj->moduleName)) { |
|
385 | 385 | $module = $obj->moduleName; |
386 | 386 | } |
387 | 387 | return array( |
@@ -400,20 +400,20 @@ discard block |
||
400 | 400 | * 'file' => 'file' |
401 | 401 | * ) |
402 | 402 | */ |
403 | - protected static function getModuleInfoForFunction($function){ |
|
403 | + protected static function getModuleInfoForFunction($function) { |
|
404 | 404 | $module = null; |
405 | 405 | $file = null; |
406 | 406 | $obj = & get_instance(); |
407 | 407 | //check if the request class contains module name |
408 | - if (strpos($function, '/') !== false){ |
|
408 | + if (strpos($function, '/') !== false) { |
|
409 | 409 | $path = explode('/', $function); |
410 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
410 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
411 | 411 | $module = $path[0]; |
412 | 412 | $function = 'function_' . $path[1]; |
413 | - $file = $path[0] . DS . $function.'.php'; |
|
413 | + $file = $path[0] . DS . $function . '.php'; |
|
414 | 414 | } |
415 | 415 | } |
416 | - if (! $module && !empty($obj->moduleName)){ |
|
416 | + if (!$module && !empty($obj->moduleName)) { |
|
417 | 417 | $module = $obj->moduleName; |
418 | 418 | } |
419 | 419 | return array( |
@@ -433,20 +433,20 @@ discard block |
||
433 | 433 | * 'file' => 'file' |
434 | 434 | * ) |
435 | 435 | */ |
436 | - protected static function getModuleInfoForLanguage($language){ |
|
436 | + protected static function getModuleInfoForLanguage($language) { |
|
437 | 437 | $module = null; |
438 | 438 | $file = null; |
439 | 439 | $obj = & get_instance(); |
440 | 440 | //check if the request class contains module name |
441 | - if (strpos($language, '/') !== false){ |
|
441 | + if (strpos($language, '/') !== false) { |
|
442 | 442 | $path = explode('/', $language); |
443 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
443 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
444 | 444 | $module = $path[0]; |
445 | 445 | $language = 'lang_' . $path[1] . '.php'; |
446 | - $file = $path[0] . DS .$language; |
|
446 | + $file = $path[0] . DS . $language; |
|
447 | 447 | } |
448 | 448 | } |
449 | - if (! $module && !empty($obj->moduleName)){ |
|
449 | + if (!$module && !empty($obj->moduleName)) { |
|
450 | 450 | $module = $obj->moduleName; |
451 | 451 | } |
452 | 452 | return array( |
@@ -466,18 +466,18 @@ discard block |
||
466 | 466 | * 'filename' => 'filename' |
467 | 467 | * ) |
468 | 468 | */ |
469 | - protected static function getModuleInfoForConfig($filename){ |
|
469 | + protected static function getModuleInfoForConfig($filename) { |
|
470 | 470 | $module = null; |
471 | 471 | $obj = & get_instance(); |
472 | 472 | //check if the request class contains module name |
473 | - if (strpos($filename, '/') !== false){ |
|
473 | + if (strpos($filename, '/') !== false) { |
|
474 | 474 | $path = explode('/', $filename); |
475 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
475 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
476 | 476 | $module = $path[0]; |
477 | 477 | $filename = $path[1] . '.php'; |
478 | 478 | } |
479 | 479 | } |
480 | - if (! $module && !empty($obj->moduleName)){ |
|
480 | + if (!$module && !empty($obj->moduleName)) { |
|
481 | 481 | $module = $obj->moduleName; |
482 | 482 | } |
483 | 483 | return array( |
@@ -491,16 +491,16 @@ discard block |
||
491 | 491 | * @param string $class the class name to determine the instance |
492 | 492 | * @return string the instance name |
493 | 493 | */ |
494 | - protected static function getModelLibraryInstanceName($class){ |
|
494 | + protected static function getModelLibraryInstanceName($class) { |
|
495 | 495 | //for module |
496 | 496 | $instance = null; |
497 | - if (strpos($class, '/') !== false){ |
|
497 | + if (strpos($class, '/') !== false) { |
|
498 | 498 | $path = explode('/', $class); |
499 | - if (isset($path[1])){ |
|
499 | + if (isset($path[1])) { |
|
500 | 500 | $instance = strtolower($path[1]); |
501 | 501 | } |
502 | 502 | } |
503 | - else{ |
|
503 | + else { |
|
504 | 504 | $instance = strtolower($class); |
505 | 505 | } |
506 | 506 | return $instance; |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | * @param string $class the class name |
512 | 512 | * @return string|null the library file path otherwise null will be returned |
513 | 513 | */ |
514 | - protected static function getLibraryPathUsingModuleInfo($class){ |
|
514 | + protected static function getLibraryPathUsingModuleInfo($class) { |
|
515 | 515 | $logger = static::getLogger(); |
516 | 516 | $libraryFilePath = null; |
517 | 517 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
@@ -519,11 +519,11 @@ discard block |
||
519 | 519 | $module = $moduleInfo['module']; |
520 | 520 | $class = $moduleInfo['class']; |
521 | 521 | $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
522 | - if ($moduleLibraryPath){ |
|
523 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
522 | + if ($moduleLibraryPath) { |
|
523 | + $logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
524 | 524 | $libraryFilePath = $moduleLibraryPath; |
525 | 525 | } |
526 | - else{ |
|
526 | + else { |
|
527 | 527 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
528 | 528 | } |
529 | 529 | return $libraryFilePath; |
@@ -537,22 +537,22 @@ discard block |
||
537 | 537 | * @param array $params the parameter to use |
538 | 538 | * @return void |
539 | 539 | */ |
540 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
541 | - if ($libraryFilePath){ |
|
540 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) { |
|
541 | + if ($libraryFilePath) { |
|
542 | 542 | $logger = static::getLogger(); |
543 | 543 | require_once $libraryFilePath; |
544 | - if (class_exists($class)){ |
|
544 | + if (class_exists($class)) { |
|
545 | 545 | $c = $params ? new $class($params) : new $class(); |
546 | 546 | $obj = & get_instance(); |
547 | 547 | $obj->{$instance} = $c; |
548 | 548 | static::$loaded[$instance] = $class; |
549 | 549 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
550 | 550 | } |
551 | - else{ |
|
552 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
551 | + else { |
|
552 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
553 | 553 | } |
554 | 554 | } |
555 | - else{ |
|
555 | + else { |
|
556 | 556 | show_error('Unable to find library class [' . $class . ']'); |
557 | 557 | } |
558 | 558 | } |
@@ -563,15 +563,15 @@ discard block |
||
563 | 563 | * @param string $language the language name |
564 | 564 | * @return void |
565 | 565 | */ |
566 | - protected static function loadLanguage($languageFilePath, $language){ |
|
567 | - if ($languageFilePath){ |
|
566 | + protected static function loadLanguage($languageFilePath, $language) { |
|
567 | + if ($languageFilePath) { |
|
568 | 568 | $logger = static::getLogger(); |
569 | 569 | $lang = array(); |
570 | 570 | require_once $languageFilePath; |
571 | - if (! empty($lang) && is_array($lang)){ |
|
572 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
571 | + if (!empty($lang) && is_array($lang)) { |
|
572 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
573 | 573 | //Note: may be here the class 'Lang' not yet loaded |
574 | - $langObj =& class_loader('Lang', 'classes'); |
|
574 | + $langObj = & class_loader('Lang', 'classes'); |
|
575 | 575 | $langObj->addLangMessages($lang); |
576 | 576 | //free the memory |
577 | 577 | unset($lang); |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | static::$loaded['lang_' . $language] = $languageFilePath; |
580 | 580 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
581 | 581 | } |
582 | - else{ |
|
582 | + else { |
|
583 | 583 | show_error('Unable to find language [' . $language . ']'); |
584 | 584 | } |
585 | 585 | } |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * Get all the autoload using the configuration file |
589 | 589 | * @return array |
590 | 590 | */ |
591 | - private function getResourcesFromAutoloadConfig(){ |
|
591 | + private function getResourcesFromAutoloadConfig() { |
|
592 | 592 | $autoloads = array(); |
593 | 593 | $autoloads['config'] = array(); |
594 | 594 | $autoloads['languages'] = array(); |
@@ -596,17 +596,17 @@ discard block |
||
596 | 596 | $autoloads['models'] = array(); |
597 | 597 | $autoloads['functions'] = array(); |
598 | 598 | //loading of the resources from autoload configuration file |
599 | - if (file_exists(CONFIG_PATH . 'autoload.php')){ |
|
599 | + if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
600 | 600 | $autoload = array(); |
601 | 601 | require_once CONFIG_PATH . 'autoload.php'; |
602 | - if (! empty($autoload) && is_array($autoload)){ |
|
602 | + if (!empty($autoload) && is_array($autoload)) { |
|
603 | 603 | $autoloads = array_merge($autoloads, $autoload); |
604 | 604 | unset($autoload); |
605 | 605 | } |
606 | 606 | } |
607 | 607 | //loading autoload configuration for modules |
608 | 608 | $modulesAutoloads = Module::getModulesAutoloadConfig(); |
609 | - if (! empty($modulesAutoloads) && is_array($modulesAutoloads)){ |
|
609 | + if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) { |
|
610 | 610 | $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
611 | 611 | } |
612 | 612 | return $autoloads; |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | * Load the autoload configuration |
617 | 617 | * @return void |
618 | 618 | */ |
619 | - private function loadResourcesFromAutoloadConfig(){ |
|
619 | + private function loadResourcesFromAutoloadConfig() { |
|
620 | 620 | $autoloads = array(); |
621 | 621 | $autoloads['config'] = array(); |
622 | 622 | $autoloads['languages'] = array(); |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | * @param array $resources the resource to load |
650 | 650 | * @return void |
651 | 651 | */ |
652 | - private function loadAutoloadResourcesArray($method, array $resources){ |
|
652 | + private function loadAutoloadResourcesArray($method, array $resources) { |
|
653 | 653 | foreach ($resources as $name) { |
654 | 654 | $this->{$method}($name); |
655 | 655 | } |