@@ -1,612 +1,612 @@ |
||
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 extends BaseStaticClass { |
|
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 extends BaseStaticClass { |
|
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 | 34 | |
35 | - public function __construct() { |
|
36 | - //add the resources already loaded during application bootstrap |
|
37 | - //in the list to prevent duplicate or loading the resources again. |
|
38 | - static::$loaded = class_loaded(); |
|
35 | + public function __construct() { |
|
36 | + //add the resources already loaded during application bootstrap |
|
37 | + //in the list to prevent duplicate or loading the resources again. |
|
38 | + static::$loaded = class_loaded(); |
|
39 | 39 | |
40 | - //Load resources from autoload configuration |
|
41 | - $this->loadResourcesFromAutoloadConfig(); |
|
42 | - } |
|
40 | + //Load resources from autoload configuration |
|
41 | + $this->loadResourcesFromAutoloadConfig(); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Load the model class |
|
47 | - * |
|
48 | - * @param string $class the class name to be loaded |
|
49 | - * @param string $instance the name of the instance to use in super object |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public static function model($class, $instance = null) { |
|
54 | - $logger = static::getLogger(); |
|
55 | - $class = str_ireplace('.php', '', $class); |
|
56 | - $class = trim($class, '/\\'); |
|
57 | - $file = ucfirst($class) . '.php'; |
|
58 | - $logger->debug('Loading model [' . $class . '] ...'); |
|
59 | - //************ |
|
60 | - if (!$instance) { |
|
61 | - $instance = self::getModelLibraryInstanceName($class); |
|
62 | - } |
|
63 | - //**************** |
|
64 | - if (isset(static::$loaded[$instance])) { |
|
65 | - $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
66 | - return; |
|
67 | - } |
|
68 | - $classFilePath = APPS_MODEL_PATH . $file; |
|
69 | - //first check if this model is in the module |
|
70 | - $logger->debug('Checking model [' . $class . '] from module list ...'); |
|
71 | - //check if the request class contains module name |
|
72 | - $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
73 | - $module = $moduleInfo['module']; |
|
74 | - $class = $moduleInfo['class']; |
|
45 | + /** |
|
46 | + * Load the model class |
|
47 | + * |
|
48 | + * @param string $class the class name to be loaded |
|
49 | + * @param string $instance the name of the instance to use in super object |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public static function model($class, $instance = null) { |
|
54 | + $logger = static::getLogger(); |
|
55 | + $class = str_ireplace('.php', '', $class); |
|
56 | + $class = trim($class, '/\\'); |
|
57 | + $file = ucfirst($class) . '.php'; |
|
58 | + $logger->debug('Loading model [' . $class . '] ...'); |
|
59 | + //************ |
|
60 | + if (!$instance) { |
|
61 | + $instance = self::getModelLibraryInstanceName($class); |
|
62 | + } |
|
63 | + //**************** |
|
64 | + if (isset(static::$loaded[$instance])) { |
|
65 | + $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
66 | + return; |
|
67 | + } |
|
68 | + $classFilePath = APPS_MODEL_PATH . $file; |
|
69 | + //first check if this model is in the module |
|
70 | + $logger->debug('Checking model [' . $class . '] from module list ...'); |
|
71 | + //check if the request class contains module name |
|
72 | + $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
73 | + $module = $moduleInfo['module']; |
|
74 | + $class = $moduleInfo['class']; |
|
75 | 75 | |
76 | - $moduleModelFilePath = Module::findModelFullPath($class, $module); |
|
77 | - if ($moduleModelFilePath){ |
|
78 | - $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
79 | - $classFilePath = $moduleModelFilePath; |
|
80 | - } else{ |
|
81 | - $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
|
82 | - } |
|
83 | - $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
|
84 | - if (file_exists($classFilePath)){ |
|
85 | - require_once $classFilePath; |
|
86 | - if (class_exists($class)){ |
|
87 | - $c = new $class(); |
|
88 | - $obj = & get_instance(); |
|
89 | - $obj->{$instance} = $c; |
|
90 | - static::$loaded[$instance] = $class; |
|
91 | - $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
|
92 | - } else{ |
|
93 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
94 | - } |
|
95 | - } else{ |
|
96 | - show_error('Unable to find the model [' . $class . ']'); |
|
97 | - } |
|
98 | - } |
|
76 | + $moduleModelFilePath = Module::findModelFullPath($class, $module); |
|
77 | + if ($moduleModelFilePath){ |
|
78 | + $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
79 | + $classFilePath = $moduleModelFilePath; |
|
80 | + } else{ |
|
81 | + $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
|
82 | + } |
|
83 | + $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
|
84 | + if (file_exists($classFilePath)){ |
|
85 | + require_once $classFilePath; |
|
86 | + if (class_exists($class)){ |
|
87 | + $c = new $class(); |
|
88 | + $obj = & get_instance(); |
|
89 | + $obj->{$instance} = $c; |
|
90 | + static::$loaded[$instance] = $class; |
|
91 | + $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
|
92 | + } else{ |
|
93 | + show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
94 | + } |
|
95 | + } else{ |
|
96 | + show_error('Unable to find the model [' . $class . ']'); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * Load the library class |
|
103 | - * |
|
104 | - * @param string $class the library class name to be loaded |
|
105 | - * @param string $instance the instance name to use in super object |
|
106 | - * @param mixed $params the arguments to pass to the constructor |
|
107 | - * |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - public static function library($class, $instance = null, array $params = array()) { |
|
111 | - $logger = static::getLogger(); |
|
112 | - $class = str_ireplace('.php', '', $class); |
|
113 | - $class = trim($class, '/\\'); |
|
114 | - $file = ucfirst($class) . '.php'; |
|
115 | - $logger->debug('Loading library [' . $class . '] ...'); |
|
116 | - if (!$instance) { |
|
117 | - $instance = self::getModelLibraryInstanceName($class); |
|
118 | - } |
|
119 | - if (isset(static::$loaded[$instance])) { |
|
120 | - $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
121 | - return; |
|
122 | - } |
|
123 | - $obj = & get_instance(); |
|
124 | - //Check and load Database library |
|
125 | - if (strtolower($class) == 'database') { |
|
126 | - $logger->info('This is the Database library ...'); |
|
127 | - $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
|
128 | - static::$loaded[$instance] = $class; |
|
129 | - $logger->info('Library Database loaded successfully.'); |
|
130 | - return; |
|
131 | - } |
|
132 | - $libraryFilePath = null; |
|
133 | - $logger->debug('Check if this is a system library ...'); |
|
134 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
135 | - $libraryFilePath = CORE_LIBRARY_PATH . $file; |
|
136 | - $class = ucfirst($class); |
|
137 | - $logger->info('This library is a system library'); |
|
138 | - } else{ |
|
139 | - $logger->info('This library is not a system library'); |
|
140 | - //first check if this library is in the module |
|
141 | - $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
|
142 | - //*************** |
|
143 | - } |
|
144 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
145 | - $libraryFilePath = LIBRARY_PATH . $file; |
|
146 | - } |
|
147 | - $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
|
148 | - //************************* |
|
149 | - self::loadLibrary($libraryFilePath, $class, $instance, $params); |
|
150 | - } |
|
101 | + /** |
|
102 | + * Load the library class |
|
103 | + * |
|
104 | + * @param string $class the library class name to be loaded |
|
105 | + * @param string $instance the instance name to use in super object |
|
106 | + * @param mixed $params the arguments to pass to the constructor |
|
107 | + * |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + public static function library($class, $instance = null, array $params = array()) { |
|
111 | + $logger = static::getLogger(); |
|
112 | + $class = str_ireplace('.php', '', $class); |
|
113 | + $class = trim($class, '/\\'); |
|
114 | + $file = ucfirst($class) . '.php'; |
|
115 | + $logger->debug('Loading library [' . $class . '] ...'); |
|
116 | + if (!$instance) { |
|
117 | + $instance = self::getModelLibraryInstanceName($class); |
|
118 | + } |
|
119 | + if (isset(static::$loaded[$instance])) { |
|
120 | + $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
|
121 | + return; |
|
122 | + } |
|
123 | + $obj = & get_instance(); |
|
124 | + //Check and load Database library |
|
125 | + if (strtolower($class) == 'database') { |
|
126 | + $logger->info('This is the Database library ...'); |
|
127 | + $obj->{$instance} = & class_loader('Database', 'classes/database', $params); |
|
128 | + static::$loaded[$instance] = $class; |
|
129 | + $logger->info('Library Database loaded successfully.'); |
|
130 | + return; |
|
131 | + } |
|
132 | + $libraryFilePath = null; |
|
133 | + $logger->debug('Check if this is a system library ...'); |
|
134 | + if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
135 | + $libraryFilePath = CORE_LIBRARY_PATH . $file; |
|
136 | + $class = ucfirst($class); |
|
137 | + $logger->info('This library is a system library'); |
|
138 | + } else{ |
|
139 | + $logger->info('This library is not a system library'); |
|
140 | + //first check if this library is in the module |
|
141 | + $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
|
142 | + //*************** |
|
143 | + } |
|
144 | + if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
145 | + $libraryFilePath = LIBRARY_PATH . $file; |
|
146 | + } |
|
147 | + $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
|
148 | + //************************* |
|
149 | + self::loadLibrary($libraryFilePath, $class, $instance, $params); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Load the helper |
|
154 | - * |
|
155 | - * @param string $function the helper name to be loaded |
|
156 | - * |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public static function functions($function) { |
|
160 | - $logger = static::getLogger(); |
|
161 | - $function = str_ireplace('.php', '', $function); |
|
162 | - $function = trim($function, '/\\'); |
|
163 | - $function = str_ireplace('function_', '', $function); |
|
164 | - $file = 'function_' . $function . '.php'; |
|
165 | - $logger->debug('Loading helper [' . $function . '] ...'); |
|
166 | - if (isset(static::$loaded['function_' . $function])) { |
|
167 | - $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
|
168 | - return; |
|
169 | - } |
|
170 | - $functionFilePath = null; |
|
171 | - //first check if this helper is in the module |
|
172 | - $logger->debug('Checking helper [' . $function . '] from module list ...'); |
|
173 | - $moduleInfo = self::getModuleInfoForFunction($function); |
|
174 | - $module = $moduleInfo['module']; |
|
175 | - $function = $moduleInfo['function']; |
|
176 | - if(! empty($moduleInfo['file'])){ |
|
177 | - $file = $moduleInfo['file']; |
|
178 | - } |
|
179 | - $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
|
180 | - if ($moduleFunctionPath){ |
|
181 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
182 | - $functionFilePath = $moduleFunctionPath; |
|
183 | - } else{ |
|
184 | - $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
|
185 | - } |
|
186 | - if (! $functionFilePath){ |
|
187 | - $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
|
188 | - foreach($searchDir as $dir){ |
|
189 | - $filePath = $dir . $file; |
|
190 | - if (file_exists($filePath)){ |
|
191 | - $functionFilePath = $filePath; |
|
192 | - //is already found not to continue |
|
193 | - break; |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
197 | - $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
|
198 | - if ($functionFilePath){ |
|
199 | - require_once $functionFilePath; |
|
200 | - static::$loaded['function_' . $function] = $functionFilePath; |
|
201 | - $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
|
202 | - } else{ |
|
203 | - show_error('Unable to find helper file [' . $file . ']'); |
|
204 | - } |
|
205 | - } |
|
152 | + /** |
|
153 | + * Load the helper |
|
154 | + * |
|
155 | + * @param string $function the helper name to be loaded |
|
156 | + * |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public static function functions($function) { |
|
160 | + $logger = static::getLogger(); |
|
161 | + $function = str_ireplace('.php', '', $function); |
|
162 | + $function = trim($function, '/\\'); |
|
163 | + $function = str_ireplace('function_', '', $function); |
|
164 | + $file = 'function_' . $function . '.php'; |
|
165 | + $logger->debug('Loading helper [' . $function . '] ...'); |
|
166 | + if (isset(static::$loaded['function_' . $function])) { |
|
167 | + $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
|
168 | + return; |
|
169 | + } |
|
170 | + $functionFilePath = null; |
|
171 | + //first check if this helper is in the module |
|
172 | + $logger->debug('Checking helper [' . $function . '] from module list ...'); |
|
173 | + $moduleInfo = self::getModuleInfoForFunction($function); |
|
174 | + $module = $moduleInfo['module']; |
|
175 | + $function = $moduleInfo['function']; |
|
176 | + if(! empty($moduleInfo['file'])){ |
|
177 | + $file = $moduleInfo['file']; |
|
178 | + } |
|
179 | + $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
|
180 | + if ($moduleFunctionPath){ |
|
181 | + $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
182 | + $functionFilePath = $moduleFunctionPath; |
|
183 | + } else{ |
|
184 | + $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
|
185 | + } |
|
186 | + if (! $functionFilePath){ |
|
187 | + $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
|
188 | + foreach($searchDir as $dir){ |
|
189 | + $filePath = $dir . $file; |
|
190 | + if (file_exists($filePath)){ |
|
191 | + $functionFilePath = $filePath; |
|
192 | + //is already found not to continue |
|
193 | + break; |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | + $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
|
198 | + if ($functionFilePath){ |
|
199 | + require_once $functionFilePath; |
|
200 | + static::$loaded['function_' . $function] = $functionFilePath; |
|
201 | + $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
|
202 | + } else{ |
|
203 | + show_error('Unable to find helper file [' . $file . ']'); |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Load the configuration file |
|
209 | - * |
|
210 | - * @param string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config |
|
211 | - * |
|
212 | - * @return void |
|
213 | - */ |
|
214 | - public static function config($filename) { |
|
215 | - $logger = static::getLogger(); |
|
216 | - $filename = str_ireplace('.php', '', $filename); |
|
217 | - $filename = trim($filename, '/\\'); |
|
218 | - $filename = str_ireplace('config_', '', $filename); |
|
219 | - $file = 'config_' . $filename . '.php'; |
|
220 | - $logger->debug('Loading configuration [' . $filename . '] ...'); |
|
221 | - if (isset(static::$loaded['config_' . $filename])) { |
|
222 | - $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
|
223 | - return; |
|
224 | - } |
|
225 | - $configFilePath = CONFIG_PATH . $file; |
|
226 | - //first check if this config is in the module |
|
227 | - $logger->debug('Checking config [' . $filename . '] from module list ...'); |
|
228 | - $moduleInfo = self::getModuleInfoForConfig($filename); |
|
229 | - $module = $moduleInfo['module']; |
|
230 | - $filename = $moduleInfo['filename']; |
|
231 | - $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
|
232 | - if ($moduleConfigPath){ |
|
233 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
234 | - $configFilePath = $moduleConfigPath; |
|
235 | - } else{ |
|
236 | - $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
|
237 | - } |
|
238 | - $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
|
239 | - $config = array(); |
|
240 | - if (file_exists($configFilePath)){ |
|
241 | - require_once $configFilePath; |
|
242 | - if (! empty($config) && is_array($config)){ |
|
243 | - Config::setAll($config); |
|
244 | - static::$loaded['config_' . $filename] = $configFilePath; |
|
245 | - $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
|
246 | - $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
|
247 | - unset($config); |
|
248 | - } |
|
249 | - } else{ |
|
250 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
251 | - } |
|
252 | - } |
|
207 | + /** |
|
208 | + * Load the configuration file |
|
209 | + * |
|
210 | + * @param string $filename the configuration filename located at CONFIG_PATH or MODULE_PATH/config |
|
211 | + * |
|
212 | + * @return void |
|
213 | + */ |
|
214 | + public static function config($filename) { |
|
215 | + $logger = static::getLogger(); |
|
216 | + $filename = str_ireplace('.php', '', $filename); |
|
217 | + $filename = trim($filename, '/\\'); |
|
218 | + $filename = str_ireplace('config_', '', $filename); |
|
219 | + $file = 'config_' . $filename . '.php'; |
|
220 | + $logger->debug('Loading configuration [' . $filename . '] ...'); |
|
221 | + if (isset(static::$loaded['config_' . $filename])) { |
|
222 | + $logger->info('Configuration [' . $file . '] already loaded no need to load it again, cost in performance'); |
|
223 | + return; |
|
224 | + } |
|
225 | + $configFilePath = CONFIG_PATH . $file; |
|
226 | + //first check if this config is in the module |
|
227 | + $logger->debug('Checking config [' . $filename . '] from module list ...'); |
|
228 | + $moduleInfo = self::getModuleInfoForConfig($filename); |
|
229 | + $module = $moduleInfo['module']; |
|
230 | + $filename = $moduleInfo['filename']; |
|
231 | + $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
|
232 | + if ($moduleConfigPath){ |
|
233 | + $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
234 | + $configFilePath = $moduleConfigPath; |
|
235 | + } else{ |
|
236 | + $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
|
237 | + } |
|
238 | + $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
|
239 | + $config = array(); |
|
240 | + if (file_exists($configFilePath)){ |
|
241 | + require_once $configFilePath; |
|
242 | + if (! empty($config) && is_array($config)){ |
|
243 | + Config::setAll($config); |
|
244 | + static::$loaded['config_' . $filename] = $configFilePath; |
|
245 | + $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
|
246 | + $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
|
247 | + unset($config); |
|
248 | + } |
|
249 | + } else{ |
|
250 | + show_error('Unable to find config file ['. $configFilePath . ']'); |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | 254 | |
255 | - /** |
|
256 | - * Load the language |
|
257 | - * |
|
258 | - * @param string $language the language name to be loaded |
|
259 | - * |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - public static function lang($language) { |
|
263 | - $logger = static::getLogger(); |
|
264 | - $language = str_ireplace('.php', '', $language); |
|
265 | - $language = trim($language, '/\\'); |
|
266 | - $language = str_ireplace('lang_', '', $language); |
|
267 | - $file = 'lang_' . $language . '.php'; |
|
268 | - $logger->debug('Loading language [' . $language . '] ...'); |
|
269 | - if (isset(static::$loaded['lang_' . $language])) { |
|
270 | - $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
|
271 | - return; |
|
272 | - } |
|
273 | - //get the current language |
|
274 | - $appLang = self::getAppLang(); |
|
275 | - $languageFilePath = null; |
|
276 | - //first check if this language is in the module |
|
277 | - $logger->debug('Checking language [' . $language . '] from module list ...'); |
|
278 | - $moduleInfo = self::getModuleInfoForLanguage($language); |
|
279 | - $module = $moduleInfo['module']; |
|
280 | - $language = $moduleInfo['language']; |
|
281 | - if(! empty($moduleInfo['file'])){ |
|
282 | - $file = $moduleInfo['file']; |
|
283 | - } |
|
284 | - $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
|
285 | - if ($moduleLanguagePath){ |
|
286 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
287 | - $languageFilePath = $moduleLanguagePath; |
|
288 | - } else{ |
|
289 | - $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
|
290 | - } |
|
291 | - if (! $languageFilePath){ |
|
292 | - $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
|
293 | - foreach($searchDir as $dir){ |
|
294 | - $filePath = $dir . $appLang . DS . $file; |
|
295 | - if (file_exists($filePath)){ |
|
296 | - $languageFilePath = $filePath; |
|
297 | - //already found no need continue |
|
298 | - break; |
|
299 | - } |
|
300 | - } |
|
301 | - } |
|
302 | - $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
|
303 | - self::loadLanguage($languageFilePath, $language); |
|
304 | - } |
|
255 | + /** |
|
256 | + * Load the language |
|
257 | + * |
|
258 | + * @param string $language the language name to be loaded |
|
259 | + * |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + public static function lang($language) { |
|
263 | + $logger = static::getLogger(); |
|
264 | + $language = str_ireplace('.php', '', $language); |
|
265 | + $language = trim($language, '/\\'); |
|
266 | + $language = str_ireplace('lang_', '', $language); |
|
267 | + $file = 'lang_' . $language . '.php'; |
|
268 | + $logger->debug('Loading language [' . $language . '] ...'); |
|
269 | + if (isset(static::$loaded['lang_' . $language])) { |
|
270 | + $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
|
271 | + return; |
|
272 | + } |
|
273 | + //get the current language |
|
274 | + $appLang = self::getAppLang(); |
|
275 | + $languageFilePath = null; |
|
276 | + //first check if this language is in the module |
|
277 | + $logger->debug('Checking language [' . $language . '] from module list ...'); |
|
278 | + $moduleInfo = self::getModuleInfoForLanguage($language); |
|
279 | + $module = $moduleInfo['module']; |
|
280 | + $language = $moduleInfo['language']; |
|
281 | + if(! empty($moduleInfo['file'])){ |
|
282 | + $file = $moduleInfo['file']; |
|
283 | + } |
|
284 | + $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
|
285 | + if ($moduleLanguagePath){ |
|
286 | + $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
287 | + $languageFilePath = $moduleLanguagePath; |
|
288 | + } else{ |
|
289 | + $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
|
290 | + } |
|
291 | + if (! $languageFilePath){ |
|
292 | + $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
|
293 | + foreach($searchDir as $dir){ |
|
294 | + $filePath = $dir . $appLang . DS . $file; |
|
295 | + if (file_exists($filePath)){ |
|
296 | + $languageFilePath = $filePath; |
|
297 | + //already found no need continue |
|
298 | + break; |
|
299 | + } |
|
300 | + } |
|
301 | + } |
|
302 | + $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
|
303 | + self::loadLanguage($languageFilePath, $language); |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
307 | - * Return the current app language by default will use the value from cookie |
|
308 | - * if can not found will use the default value from configuration |
|
309 | - * @return string the app language like "en", "fr" |
|
310 | - */ |
|
311 | - protected static function getAppLang() { |
|
312 | - //determine the current language |
|
313 | - $appLang = get_config('default_language'); |
|
314 | - //if the language exists in the cookie use it |
|
315 | - $cfgKey = get_config('language_cookie_name'); |
|
316 | - $objCookie = & class_loader('Cookie'); |
|
317 | - $cookieLang = $objCookie->get($cfgKey); |
|
318 | - if ($cookieLang) { |
|
319 | - $appLang = $cookieLang; |
|
320 | - } |
|
321 | - return $appLang; |
|
322 | - } |
|
323 | - /** |
|
324 | - * Get the module information for the model and library to load |
|
325 | - * @param string $class the full class name like moduleName/className, className, |
|
326 | - * @return array the module information |
|
327 | - * array( |
|
328 | - * 'module'=> 'module_name' |
|
329 | - * 'class' => 'class_name' |
|
330 | - * ) |
|
331 | - */ |
|
332 | - protected static function getModuleInfoForModelLibrary($class){ |
|
333 | - $module = null; |
|
334 | - $obj = & get_instance(); |
|
335 | - if (strpos($class, '/') !== false){ |
|
336 | - $path = explode('/', $class); |
|
337 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
338 | - $module = $path[0]; |
|
339 | - $class = ucfirst($path[1]); |
|
340 | - } |
|
341 | - } else{ |
|
342 | - $class = ucfirst($class); |
|
343 | - } |
|
344 | - if (! $module && !empty($obj->moduleName)){ |
|
345 | - $module = $obj->moduleName; |
|
346 | - } |
|
347 | - return array( |
|
348 | - 'class' => $class, |
|
349 | - 'module' => $module |
|
350 | - ); |
|
351 | - } |
|
306 | + /** |
|
307 | + * Return the current app language by default will use the value from cookie |
|
308 | + * if can not found will use the default value from configuration |
|
309 | + * @return string the app language like "en", "fr" |
|
310 | + */ |
|
311 | + protected static function getAppLang() { |
|
312 | + //determine the current language |
|
313 | + $appLang = get_config('default_language'); |
|
314 | + //if the language exists in the cookie use it |
|
315 | + $cfgKey = get_config('language_cookie_name'); |
|
316 | + $objCookie = & class_loader('Cookie'); |
|
317 | + $cookieLang = $objCookie->get($cfgKey); |
|
318 | + if ($cookieLang) { |
|
319 | + $appLang = $cookieLang; |
|
320 | + } |
|
321 | + return $appLang; |
|
322 | + } |
|
323 | + /** |
|
324 | + * Get the module information for the model and library to load |
|
325 | + * @param string $class the full class name like moduleName/className, className, |
|
326 | + * @return array the module information |
|
327 | + * array( |
|
328 | + * 'module'=> 'module_name' |
|
329 | + * 'class' => 'class_name' |
|
330 | + * ) |
|
331 | + */ |
|
332 | + protected static function getModuleInfoForModelLibrary($class){ |
|
333 | + $module = null; |
|
334 | + $obj = & get_instance(); |
|
335 | + if (strpos($class, '/') !== false){ |
|
336 | + $path = explode('/', $class); |
|
337 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
338 | + $module = $path[0]; |
|
339 | + $class = ucfirst($path[1]); |
|
340 | + } |
|
341 | + } else{ |
|
342 | + $class = ucfirst($class); |
|
343 | + } |
|
344 | + if (! $module && !empty($obj->moduleName)){ |
|
345 | + $module = $obj->moduleName; |
|
346 | + } |
|
347 | + return array( |
|
348 | + 'class' => $class, |
|
349 | + 'module' => $module |
|
350 | + ); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Get the module information for the function to load |
|
355 | - * @param string $function the function name like moduleName/functionName, functionName, |
|
356 | - * @return array the module information |
|
357 | - * array( |
|
358 | - * 'module'=> 'module_name' |
|
359 | - * 'function' => 'function' |
|
360 | - * 'file' => 'file' |
|
361 | - * ) |
|
362 | - */ |
|
363 | - protected static function getModuleInfoForFunction($function) { |
|
364 | - $module = null; |
|
365 | - $file = null; |
|
366 | - $obj = & get_instance(); |
|
367 | - //check if the request class contains module name |
|
368 | - if (strpos($function, '/') !== false) { |
|
369 | - $path = explode('/', $function); |
|
370 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
371 | - $module = $path[0]; |
|
372 | - $function = 'function_' . $path[1]; |
|
373 | - $file = $path[0] . DS . $function . '.php'; |
|
374 | - } |
|
375 | - } |
|
376 | - if (!$module && !empty($obj->moduleName)) { |
|
377 | - $module = $obj->moduleName; |
|
378 | - } |
|
379 | - return array( |
|
380 | - 'function' => $function, |
|
381 | - 'module' => $module, |
|
382 | - 'file' => $file |
|
383 | - ); |
|
384 | - } |
|
353 | + /** |
|
354 | + * Get the module information for the function to load |
|
355 | + * @param string $function the function name like moduleName/functionName, functionName, |
|
356 | + * @return array the module information |
|
357 | + * array( |
|
358 | + * 'module'=> 'module_name' |
|
359 | + * 'function' => 'function' |
|
360 | + * 'file' => 'file' |
|
361 | + * ) |
|
362 | + */ |
|
363 | + protected static function getModuleInfoForFunction($function) { |
|
364 | + $module = null; |
|
365 | + $file = null; |
|
366 | + $obj = & get_instance(); |
|
367 | + //check if the request class contains module name |
|
368 | + if (strpos($function, '/') !== false) { |
|
369 | + $path = explode('/', $function); |
|
370 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
371 | + $module = $path[0]; |
|
372 | + $function = 'function_' . $path[1]; |
|
373 | + $file = $path[0] . DS . $function . '.php'; |
|
374 | + } |
|
375 | + } |
|
376 | + if (!$module && !empty($obj->moduleName)) { |
|
377 | + $module = $obj->moduleName; |
|
378 | + } |
|
379 | + return array( |
|
380 | + 'function' => $function, |
|
381 | + 'module' => $module, |
|
382 | + 'file' => $file |
|
383 | + ); |
|
384 | + } |
|
385 | 385 | |
386 | - /** |
|
387 | - * Get the module information for the language to load |
|
388 | - * @param string $language the language name like moduleName/languageName, languageName, |
|
389 | - * @return array the module information |
|
390 | - * array( |
|
391 | - * 'module'=> 'module_name' |
|
392 | - * 'language' => 'language' |
|
393 | - * 'file' => 'file' |
|
394 | - * ) |
|
395 | - */ |
|
396 | - protected static function getModuleInfoForLanguage($language) { |
|
397 | - $module = null; |
|
398 | - $file = null; |
|
399 | - $obj = & get_instance(); |
|
400 | - //check if the request class contains module name |
|
401 | - if (strpos($language, '/') !== false) { |
|
402 | - $path = explode('/', $language); |
|
403 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
404 | - $module = $path[0]; |
|
405 | - $language = 'lang_' . $path[1] . '.php'; |
|
406 | - $file = $path[0] . DS . $language; |
|
407 | - } |
|
408 | - } |
|
409 | - if (!$module && !empty($obj->moduleName)) { |
|
410 | - $module = $obj->moduleName; |
|
411 | - } |
|
412 | - return array( |
|
413 | - 'language' => $language, |
|
414 | - 'module' => $module, |
|
415 | - 'file' => $file |
|
416 | - ); |
|
417 | - } |
|
386 | + /** |
|
387 | + * Get the module information for the language to load |
|
388 | + * @param string $language the language name like moduleName/languageName, languageName, |
|
389 | + * @return array the module information |
|
390 | + * array( |
|
391 | + * 'module'=> 'module_name' |
|
392 | + * 'language' => 'language' |
|
393 | + * 'file' => 'file' |
|
394 | + * ) |
|
395 | + */ |
|
396 | + protected static function getModuleInfoForLanguage($language) { |
|
397 | + $module = null; |
|
398 | + $file = null; |
|
399 | + $obj = & get_instance(); |
|
400 | + //check if the request class contains module name |
|
401 | + if (strpos($language, '/') !== false) { |
|
402 | + $path = explode('/', $language); |
|
403 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
404 | + $module = $path[0]; |
|
405 | + $language = 'lang_' . $path[1] . '.php'; |
|
406 | + $file = $path[0] . DS . $language; |
|
407 | + } |
|
408 | + } |
|
409 | + if (!$module && !empty($obj->moduleName)) { |
|
410 | + $module = $obj->moduleName; |
|
411 | + } |
|
412 | + return array( |
|
413 | + 'language' => $language, |
|
414 | + 'module' => $module, |
|
415 | + 'file' => $file |
|
416 | + ); |
|
417 | + } |
|
418 | 418 | |
419 | 419 | |
420 | - /** |
|
421 | - * Get the module information for the config to load |
|
422 | - * @param string $filename the filename of the configuration file, |
|
423 | - * @return array the module information |
|
424 | - * array( |
|
425 | - * 'module'=> 'module_name' |
|
426 | - * 'filename' => 'filename' |
|
427 | - * ) |
|
428 | - */ |
|
429 | - protected static function getModuleInfoForConfig($filename) { |
|
430 | - $module = null; |
|
431 | - $obj = & get_instance(); |
|
432 | - //check if the request class contains module name |
|
433 | - if (strpos($filename, '/') !== false) { |
|
434 | - $path = explode('/', $filename); |
|
435 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
436 | - $module = $path[0]; |
|
437 | - $filename = $path[1] . '.php'; |
|
438 | - } |
|
439 | - } |
|
440 | - if (!$module && !empty($obj->moduleName)) { |
|
441 | - $module = $obj->moduleName; |
|
442 | - } |
|
443 | - return array( |
|
444 | - 'filename' => $filename, |
|
445 | - 'module' => $module |
|
446 | - ); |
|
447 | - } |
|
420 | + /** |
|
421 | + * Get the module information for the config to load |
|
422 | + * @param string $filename the filename of the configuration file, |
|
423 | + * @return array the module information |
|
424 | + * array( |
|
425 | + * 'module'=> 'module_name' |
|
426 | + * 'filename' => 'filename' |
|
427 | + * ) |
|
428 | + */ |
|
429 | + protected static function getModuleInfoForConfig($filename) { |
|
430 | + $module = null; |
|
431 | + $obj = & get_instance(); |
|
432 | + //check if the request class contains module name |
|
433 | + if (strpos($filename, '/') !== false) { |
|
434 | + $path = explode('/', $filename); |
|
435 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
436 | + $module = $path[0]; |
|
437 | + $filename = $path[1] . '.php'; |
|
438 | + } |
|
439 | + } |
|
440 | + if (!$module && !empty($obj->moduleName)) { |
|
441 | + $module = $obj->moduleName; |
|
442 | + } |
|
443 | + return array( |
|
444 | + 'filename' => $filename, |
|
445 | + 'module' => $module |
|
446 | + ); |
|
447 | + } |
|
448 | 448 | |
449 | - /** |
|
450 | - * Get the name of model or library instance if is null |
|
451 | - * @param string $class the class name to determine the instance |
|
452 | - * @return string the instance name |
|
453 | - */ |
|
454 | - protected static function getModelLibraryInstanceName($class){ |
|
455 | - //for module |
|
456 | - $instance = null; |
|
457 | - if (strpos($class, '/') !== false){ |
|
458 | - $path = explode('/', $class); |
|
459 | - if (isset($path[1])){ |
|
460 | - $instance = strtolower($path[1]); |
|
461 | - } |
|
462 | - } else{ |
|
463 | - $instance = strtolower($class); |
|
464 | - } |
|
465 | - return $instance; |
|
466 | - } |
|
449 | + /** |
|
450 | + * Get the name of model or library instance if is null |
|
451 | + * @param string $class the class name to determine the instance |
|
452 | + * @return string the instance name |
|
453 | + */ |
|
454 | + protected static function getModelLibraryInstanceName($class){ |
|
455 | + //for module |
|
456 | + $instance = null; |
|
457 | + if (strpos($class, '/') !== false){ |
|
458 | + $path = explode('/', $class); |
|
459 | + if (isset($path[1])){ |
|
460 | + $instance = strtolower($path[1]); |
|
461 | + } |
|
462 | + } else{ |
|
463 | + $instance = strtolower($class); |
|
464 | + } |
|
465 | + return $instance; |
|
466 | + } |
|
467 | 467 | |
468 | - /** |
|
469 | - * Get the library file path using the module information |
|
470 | - * @param string $class the class name |
|
471 | - * @return string|null the library file path otherwise null will be returned |
|
472 | - */ |
|
473 | - protected static function getLibraryPathUsingModuleInfo($class) { |
|
474 | - $logger = static::getLogger(); |
|
475 | - $libraryFilePath = null; |
|
476 | - $logger->debug('Checking library [' . $class . '] from module list ...'); |
|
477 | - $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
478 | - $module = $moduleInfo['module']; |
|
479 | - $class = $moduleInfo['class']; |
|
480 | - $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
|
481 | - if ($moduleLibraryPath){ |
|
482 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
483 | - $libraryFilePath = $moduleLibraryPath; |
|
484 | - } else{ |
|
485 | - $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
|
486 | - } |
|
487 | - return $libraryFilePath; |
|
488 | - } |
|
468 | + /** |
|
469 | + * Get the library file path using the module information |
|
470 | + * @param string $class the class name |
|
471 | + * @return string|null the library file path otherwise null will be returned |
|
472 | + */ |
|
473 | + protected static function getLibraryPathUsingModuleInfo($class) { |
|
474 | + $logger = static::getLogger(); |
|
475 | + $libraryFilePath = null; |
|
476 | + $logger->debug('Checking library [' . $class . '] from module list ...'); |
|
477 | + $moduleInfo = self::getModuleInfoForModelLibrary($class); |
|
478 | + $module = $moduleInfo['module']; |
|
479 | + $class = $moduleInfo['class']; |
|
480 | + $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
|
481 | + if ($moduleLibraryPath){ |
|
482 | + $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
483 | + $libraryFilePath = $moduleLibraryPath; |
|
484 | + } else{ |
|
485 | + $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
|
486 | + } |
|
487 | + return $libraryFilePath; |
|
488 | + } |
|
489 | 489 | |
490 | - /** |
|
491 | - * Load the library |
|
492 | - * @param string $libraryFilePath the file path of the library to load |
|
493 | - * @param string $class the class name |
|
494 | - * @param string $instance the instance |
|
495 | - * @param array $params the parameter to use |
|
496 | - * @return void |
|
497 | - */ |
|
498 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
499 | - if ($libraryFilePath){ |
|
500 | - $logger = static::getLogger(); |
|
501 | - require_once $libraryFilePath; |
|
502 | - if (class_exists($class)){ |
|
503 | - $c = $params ? new $class($params) : new $class(); |
|
504 | - $obj = & get_instance(); |
|
505 | - $obj->{$instance} = $c; |
|
506 | - static::$loaded[$instance] = $class; |
|
507 | - $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
|
508 | - } else{ |
|
509 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
510 | - } |
|
511 | - } else{ |
|
512 | - show_error('Unable to find library class [' . $class . ']'); |
|
513 | - } |
|
514 | - } |
|
490 | + /** |
|
491 | + * Load the library |
|
492 | + * @param string $libraryFilePath the file path of the library to load |
|
493 | + * @param string $class the class name |
|
494 | + * @param string $instance the instance |
|
495 | + * @param array $params the parameter to use |
|
496 | + * @return void |
|
497 | + */ |
|
498 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
499 | + if ($libraryFilePath){ |
|
500 | + $logger = static::getLogger(); |
|
501 | + require_once $libraryFilePath; |
|
502 | + if (class_exists($class)){ |
|
503 | + $c = $params ? new $class($params) : new $class(); |
|
504 | + $obj = & get_instance(); |
|
505 | + $obj->{$instance} = $c; |
|
506 | + static::$loaded[$instance] = $class; |
|
507 | + $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
|
508 | + } else{ |
|
509 | + show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
510 | + } |
|
511 | + } else{ |
|
512 | + show_error('Unable to find library class [' . $class . ']'); |
|
513 | + } |
|
514 | + } |
|
515 | 515 | |
516 | - /** |
|
517 | - * Load the language |
|
518 | - * @param string $languageFilePath the file path of the language to load |
|
519 | - * @param string $language the language name |
|
520 | - * @return void |
|
521 | - */ |
|
522 | - protected static function loadLanguage($languageFilePath, $language) { |
|
523 | - if ($languageFilePath) { |
|
524 | - $logger = static::getLogger(); |
|
525 | - $lang = array(); |
|
526 | - require_once $languageFilePath; |
|
527 | - if (!empty($lang) && is_array($lang)) { |
|
528 | - $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
529 | - //Note: may be here the class 'Lang' not yet loaded |
|
530 | - $langObj = & class_loader('Lang', 'classes'); |
|
531 | - $langObj->addLangMessages($lang); |
|
532 | - //free the memory |
|
533 | - unset($lang); |
|
534 | - } |
|
535 | - static::$loaded['lang_' . $language] = $languageFilePath; |
|
536 | - $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
|
537 | - } else{ |
|
538 | - show_error('Unable to find language [' . $language . ']'); |
|
539 | - } |
|
540 | - } |
|
516 | + /** |
|
517 | + * Load the language |
|
518 | + * @param string $languageFilePath the file path of the language to load |
|
519 | + * @param string $language the language name |
|
520 | + * @return void |
|
521 | + */ |
|
522 | + protected static function loadLanguage($languageFilePath, $language) { |
|
523 | + if ($languageFilePath) { |
|
524 | + $logger = static::getLogger(); |
|
525 | + $lang = array(); |
|
526 | + require_once $languageFilePath; |
|
527 | + if (!empty($lang) && is_array($lang)) { |
|
528 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
529 | + //Note: may be here the class 'Lang' not yet loaded |
|
530 | + $langObj = & class_loader('Lang', 'classes'); |
|
531 | + $langObj->addLangMessages($lang); |
|
532 | + //free the memory |
|
533 | + unset($lang); |
|
534 | + } |
|
535 | + static::$loaded['lang_' . $language] = $languageFilePath; |
|
536 | + $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
|
537 | + } else{ |
|
538 | + show_error('Unable to find language [' . $language . ']'); |
|
539 | + } |
|
540 | + } |
|
541 | 541 | |
542 | - /** |
|
543 | - * Get all the autoload using the configuration file |
|
544 | - * @return array |
|
545 | - */ |
|
546 | - private function getResourcesFromAutoloadConfig() { |
|
547 | - $autoloads = array(); |
|
548 | - $autoloads['config'] = array(); |
|
549 | - $autoloads['languages'] = array(); |
|
550 | - $autoloads['libraries'] = array(); |
|
551 | - $autoloads['models'] = array(); |
|
552 | - $autoloads['functions'] = array(); |
|
553 | - //loading of the resources from autoload configuration file |
|
554 | - if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
555 | - $autoload = array(); |
|
556 | - require_once CONFIG_PATH . 'autoload.php'; |
|
557 | - if (!empty($autoload) && is_array($autoload)) { |
|
558 | - $autoloads = array_merge($autoloads, $autoload); |
|
559 | - unset($autoload); |
|
560 | - } |
|
561 | - } |
|
562 | - //loading autoload configuration for modules |
|
563 | - $modulesAutoloads = Module::getModulesAutoloadConfig(); |
|
564 | - if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) { |
|
565 | - $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
|
566 | - } |
|
567 | - return $autoloads; |
|
568 | - } |
|
542 | + /** |
|
543 | + * Get all the autoload using the configuration file |
|
544 | + * @return array |
|
545 | + */ |
|
546 | + private function getResourcesFromAutoloadConfig() { |
|
547 | + $autoloads = array(); |
|
548 | + $autoloads['config'] = array(); |
|
549 | + $autoloads['languages'] = array(); |
|
550 | + $autoloads['libraries'] = array(); |
|
551 | + $autoloads['models'] = array(); |
|
552 | + $autoloads['functions'] = array(); |
|
553 | + //loading of the resources from autoload configuration file |
|
554 | + if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
555 | + $autoload = array(); |
|
556 | + require_once CONFIG_PATH . 'autoload.php'; |
|
557 | + if (!empty($autoload) && is_array($autoload)) { |
|
558 | + $autoloads = array_merge($autoloads, $autoload); |
|
559 | + unset($autoload); |
|
560 | + } |
|
561 | + } |
|
562 | + //loading autoload configuration for modules |
|
563 | + $modulesAutoloads = Module::getModulesAutoloadConfig(); |
|
564 | + if (!empty($modulesAutoloads) && is_array($modulesAutoloads)) { |
|
565 | + $autoloads = array_merge_recursive($autoloads, $modulesAutoloads); |
|
566 | + } |
|
567 | + return $autoloads; |
|
568 | + } |
|
569 | 569 | |
570 | - /** |
|
571 | - * Load the autoload configuration |
|
572 | - * @return void |
|
573 | - */ |
|
574 | - private function loadResourcesFromAutoloadConfig() { |
|
575 | - $autoloads = array(); |
|
576 | - $autoloads['config'] = array(); |
|
577 | - $autoloads['languages'] = array(); |
|
578 | - $autoloads['libraries'] = array(); |
|
579 | - $autoloads['models'] = array(); |
|
580 | - $autoloads['functions'] = array(); |
|
570 | + /** |
|
571 | + * Load the autoload configuration |
|
572 | + * @return void |
|
573 | + */ |
|
574 | + private function loadResourcesFromAutoloadConfig() { |
|
575 | + $autoloads = array(); |
|
576 | + $autoloads['config'] = array(); |
|
577 | + $autoloads['languages'] = array(); |
|
578 | + $autoloads['libraries'] = array(); |
|
579 | + $autoloads['models'] = array(); |
|
580 | + $autoloads['functions'] = array(); |
|
581 | 581 | |
582 | - $list = $this->getResourcesFromAutoloadConfig(); |
|
583 | - $autoloads = array_merge($autoloads, $list); |
|
582 | + $list = $this->getResourcesFromAutoloadConfig(); |
|
583 | + $autoloads = array_merge($autoloads, $list); |
|
584 | 584 | |
585 | - //config autoload |
|
586 | - $this->loadAutoloadResourcesArray('config', $autoloads['config']); |
|
585 | + //config autoload |
|
586 | + $this->loadAutoloadResourcesArray('config', $autoloads['config']); |
|
587 | 587 | |
588 | - //languages autoload |
|
589 | - $this->loadAutoloadResourcesArray('lang', $autoloads['languages']); |
|
588 | + //languages autoload |
|
589 | + $this->loadAutoloadResourcesArray('lang', $autoloads['languages']); |
|
590 | 590 | |
591 | - //libraries autoload |
|
592 | - $this->loadAutoloadResourcesArray('library', $autoloads['libraries']); |
|
591 | + //libraries autoload |
|
592 | + $this->loadAutoloadResourcesArray('library', $autoloads['libraries']); |
|
593 | 593 | |
594 | - //models autoload |
|
595 | - $this->loadAutoloadResourcesArray('model', $autoloads['models']); |
|
594 | + //models autoload |
|
595 | + $this->loadAutoloadResourcesArray('model', $autoloads['models']); |
|
596 | 596 | |
597 | - //functions autoload |
|
598 | - $this->loadAutoloadResourcesArray('functions', $autoloads['functions']); |
|
599 | - } |
|
597 | + //functions autoload |
|
598 | + $this->loadAutoloadResourcesArray('functions', $autoloads['functions']); |
|
599 | + } |
|
600 | 600 | |
601 | - /** |
|
602 | - * Load the resources autoload array |
|
603 | - * @param string $method this object method name to call |
|
604 | - * @param array $resources the resource to load |
|
605 | - * @return void |
|
606 | - */ |
|
607 | - private function loadAutoloadResourcesArray($method, array $resources) { |
|
608 | - foreach ($resources as $name) { |
|
609 | - $this->{$method}($name); |
|
610 | - } |
|
611 | - } |
|
612 | - } |
|
601 | + /** |
|
602 | + * Load the resources autoload array |
|
603 | + * @param string $method this object method name to call |
|
604 | + * @param array $resources the resource to load |
|
605 | + * @return void |
|
606 | + */ |
|
607 | + private function loadAutoloadResourcesArray($method, array $resources) { |
|
608 | + foreach ($resources as $name) { |
|
609 | + $this->{$method}($name); |
|
610 | + } |
|
611 | + } |
|
612 | + } |
@@ -74,25 +74,25 @@ discard block |
||
74 | 74 | $class = $moduleInfo['class']; |
75 | 75 | |
76 | 76 | $moduleModelFilePath = Module::findModelFullPath($class, $module); |
77 | - if ($moduleModelFilePath){ |
|
78 | - $logger->info('Found model [' . $class . '] from module [' .$module. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
77 | + if ($moduleModelFilePath) { |
|
78 | + $logger->info('Found model [' . $class . '] from module [' . $module . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
79 | 79 | $classFilePath = $moduleModelFilePath; |
80 | - } else{ |
|
80 | + } else { |
|
81 | 81 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
82 | 82 | } |
83 | 83 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
84 | - if (file_exists($classFilePath)){ |
|
84 | + if (file_exists($classFilePath)) { |
|
85 | 85 | require_once $classFilePath; |
86 | - if (class_exists($class)){ |
|
86 | + if (class_exists($class)) { |
|
87 | 87 | $c = new $class(); |
88 | 88 | $obj = & get_instance(); |
89 | 89 | $obj->{$instance} = $c; |
90 | 90 | static::$loaded[$instance] = $class; |
91 | 91 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
92 | - } else{ |
|
93 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
92 | + } else { |
|
93 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
94 | 94 | } |
95 | - } else{ |
|
95 | + } else { |
|
96 | 96 | show_error('Unable to find the model [' . $class . ']'); |
97 | 97 | } |
98 | 98 | } |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | } |
132 | 132 | $libraryFilePath = null; |
133 | 133 | $logger->debug('Check if this is a system library ...'); |
134 | - if (file_exists(CORE_LIBRARY_PATH . $file)){ |
|
134 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
135 | 135 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
136 | 136 | $class = ucfirst($class); |
137 | 137 | $logger->info('This library is a system library'); |
138 | - } else{ |
|
138 | + } else { |
|
139 | 139 | $logger->info('This library is not a system library'); |
140 | 140 | //first check if this library is in the module |
141 | 141 | $libraryFilePath = self::getLibraryPathUsingModuleInfo($class); |
142 | 142 | //*************** |
143 | 143 | } |
144 | - if (! $libraryFilePath && file_exists(LIBRARY_PATH . $file)){ |
|
144 | + if (!$libraryFilePath && file_exists(LIBRARY_PATH . $file)) { |
|
145 | 145 | $libraryFilePath = LIBRARY_PATH . $file; |
146 | 146 | } |
147 | 147 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
@@ -173,21 +173,21 @@ discard block |
||
173 | 173 | $moduleInfo = self::getModuleInfoForFunction($function); |
174 | 174 | $module = $moduleInfo['module']; |
175 | 175 | $function = $moduleInfo['function']; |
176 | - if(! empty($moduleInfo['file'])){ |
|
176 | + if (!empty($moduleInfo['file'])) { |
|
177 | 177 | $file = $moduleInfo['file']; |
178 | 178 | } |
179 | 179 | $moduleFunctionPath = Module::findFunctionFullPath($function, $module); |
180 | - if ($moduleFunctionPath){ |
|
181 | - $logger->info('Found helper [' . $function . '] from module [' .$module. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
180 | + if ($moduleFunctionPath) { |
|
181 | + $logger->info('Found helper [' . $function . '] from module [' . $module . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
182 | 182 | $functionFilePath = $moduleFunctionPath; |
183 | - } else{ |
|
183 | + } else { |
|
184 | 184 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
185 | 185 | } |
186 | - if (! $functionFilePath){ |
|
186 | + if (!$functionFilePath) { |
|
187 | 187 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
188 | - foreach($searchDir as $dir){ |
|
188 | + foreach ($searchDir as $dir) { |
|
189 | 189 | $filePath = $dir . $file; |
190 | - if (file_exists($filePath)){ |
|
190 | + if (file_exists($filePath)) { |
|
191 | 191 | $functionFilePath = $filePath; |
192 | 192 | //is already found not to continue |
193 | 193 | break; |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | } |
196 | 196 | } |
197 | 197 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
198 | - if ($functionFilePath){ |
|
198 | + if ($functionFilePath) { |
|
199 | 199 | require_once $functionFilePath; |
200 | 200 | static::$loaded['function_' . $function] = $functionFilePath; |
201 | 201 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
202 | - } else{ |
|
202 | + } else { |
|
203 | 203 | show_error('Unable to find helper file [' . $file . ']'); |
204 | 204 | } |
205 | 205 | } |
@@ -229,25 +229,25 @@ discard block |
||
229 | 229 | $module = $moduleInfo['module']; |
230 | 230 | $filename = $moduleInfo['filename']; |
231 | 231 | $moduleConfigPath = Module::findConfigFullPath($filename, $module); |
232 | - if ($moduleConfigPath){ |
|
233 | - $logger->info('Found config [' . $filename . '] from module [' .$module. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
232 | + if ($moduleConfigPath) { |
|
233 | + $logger->info('Found config [' . $filename . '] from module [' . $module . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
234 | 234 | $configFilePath = $moduleConfigPath; |
235 | - } else{ |
|
235 | + } else { |
|
236 | 236 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
237 | 237 | } |
238 | 238 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
239 | 239 | $config = array(); |
240 | - if (file_exists($configFilePath)){ |
|
240 | + if (file_exists($configFilePath)) { |
|
241 | 241 | require_once $configFilePath; |
242 | - if (! empty($config) && is_array($config)){ |
|
242 | + if (!empty($config) && is_array($config)) { |
|
243 | 243 | Config::setAll($config); |
244 | 244 | static::$loaded['config_' . $filename] = $configFilePath; |
245 | 245 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
246 | 246 | $logger->info('The custom application configuration loaded are listed below: ' . stringfy_vars($config)); |
247 | 247 | unset($config); |
248 | 248 | } |
249 | - } else{ |
|
250 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
249 | + } else { |
|
250 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | $moduleInfo = self::getModuleInfoForLanguage($language); |
279 | 279 | $module = $moduleInfo['module']; |
280 | 280 | $language = $moduleInfo['language']; |
281 | - if(! empty($moduleInfo['file'])){ |
|
281 | + if (!empty($moduleInfo['file'])) { |
|
282 | 282 | $file = $moduleInfo['file']; |
283 | 283 | } |
284 | 284 | $moduleLanguagePath = Module::findLanguageFullPath($language, $appLang, $module); |
285 | - if ($moduleLanguagePath){ |
|
286 | - $logger->info('Found language [' . $language . '] from module [' .$module. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
285 | + if ($moduleLanguagePath) { |
|
286 | + $logger->info('Found language [' . $language . '] from module [' . $module . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
287 | 287 | $languageFilePath = $moduleLanguagePath; |
288 | - } else{ |
|
288 | + } else { |
|
289 | 289 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
290 | 290 | } |
291 | - if (! $languageFilePath){ |
|
291 | + if (!$languageFilePath) { |
|
292 | 292 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
293 | - foreach($searchDir as $dir){ |
|
293 | + foreach ($searchDir as $dir) { |
|
294 | 294 | $filePath = $dir . $appLang . DS . $file; |
295 | - if (file_exists($filePath)){ |
|
295 | + if (file_exists($filePath)) { |
|
296 | 296 | $languageFilePath = $filePath; |
297 | 297 | //already found no need continue |
298 | 298 | break; |
@@ -329,19 +329,19 @@ discard block |
||
329 | 329 | * 'class' => 'class_name' |
330 | 330 | * ) |
331 | 331 | */ |
332 | - protected static function getModuleInfoForModelLibrary($class){ |
|
332 | + protected static function getModuleInfoForModelLibrary($class) { |
|
333 | 333 | $module = null; |
334 | 334 | $obj = & get_instance(); |
335 | - if (strpos($class, '/') !== false){ |
|
335 | + if (strpos($class, '/') !== false) { |
|
336 | 336 | $path = explode('/', $class); |
337 | - if (isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
337 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
338 | 338 | $module = $path[0]; |
339 | 339 | $class = ucfirst($path[1]); |
340 | 340 | } |
341 | - } else{ |
|
341 | + } else { |
|
342 | 342 | $class = ucfirst($class); |
343 | 343 | } |
344 | - if (! $module && !empty($obj->moduleName)){ |
|
344 | + if (!$module && !empty($obj->moduleName)) { |
|
345 | 345 | $module = $obj->moduleName; |
346 | 346 | } |
347 | 347 | return array( |
@@ -451,15 +451,15 @@ discard block |
||
451 | 451 | * @param string $class the class name to determine the instance |
452 | 452 | * @return string the instance name |
453 | 453 | */ |
454 | - protected static function getModelLibraryInstanceName($class){ |
|
454 | + protected static function getModelLibraryInstanceName($class) { |
|
455 | 455 | //for module |
456 | 456 | $instance = null; |
457 | - if (strpos($class, '/') !== false){ |
|
457 | + if (strpos($class, '/') !== false) { |
|
458 | 458 | $path = explode('/', $class); |
459 | - if (isset($path[1])){ |
|
459 | + if (isset($path[1])) { |
|
460 | 460 | $instance = strtolower($path[1]); |
461 | 461 | } |
462 | - } else{ |
|
462 | + } else { |
|
463 | 463 | $instance = strtolower($class); |
464 | 464 | } |
465 | 465 | return $instance; |
@@ -478,10 +478,10 @@ discard block |
||
478 | 478 | $module = $moduleInfo['module']; |
479 | 479 | $class = $moduleInfo['class']; |
480 | 480 | $moduleLibraryPath = Module::findLibraryFullPath($class, $module); |
481 | - if ($moduleLibraryPath){ |
|
482 | - $logger->info('Found library [' . $class . '] from module [' .$module. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
481 | + if ($moduleLibraryPath) { |
|
482 | + $logger->info('Found library [' . $class . '] from module [' . $module . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
483 | 483 | $libraryFilePath = $moduleLibraryPath; |
484 | - } else{ |
|
484 | + } else { |
|
485 | 485 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
486 | 486 | } |
487 | 487 | return $libraryFilePath; |
@@ -495,20 +495,20 @@ discard block |
||
495 | 495 | * @param array $params the parameter to use |
496 | 496 | * @return void |
497 | 497 | */ |
498 | - protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()){ |
|
499 | - if ($libraryFilePath){ |
|
498 | + protected static function loadLibrary($libraryFilePath, $class, $instance, $params = array()) { |
|
499 | + if ($libraryFilePath) { |
|
500 | 500 | $logger = static::getLogger(); |
501 | 501 | require_once $libraryFilePath; |
502 | - if (class_exists($class)){ |
|
502 | + if (class_exists($class)) { |
|
503 | 503 | $c = $params ? new $class($params) : new $class(); |
504 | 504 | $obj = & get_instance(); |
505 | 505 | $obj->{$instance} = $c; |
506 | 506 | static::$loaded[$instance] = $class; |
507 | 507 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
508 | - } else{ |
|
509 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
508 | + } else { |
|
509 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
510 | 510 | } |
511 | - } else{ |
|
511 | + } else { |
|
512 | 512 | show_error('Unable to find library class [' . $class . ']'); |
513 | 513 | } |
514 | 514 | } |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | } |
535 | 535 | static::$loaded['lang_' . $language] = $languageFilePath; |
536 | 536 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
537 | - } else{ |
|
537 | + } else { |
|
538 | 538 | show_error('Unable to find language [' . $language . ']'); |
539 | 539 | } |
540 | 540 | } |
@@ -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 Controller extends BaseClass{ |
|
27 | + class Controller extends BaseClass { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The name of the module if this controller belong to an module |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * Class constructor |
44 | 44 | */ |
45 | - public function __construct(){ |
|
45 | + public function __construct() { |
|
46 | 46 | parent::__construct(); |
47 | 47 | |
48 | 48 | //instance of the super object |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | |
51 | 51 | //Load the resources loaded during the application bootstrap |
52 | 52 | $this->logger->debug('Adding the loaded classes to the super instance'); |
53 | - foreach (class_loaded() as $var => $class){ |
|
54 | - $this->$var =& class_loader($class); |
|
53 | + foreach (class_loaded() as $var => $class) { |
|
54 | + $this->$var = & class_loader($class); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | //set module using the router |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * This method is used to set the module name |
85 | 85 | */ |
86 | - protected function setModuleNameFromRouter(){ |
|
86 | + protected function setModuleNameFromRouter() { |
|
87 | 87 | //set the module using the router instance |
88 | - if(isset($this->router) && $this->router->getModule()){ |
|
88 | + if (isset($this->router) && $this->router->getModule()) { |
|
89 | 89 | $this->moduleName = $this->router->getModule(); |
90 | 90 | } |
91 | 91 | } |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | * Set the cache using the argument otherwise will use the configuration |
95 | 95 | * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
96 | 96 | */ |
97 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
97 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null) { |
|
98 | 98 | $this->logger->debug('Setting the cache handler instance'); |
99 | 99 | //set cache handler instance |
100 | - if(get_config('cache_enable', false)){ |
|
101 | - if ($cache !== null){ |
|
100 | + if (get_config('cache_enable', false)) { |
|
101 | + if ($cache !== null) { |
|
102 | 102 | $this->cache = $cache; |
103 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
103 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
104 | 104 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
105 | 105 | unset($this->{strtolower(get_config('cache_handler'))}); |
106 | 106 | } |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | * This method is used to load the required resources for framework to work |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - private function loadRequiredResources(){ |
|
115 | + private function loadRequiredResources() { |
|
116 | 116 | $this->logger->debug('Loading the required classes into super instance'); |
117 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
118 | - $this->loader =& class_loader('Loader', 'classes'); |
|
119 | - $this->lang =& class_loader('Lang', 'classes'); |
|
120 | - $this->request =& class_loader('Request', 'classes'); |
|
117 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
118 | + $this->loader = & class_loader('Loader', 'classes'); |
|
119 | + $this->lang = & class_loader('Lang', 'classes'); |
|
120 | + $this->request = & class_loader('Request', 'classes'); |
|
121 | 121 | //dispatch the request instance created event |
122 | 122 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
123 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
123 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | } |
@@ -42,41 +42,41 @@ |
||
42 | 42 | 'sbrowser' => '', //VARCHAR(255) |
43 | 43 | 'skey' => '' //VARCHAR(255) |
44 | 44 | ); |
45 | - */ |
|
46 | - protected $sessionTableColumns = array(); |
|
45 | + */ |
|
46 | + protected $sessionTableColumns = array(); |
|
47 | 47 | |
48 | - public function __construct(Database $db = null) { |
|
49 | - parent::__construct($db); |
|
50 | - } |
|
48 | + public function __construct(Database $db = null) { |
|
49 | + parent::__construct($db); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Return the session database table columns |
|
54 | - * @return array |
|
55 | - */ |
|
56 | - public function getSessionTableColumns() { |
|
57 | - return $this->sessionTableColumns; |
|
58 | - } |
|
52 | + /** |
|
53 | + * Return the session database table columns |
|
54 | + * @return array |
|
55 | + */ |
|
56 | + public function getSessionTableColumns() { |
|
57 | + return $this->sessionTableColumns; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Set the session database table columns |
|
62 | - * @param array $columns the columns definition |
|
63 | - */ |
|
64 | - public function setSessionTableColumns(array $columns) { |
|
65 | - $this->sessionTableColumns = $columns; |
|
66 | - return $this; |
|
67 | - } |
|
60 | + /** |
|
61 | + * Set the session database table columns |
|
62 | + * @param array $columns the columns definition |
|
63 | + */ |
|
64 | + public function setSessionTableColumns(array $columns) { |
|
65 | + $this->sessionTableColumns = $columns; |
|
66 | + return $this; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Delete the expire session |
|
71 | - * @param int $time the unix timestamp |
|
72 | - * @return int affected rows |
|
73 | - */ |
|
74 | - abstract public function deleteByTime($time); |
|
69 | + /** |
|
70 | + * Delete the expire session |
|
71 | + * @param int $time the unix timestamp |
|
72 | + * @return int affected rows |
|
73 | + */ |
|
74 | + abstract public function deleteByTime($time); |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * How to get the value of the table column key. Generally is the session key |
|
79 | - * @return mixed the key value like used to identify the data |
|
80 | - */ |
|
81 | - abstract public function getKeyValue(); |
|
82 | - } |
|
77 | + /** |
|
78 | + * How to get the value of the table column key. Generally is the session key |
|
79 | + * @return mixed the key value like used to identify the data |
|
80 | + */ |
|
81 | + abstract public function getKeyValue(); |
|
82 | + } |
@@ -145,12 +145,12 @@ discard block |
||
145 | 145 | * Initialise the model, tie into the CodeIgniter superobject and |
146 | 146 | * try our best to guess the table name. |
147 | 147 | */ |
148 | - public function __construct(Database $db = null){ |
|
149 | - if (is_object($db)){ |
|
148 | + public function __construct(Database $db = null) { |
|
149 | + if (is_object($db)) { |
|
150 | 150 | $this->setDatabaseInstance($db); |
151 | - } else{ |
|
151 | + } else { |
|
152 | 152 | $obj = & get_instance(); |
153 | - if (isset($obj->database) && is_object($obj->database)){ |
|
153 | + if (isset($obj->database) && is_object($obj->database)) { |
|
154 | 154 | /** |
155 | 155 | * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
156 | 156 | * to prevent duplication |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | $this->trigger('before_get'); |
229 | 229 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
230 | 230 | { |
231 | - $this->getQueryBuilder()->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
231 | + $this->getQueryBuilder()->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
232 | 232 | } |
233 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
233 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
234 | 234 | $this->getQueryBuilder()->from($this->_table); |
235 | 235 | $result = $this->_database->getAll($type); |
236 | 236 | $this->_temporary_return_type = $this->return_type; |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $insert_id = $this->_database->insertId(); |
264 | 264 | $this->trigger('after_create', $insert_id); |
265 | 265 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
266 | - return ! $insert_id ? true : $insert_id; |
|
266 | + return !$insert_id ? true : $insert_id; |
|
267 | 267 | } |
268 | 268 | else |
269 | 269 | { |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | if ($this->soft_delete) |
384 | 384 | { |
385 | 385 | $this->getQueryBuilder()->from($this->_table); |
386 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
386 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
387 | 387 | } |
388 | 388 | else |
389 | 389 | { |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | if ($this->soft_delete) |
408 | 408 | { |
409 | 409 | $this->getQueryBuilder()->from($this->_table); |
410 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
410 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
411 | 411 | } |
412 | 412 | else |
413 | 413 | { |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | if ($this->soft_delete) |
430 | 430 | { |
431 | 431 | $this->getQueryBuilder()->from($this->_table); |
432 | - $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
|
432 | + $result = $this->_database->update(array($this->soft_delete_key => TRUE)); |
|
433 | 433 | } |
434 | 434 | else |
435 | 435 | { |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | /** |
550 | 550 | * Enabled cache temporary |
551 | 551 | */ |
552 | - public function cached($ttl = 0){ |
|
553 | - if ($ttl > 0){ |
|
552 | + public function cached($ttl = 0) { |
|
553 | + if ($ttl > 0) { |
|
554 | 554 | $this->_database = $this->_database->cached($ttl); |
555 | 555 | } |
556 | 556 | return $this; |
@@ -701,13 +701,13 @@ discard block |
||
701 | 701 | { |
702 | 702 | if (is_object($row)) |
703 | 703 | { |
704 | - if (isset($row->$attr)){ |
|
704 | + if (isset($row->$attr)) { |
|
705 | 705 | unset($row->$attr); |
706 | 706 | } |
707 | 707 | } |
708 | 708 | else |
709 | 709 | { |
710 | - if (isset($row[$attr])){ |
|
710 | + if (isset($row[$attr])) { |
|
711 | 711 | unset($row[$attr]); |
712 | 712 | } |
713 | 713 | } |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * Return the database instance |
720 | 720 | * @return Database the database instance |
721 | 721 | */ |
722 | - public function getDatabaseInstance(){ |
|
722 | + public function getDatabaseInstance() { |
|
723 | 723 | return $this->_database; |
724 | 724 | } |
725 | 725 | |
@@ -727,9 +727,9 @@ discard block |
||
727 | 727 | * set the Database instance for future use |
728 | 728 | * @param Database $db the database object |
729 | 729 | */ |
730 | - public function setDatabaseInstance($db){ |
|
730 | + public function setDatabaseInstance($db) { |
|
731 | 731 | $this->_database = $db; |
732 | - if ($this->dbCacheTime > 0){ |
|
732 | + if ($this->dbCacheTime > 0) { |
|
733 | 733 | $this->_database->setCache($this->dbCacheTime); |
734 | 734 | } |
735 | 735 | return $this; |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | * @param Loader $loader the loader object |
749 | 749 | * @return object |
750 | 750 | */ |
751 | - public function setLoader($loader){ |
|
751 | + public function setLoader($loader) { |
|
752 | 752 | $this->loaderInstance = $loader; |
753 | 753 | return $this; |
754 | 754 | } |
@@ -766,7 +766,7 @@ discard block |
||
766 | 766 | * @param object $queryBuilder the DatabaseQueryBuilder object |
767 | 767 | * @return object |
768 | 768 | */ |
769 | - public function setQueryBuilder($queryBuilder){ |
|
769 | + public function setQueryBuilder($queryBuilder) { |
|
770 | 770 | $this->_database->setQueryBuilder($queryBuilder); |
771 | 771 | return $this; |
772 | 772 | } |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | * @param FormValidation $fv the form validation object |
786 | 786 | * @return object |
787 | 787 | */ |
788 | - public function setFormValidation($fv){ |
|
788 | + public function setFormValidation($fv) { |
|
789 | 789 | $this->formValidationInstance = $fv; |
790 | 790 | return $this; |
791 | 791 | } |
@@ -829,13 +829,13 @@ discard block |
||
829 | 829 | * relate for the relation "belongs_to" |
830 | 830 | * @return mixed |
831 | 831 | */ |
832 | - protected function relateBelongsTo($row){ |
|
832 | + protected function relateBelongsTo($row) { |
|
833 | 833 | foreach ($this->belongs_to as $key => $value) |
834 | 834 | { |
835 | 835 | if (is_string($value)) |
836 | 836 | { |
837 | 837 | $relationship = $value; |
838 | - $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
|
838 | + $options = array('primary_key' => $value . '_id', 'model' => $value . '_model'); |
|
839 | 839 | } else |
840 | 840 | { |
841 | 841 | $relationship = $key; |
@@ -867,13 +867,13 @@ discard block |
||
867 | 867 | * relate for the relation "has_many" |
868 | 868 | * @return mixed |
869 | 869 | */ |
870 | - protected function relateHasMany($row){ |
|
870 | + protected function relateHasMany($row) { |
|
871 | 871 | foreach ($this->has_many as $key => $value) |
872 | 872 | { |
873 | 873 | if (is_string($value)) |
874 | 874 | { |
875 | 875 | $relationship = $value; |
876 | - $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
|
876 | + $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model'); |
|
877 | 877 | } else |
878 | 878 | { |
879 | 879 | $relationship = $key; |
@@ -934,7 +934,7 @@ discard block |
||
934 | 934 | return $data; |
935 | 935 | } |
936 | 936 | $fv = $this->formValidationInstance; |
937 | - if (! is_object($fv)){ |
|
937 | + if (!is_object($fv)) { |
|
938 | 938 | Loader::library('FormValidation'); |
939 | 939 | $fv = $this->formvalidation; |
940 | 940 | $this->setFormValidation($fv); |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | * Set WHERE parameters, when is array |
955 | 955 | * @param array $params |
956 | 956 | */ |
957 | - protected function _set_where_array(array $params){ |
|
957 | + protected function _set_where_array(array $params) { |
|
958 | 958 | foreach ($params as $field => $filter) |
959 | 959 | { |
960 | 960 | if (is_array($filter)) |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | /** |
1021 | 1021 | Shortcut to controller |
1022 | 1022 | */ |
1023 | - public function __get($key){ |
|
1023 | + public function __get($key) { |
|
1024 | 1024 | return get_instance()->{$key}; |
1025 | 1025 | } |
1026 | 1026 |
@@ -264,8 +264,7 @@ discard block |
||
264 | 264 | $this->trigger('after_create', $insert_id); |
265 | 265 | //if the table doesn't have the auto increment field or sequence, the value of 0 will be returned |
266 | 266 | return ! $insert_id ? true : $insert_id; |
267 | - } |
|
268 | - else |
|
267 | + } else |
|
269 | 268 | { |
270 | 269 | return FALSE; |
271 | 270 | } |
@@ -342,8 +341,7 @@ discard block |
||
342 | 341 | if (is_array($args[1])) { |
343 | 342 | $data = array_pop($args); |
344 | 343 | } |
345 | - } |
|
346 | - else if (count($args) == 3) { |
|
344 | + } else if (count($args) == 3) { |
|
347 | 345 | if (is_array($args[2])) { |
348 | 346 | $data = array_pop($args); |
349 | 347 | } |
@@ -384,8 +382,7 @@ discard block |
||
384 | 382 | { |
385 | 383 | $this->getQueryBuilder()->from($this->_table); |
386 | 384 | $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
387 | - } |
|
388 | - else |
|
385 | + } else |
|
389 | 386 | { |
390 | 387 | $this->getQueryBuilder()->from($this->_table); |
391 | 388 | $result = $this->_database->delete(); |
@@ -408,8 +405,7 @@ discard block |
||
408 | 405 | { |
409 | 406 | $this->getQueryBuilder()->from($this->_table); |
410 | 407 | $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
411 | - } |
|
412 | - else |
|
408 | + } else |
|
413 | 409 | { |
414 | 410 | $this->getQueryBuilder()->from($this->_table); |
415 | 411 | $result = $this->_database->delete(); |
@@ -430,8 +426,7 @@ discard block |
||
430 | 426 | { |
431 | 427 | $this->getQueryBuilder()->from($this->_table); |
432 | 428 | $result = $this->_database->update(array( $this->soft_delete_key => TRUE )); |
433 | - } |
|
434 | - else |
|
429 | + } else |
|
435 | 430 | { |
436 | 431 | $this->getQueryBuilder()->from($this->_table); |
437 | 432 | $result = $this->_database->delete(); |
@@ -704,8 +699,7 @@ discard block |
||
704 | 699 | if (isset($row->$attr)){ |
705 | 700 | unset($row->$attr); |
706 | 701 | } |
707 | - } |
|
708 | - else |
|
702 | + } else |
|
709 | 703 | { |
710 | 704 | if (isset($row[$attr])){ |
711 | 705 | unset($row[$attr]); |
@@ -846,15 +840,13 @@ discard block |
||
846 | 840 | { |
847 | 841 | if (is_object($this->loaderInstance)) { |
848 | 842 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
849 | - } |
|
850 | - else { |
|
843 | + } else { |
|
851 | 844 | Loader::model($options['model'], $relationship . '_model'); |
852 | 845 | } |
853 | 846 | if (is_object($row)) |
854 | 847 | { |
855 | 848 | $row->{$relationship} = $this->{$relationship . '_model'}->get($row->{$options['primary_key']}); |
856 | - } |
|
857 | - else |
|
849 | + } else |
|
858 | 850 | { |
859 | 851 | $row[$relationship] = $this->{$relationship . '_model'}->get($row[$options['primary_key']]); |
860 | 852 | } |
@@ -884,15 +876,13 @@ discard block |
||
884 | 876 | { |
885 | 877 | if (is_object($this->loaderInstance)) { |
886 | 878 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
887 | - } |
|
888 | - else { |
|
879 | + } else { |
|
889 | 880 | Loader::model($options['model'], $relationship . '_model'); |
890 | 881 | } |
891 | 882 | if (is_object($row)) |
892 | 883 | { |
893 | 884 | $row->{$relationship} = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row->{$this->primary_key}); |
894 | - } |
|
895 | - else |
|
885 | + } else |
|
896 | 886 | { |
897 | 887 | $row[$relationship] = $this->{$relationship . '_model'}->get_many_by($options['primary_key'], $row[$this->primary_key]); |
898 | 888 | } |
@@ -960,14 +950,12 @@ discard block |
||
960 | 950 | if (is_array($filter)) |
961 | 951 | { |
962 | 952 | $this->getQueryBuilder()->in($field, $filter); |
963 | - } |
|
964 | - else |
|
953 | + } else |
|
965 | 954 | { |
966 | 955 | if (is_int($field)) |
967 | 956 | { |
968 | 957 | $this->getQueryBuilder()->where($filter); |
969 | - } |
|
970 | - else |
|
958 | + } else |
|
971 | 959 | { |
972 | 960 | $this->getQueryBuilder()->where($field, $filter); |
973 | 961 | } |
@@ -984,33 +972,27 @@ discard block |
||
984 | 972 | if (count($params) == 1 && is_array($params[0])) |
985 | 973 | { |
986 | 974 | $this->_set_where_array($params[0]); |
987 | - } |
|
988 | - else if (count($params) == 1) |
|
975 | + } else if (count($params) == 1) |
|
989 | 976 | { |
990 | 977 | $this->getQueryBuilder()->where($params[0]); |
991 | - } |
|
992 | - else if (count($params) == 2) |
|
978 | + } else if (count($params) == 2) |
|
993 | 979 | { |
994 | 980 | if (is_array($params[1])) |
995 | 981 | { |
996 | 982 | $this->getQueryBuilder()->in($params[0], $params[1]); |
997 | - } |
|
998 | - else |
|
983 | + } else |
|
999 | 984 | { |
1000 | 985 | $this->getQueryBuilder()->where($params[0], $params[1]); |
1001 | 986 | } |
1002 | - } |
|
1003 | - else if (count($params) == 3) |
|
987 | + } else if (count($params) == 3) |
|
1004 | 988 | { |
1005 | 989 | $this->getQueryBuilder()->where($params[0], $params[1], $params[2]); |
1006 | - } |
|
1007 | - else |
|
990 | + } else |
|
1008 | 991 | { |
1009 | 992 | if (is_array($params[1])) |
1010 | 993 | { |
1011 | 994 | $this->getQueryBuilder()->in($params[0], $params[1]); |
1012 | - } |
|
1013 | - else |
|
995 | + } else |
|
1014 | 996 | { |
1015 | 997 | $this->getQueryBuilder()->where($params[0], $params[1]); |
1016 | 998 | } |
@@ -1,199 +1,199 @@ |
||
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 | - |
|
27 | - /** |
|
28 | - * For application languages management |
|
29 | - */ |
|
30 | - class Lang extends BaseClass { |
|
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 | + |
|
27 | + /** |
|
28 | + * For application languages management |
|
29 | + */ |
|
30 | + class Lang extends BaseClass { |
|
31 | 31 | |
32 | - /** |
|
33 | - * The supported available language for this application. |
|
34 | - * @example "en" => "english" |
|
35 | - * @see Lang::addLang() |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $availables = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * The all messages language |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - protected $languages = array(); |
|
45 | - |
|
46 | - /** |
|
47 | - * The default language to use if can not |
|
48 | - * determine the client language |
|
49 | - * |
|
50 | - * @example $default = 'en' |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $default = null; |
|
54 | - |
|
55 | - /** |
|
56 | - * The current client language |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $current = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * Construct new Lang instance |
|
63 | - */ |
|
64 | - public function __construct() { |
|
65 | - parent::__construct(); |
|
66 | - |
|
67 | - $this->default = get_config('default_language', 'en'); |
|
68 | - $this->logger->debug('Setting the supported languages'); |
|
32 | + /** |
|
33 | + * The supported available language for this application. |
|
34 | + * @example "en" => "english" |
|
35 | + * @see Lang::addLang() |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $availables = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * The all messages language |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + protected $languages = array(); |
|
45 | + |
|
46 | + /** |
|
47 | + * The default language to use if can not |
|
48 | + * determine the client language |
|
49 | + * |
|
50 | + * @example $default = 'en' |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $default = null; |
|
54 | + |
|
55 | + /** |
|
56 | + * The current client language |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $current = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * Construct new Lang instance |
|
63 | + */ |
|
64 | + public function __construct() { |
|
65 | + parent::__construct(); |
|
66 | + |
|
67 | + $this->default = get_config('default_language', 'en'); |
|
68 | + $this->logger->debug('Setting the supported languages'); |
|
69 | 69 | |
70 | - //add the supported languages ('key', 'display name') |
|
71 | - $languages = get_config('languages', null); |
|
72 | - if (!empty($languages)) { |
|
73 | - foreach ($languages as $key => $displayName) { |
|
74 | - $this->addLang($key, $displayName); |
|
75 | - } |
|
76 | - } |
|
77 | - unset($languages); |
|
78 | - |
|
79 | - //if the language exists in cookie use it |
|
80 | - $cfgKey = get_config('language_cookie_name'); |
|
81 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
82 | - $objCookie = & class_loader('Cookie'); |
|
83 | - $cookieLang = $objCookie->get($cfgKey); |
|
84 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
85 | - $this->current = $cookieLang; |
|
86 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
87 | - } else{ |
|
88 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
89 | - $this->current = $this->getDefault(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Get the all languages messages |
|
95 | - * |
|
96 | - * @return array the language message list |
|
97 | - */ |
|
98 | - public function getAll() { |
|
99 | - return $this->languages; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Set the language message |
|
104 | - * |
|
105 | - * @param string $key the language key to identify |
|
106 | - * @param string $value the language message value |
|
107 | - */ |
|
108 | - public function set($key, $value) { |
|
109 | - $this->languages[$key] = $value; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Get the language message for the given key. If can't find return the default value |
|
114 | - * |
|
115 | - * @param string $key the message language key |
|
116 | - * @param string $default the default value to return if can not found the language message key |
|
117 | - * |
|
118 | - * @return string the language message value |
|
119 | - */ |
|
120 | - public function get($key, $default = 'LANGUAGE_ERROR') { |
|
121 | - if (isset($this->languages[$key])) { |
|
122 | - return $this->languages[$key]; |
|
123 | - } |
|
124 | - $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
125 | - return $default; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Check whether the language file for given name exists |
|
130 | - * |
|
131 | - * @param string $language the language name like "fr", "en", etc. |
|
132 | - * |
|
133 | - * @return boolean true if the language directory exists, false or not |
|
134 | - */ |
|
135 | - public function isValid($language) { |
|
136 | - $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
137 | - foreach ($searchDir as $dir) { |
|
138 | - if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
139 | - return true; |
|
140 | - } |
|
141 | - } |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Get the default language value like "en" , "fr", etc. |
|
147 | - * |
|
148 | - * @return string the default language |
|
149 | - */ |
|
150 | - public function getDefault() { |
|
151 | - return $this->default; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Get the current language defined by cookie or the default value |
|
156 | - * |
|
157 | - * @return string the current language |
|
158 | - */ |
|
159 | - public function getCurrent() { |
|
160 | - return $this->current; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Add new supported or available language |
|
165 | - * |
|
166 | - * @param string $name the short language name like "en", "fr". |
|
167 | - * @param string $description the human readable description of this language |
|
168 | - */ |
|
169 | - public function addLang($name, $description){ |
|
170 | - if(isset($this->availables[$name])){ |
|
171 | - return; //already added cost in performance |
|
172 | - } |
|
173 | - if($this->isValid($name)){ |
|
174 | - $this->availables[$name] = $description; |
|
175 | - } else{ |
|
176 | - show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Get the list of the application supported language |
|
182 | - * |
|
183 | - * @return array the list of the application language |
|
184 | - */ |
|
185 | - public function getSupported() { |
|
186 | - return $this->availables; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Add new language messages |
|
191 | - * |
|
192 | - * @param array $langs the languages array of the messages to be added |
|
193 | - */ |
|
194 | - public function addLangMessages(array $langs) { |
|
195 | - foreach ($langs as $key => $value) { |
|
196 | - $this->set($key, $value); |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
70 | + //add the supported languages ('key', 'display name') |
|
71 | + $languages = get_config('languages', null); |
|
72 | + if (!empty($languages)) { |
|
73 | + foreach ($languages as $key => $displayName) { |
|
74 | + $this->addLang($key, $displayName); |
|
75 | + } |
|
76 | + } |
|
77 | + unset($languages); |
|
78 | + |
|
79 | + //if the language exists in cookie use it |
|
80 | + $cfgKey = get_config('language_cookie_name'); |
|
81 | + $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
82 | + $objCookie = & class_loader('Cookie'); |
|
83 | + $cookieLang = $objCookie->get($cfgKey); |
|
84 | + if($cookieLang && $this->isValid($cookieLang)){ |
|
85 | + $this->current = $cookieLang; |
|
86 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
87 | + } else{ |
|
88 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
89 | + $this->current = $this->getDefault(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Get the all languages messages |
|
95 | + * |
|
96 | + * @return array the language message list |
|
97 | + */ |
|
98 | + public function getAll() { |
|
99 | + return $this->languages; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Set the language message |
|
104 | + * |
|
105 | + * @param string $key the language key to identify |
|
106 | + * @param string $value the language message value |
|
107 | + */ |
|
108 | + public function set($key, $value) { |
|
109 | + $this->languages[$key] = $value; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Get the language message for the given key. If can't find return the default value |
|
114 | + * |
|
115 | + * @param string $key the message language key |
|
116 | + * @param string $default the default value to return if can not found the language message key |
|
117 | + * |
|
118 | + * @return string the language message value |
|
119 | + */ |
|
120 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
121 | + if (isset($this->languages[$key])) { |
|
122 | + return $this->languages[$key]; |
|
123 | + } |
|
124 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
125 | + return $default; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Check whether the language file for given name exists |
|
130 | + * |
|
131 | + * @param string $language the language name like "fr", "en", etc. |
|
132 | + * |
|
133 | + * @return boolean true if the language directory exists, false or not |
|
134 | + */ |
|
135 | + public function isValid($language) { |
|
136 | + $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
137 | + foreach ($searchDir as $dir) { |
|
138 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
139 | + return true; |
|
140 | + } |
|
141 | + } |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Get the default language value like "en" , "fr", etc. |
|
147 | + * |
|
148 | + * @return string the default language |
|
149 | + */ |
|
150 | + public function getDefault() { |
|
151 | + return $this->default; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Get the current language defined by cookie or the default value |
|
156 | + * |
|
157 | + * @return string the current language |
|
158 | + */ |
|
159 | + public function getCurrent() { |
|
160 | + return $this->current; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Add new supported or available language |
|
165 | + * |
|
166 | + * @param string $name the short language name like "en", "fr". |
|
167 | + * @param string $description the human readable description of this language |
|
168 | + */ |
|
169 | + public function addLang($name, $description){ |
|
170 | + if(isset($this->availables[$name])){ |
|
171 | + return; //already added cost in performance |
|
172 | + } |
|
173 | + if($this->isValid($name)){ |
|
174 | + $this->availables[$name] = $description; |
|
175 | + } else{ |
|
176 | + show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Get the list of the application supported language |
|
182 | + * |
|
183 | + * @return array the list of the application language |
|
184 | + */ |
|
185 | + public function getSupported() { |
|
186 | + return $this->availables; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Add new language messages |
|
191 | + * |
|
192 | + * @param array $langs the languages array of the messages to be added |
|
193 | + */ |
|
194 | + public function addLangMessages(array $langs) { |
|
195 | + foreach ($langs as $key => $value) { |
|
196 | + $this->set($key, $value); |
|
197 | + } |
|
198 | + } |
|
199 | + } |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | |
79 | 79 | //if the language exists in cookie use it |
80 | 80 | $cfgKey = get_config('language_cookie_name'); |
81 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
81 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
82 | 82 | $objCookie = & class_loader('Cookie'); |
83 | 83 | $cookieLang = $objCookie->get($cfgKey); |
84 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
84 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
85 | 85 | $this->current = $cookieLang; |
86 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
87 | - } else{ |
|
88 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
86 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
87 | + } else { |
|
88 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
89 | 89 | $this->current = $this->getDefault(); |
90 | 90 | } |
91 | 91 | } |
@@ -166,13 +166,13 @@ discard block |
||
166 | 166 | * @param string $name the short language name like "en", "fr". |
167 | 167 | * @param string $description the human readable description of this language |
168 | 168 | */ |
169 | - public function addLang($name, $description){ |
|
170 | - if(isset($this->availables[$name])){ |
|
169 | + public function addLang($name, $description) { |
|
170 | + if (isset($this->availables[$name])) { |
|
171 | 171 | return; //already added cost in performance |
172 | 172 | } |
173 | - if($this->isValid($name)){ |
|
173 | + if ($this->isValid($name)) { |
|
174 | 174 | $this->availables[$name] = $description; |
175 | - } else{ |
|
175 | + } else { |
|
176 | 176 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
177 | 177 | } |
178 | 178 | } |
@@ -1,158 +1,158 @@ |
||
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 extends BaseStaticClass { |
|
27 | + class Config extends BaseStaticClass { |
|
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 | - * Initialize the configuration by loading all the configuration from config file |
|
37 | - */ |
|
38 | - public static function init() { |
|
39 | - $logger = self::getLogger(); |
|
40 | - $logger->debug('Initialization of the configuration'); |
|
41 | - self::$config = & load_configurations(); |
|
42 | - self::setBaseUrlUsingServerVar(); |
|
43 | - if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) { |
|
44 | - $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
45 | - } |
|
46 | - $logger->info('Configuration initialized successfully'); |
|
47 | - $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
48 | - } |
|
35 | + /** |
|
36 | + * Initialize the configuration by loading all the configuration from config file |
|
37 | + */ |
|
38 | + public static function init() { |
|
39 | + $logger = self::getLogger(); |
|
40 | + $logger->debug('Initialization of the configuration'); |
|
41 | + self::$config = & load_configurations(); |
|
42 | + self::setBaseUrlUsingServerVar(); |
|
43 | + if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) { |
|
44 | + $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
|
45 | + } |
|
46 | + $logger->info('Configuration initialized successfully'); |
|
47 | + $logger->info('The application configuration are listed below: ' . stringfy_vars(self::$config)); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Get the configuration item value |
|
52 | - * @param string $item the configuration item name to get |
|
53 | - * @param mixed $default the default value to use if can not find the config item in the list |
|
54 | - * @return mixed the config value if exist or the default value |
|
55 | - */ |
|
56 | - public static function get($item, $default = null) { |
|
57 | - $logger = self::getLogger(); |
|
58 | - if (array_key_exists($item, self::$config)) { |
|
59 | - return self::$config[$item]; |
|
60 | - } |
|
61 | - $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
62 | - return $default; |
|
63 | - } |
|
50 | + /** |
|
51 | + * Get the configuration item value |
|
52 | + * @param string $item the configuration item name to get |
|
53 | + * @param mixed $default the default value to use if can not find the config item in the list |
|
54 | + * @return mixed the config value if exist or the default value |
|
55 | + */ |
|
56 | + public static function get($item, $default = null) { |
|
57 | + $logger = self::getLogger(); |
|
58 | + if (array_key_exists($item, self::$config)) { |
|
59 | + return self::$config[$item]; |
|
60 | + } |
|
61 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
62 | + return $default; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Set the configuration item value |
|
67 | - * @param string $item the config item name to set |
|
68 | - * @param mixed $value the config item value |
|
69 | - */ |
|
70 | - public static function set($item, $value) { |
|
71 | - self::$config[$item] = $value; |
|
72 | - } |
|
65 | + /** |
|
66 | + * Set the configuration item value |
|
67 | + * @param string $item the config item name to set |
|
68 | + * @param mixed $value the config item value |
|
69 | + */ |
|
70 | + public static function set($item, $value) { |
|
71 | + self::$config[$item] = $value; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Get all the configuration values |
|
76 | - * @return array the config values |
|
77 | - */ |
|
78 | - public static function getAll() { |
|
79 | - return self::$config; |
|
80 | - } |
|
74 | + /** |
|
75 | + * Get all the configuration values |
|
76 | + * @return array the config values |
|
77 | + */ |
|
78 | + public static function getAll() { |
|
79 | + return self::$config; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Set the configuration values bu merged with the existing configuration |
|
84 | - * @param array $config the config values to add in the configuration list |
|
85 | - */ |
|
86 | - public static function setAll(array $config = array()) { |
|
87 | - self::$config = array_merge(self::$config, $config); |
|
88 | - } |
|
82 | + /** |
|
83 | + * Set the configuration values bu merged with the existing configuration |
|
84 | + * @param array $config the config values to add in the configuration list |
|
85 | + */ |
|
86 | + public static function setAll(array $config = array()) { |
|
87 | + self::$config = array_merge(self::$config, $config); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Delete the configuration item in the list |
|
92 | - * @param string $item the config item name to be deleted |
|
93 | - * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
94 | - */ |
|
95 | - public static function delete($item){ |
|
96 | - $logger = self::getLogger(); |
|
97 | - if(array_key_exists($item, self::$config)){ |
|
98 | - $logger->info('Delete config item ['.$item.']'); |
|
99 | - unset(self::$config[$item]); |
|
100 | - return true; |
|
101 | - } else{ |
|
102 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
103 | - return false; |
|
104 | - } |
|
105 | - } |
|
90 | + /** |
|
91 | + * Delete the configuration item in the list |
|
92 | + * @param string $item the config item name to be deleted |
|
93 | + * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
94 | + */ |
|
95 | + public static function delete($item){ |
|
96 | + $logger = self::getLogger(); |
|
97 | + if(array_key_exists($item, self::$config)){ |
|
98 | + $logger->info('Delete config item ['.$item.']'); |
|
99 | + unset(self::$config[$item]); |
|
100 | + return true; |
|
101 | + } else{ |
|
102 | + $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
103 | + return false; |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Load the configuration file. This an alias to Loader::config() |
|
109 | - * @param string $config the config name to be loaded |
|
110 | - */ |
|
111 | - public static function load($config) { |
|
112 | - Loader::config($config); |
|
113 | - } |
|
107 | + /** |
|
108 | + * Load the configuration file. This an alias to Loader::config() |
|
109 | + * @param string $config the config name to be loaded |
|
110 | + */ |
|
111 | + public static function load($config) { |
|
112 | + Loader::config($config); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Set the configuration for "base_url" if is not set in the configuration |
|
117 | - */ |
|
118 | - private static function setBaseUrlUsingServerVar() { |
|
119 | - $logger = self::getLogger(); |
|
120 | - if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) { |
|
121 | - if (ENVIRONMENT == 'production') { |
|
122 | - $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
123 | - } |
|
124 | - $baseUrl = null; |
|
125 | - $protocol = 'http'; |
|
126 | - if (is_https()) { |
|
127 | - $protocol = 'https'; |
|
128 | - } |
|
129 | - $protocol .= '://'; |
|
115 | + /** |
|
116 | + * Set the configuration for "base_url" if is not set in the configuration |
|
117 | + */ |
|
118 | + private static function setBaseUrlUsingServerVar() { |
|
119 | + $logger = self::getLogger(); |
|
120 | + if (!isset(self::$config['base_url']) || !is_url(self::$config['base_url'])) { |
|
121 | + if (ENVIRONMENT == 'production') { |
|
122 | + $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
|
123 | + } |
|
124 | + $baseUrl = null; |
|
125 | + $protocol = 'http'; |
|
126 | + if (is_https()) { |
|
127 | + $protocol = 'https'; |
|
128 | + } |
|
129 | + $protocol .= '://'; |
|
130 | 130 | |
131 | - if (isset($_SERVER['SERVER_ADDR'])) { |
|
132 | - $baseUrl = $_SERVER['SERVER_ADDR']; |
|
133 | - //check if the server is running under IPv6 |
|
134 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
135 | - $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
136 | - } |
|
137 | - $serverPort = 80; |
|
138 | - if (isset($_SERVER['SERVER_PORT'])) { |
|
139 | - $serverPort = $_SERVER['SERVER_PORT']; |
|
140 | - } |
|
141 | - $port = ''; |
|
142 | - if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) { |
|
143 | - $port = ':' . $serverPort; |
|
144 | - } |
|
145 | - $baseUrl = $protocol . $baseUrl . $port . substr( |
|
146 | - $_SERVER['SCRIPT_NAME'], |
|
147 | - 0, |
|
148 | - strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
|
149 | - ); |
|
150 | - } else{ |
|
151 | - $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
152 | - $baseUrl = 'http://localhost/'; |
|
153 | - } |
|
154 | - self::set('base_url', $baseUrl); |
|
155 | - } |
|
156 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
157 | - } |
|
158 | - } |
|
131 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
132 | + $baseUrl = $_SERVER['SERVER_ADDR']; |
|
133 | + //check if the server is running under IPv6 |
|
134 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
135 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
136 | + } |
|
137 | + $serverPort = 80; |
|
138 | + if (isset($_SERVER['SERVER_PORT'])) { |
|
139 | + $serverPort = $_SERVER['SERVER_PORT']; |
|
140 | + } |
|
141 | + $port = ''; |
|
142 | + if ($serverPort && ((is_https() && $serverPort != 443) || (!is_https() && $serverPort != 80))) { |
|
143 | + $port = ':' . $serverPort; |
|
144 | + } |
|
145 | + $baseUrl = $protocol . $baseUrl . $port . substr( |
|
146 | + $_SERVER['SCRIPT_NAME'], |
|
147 | + 0, |
|
148 | + strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
|
149 | + ); |
|
150 | + } else{ |
|
151 | + $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
|
152 | + $baseUrl = 'http://localhost/'; |
|
153 | + } |
|
154 | + self::set('base_url', $baseUrl); |
|
155 | + } |
|
156 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
157 | + } |
|
158 | + } |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | * @param string $item the config item name to be deleted |
93 | 93 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
94 | 94 | */ |
95 | - public static function delete($item){ |
|
95 | + public static function delete($item) { |
|
96 | 96 | $logger = self::getLogger(); |
97 | - if(array_key_exists($item, self::$config)){ |
|
98 | - $logger->info('Delete config item ['.$item.']'); |
|
97 | + if (array_key_exists($item, self::$config)) { |
|
98 | + $logger->info('Delete config item [' . $item . ']'); |
|
99 | 99 | unset(self::$config[$item]); |
100 | 100 | return true; |
101 | - } else{ |
|
102 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
101 | + } else { |
|
102 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | } |
@@ -147,12 +147,12 @@ discard block |
||
147 | 147 | 0, |
148 | 148 | strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])) |
149 | 149 | ); |
150 | - } else{ |
|
150 | + } else { |
|
151 | 151 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
152 | 152 | $baseUrl = 'http://localhost/'; |
153 | 153 | } |
154 | 154 | self::set('base_url', $baseUrl); |
155 | 155 | } |
156 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
156 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
|
157 | 157 | } |
158 | 158 | } |
@@ -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 BaseStaticClass{ |
|
27 | + class BaseStaticClass { |
|
28 | 28 | /** |
29 | 29 | * The logger instance |
30 | 30 | * @var object |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | * The signleton of the logger |
36 | 36 | * @return Object the Log instance |
37 | 37 | */ |
38 | - public static function getLogger(){ |
|
39 | - if(self::$logger == null){ |
|
38 | + public static function getLogger() { |
|
39 | + if (self::$logger == null) { |
|
40 | 40 | $logger = array(); |
41 | - $logger[0] =& class_loader('Log', 'classes'); |
|
41 | + $logger[0] = & class_loader('Log', 'classes'); |
|
42 | 42 | $logger[0]->setLogger('Class::' . get_called_class()); |
43 | 43 | self::$logger = $logger[0]; |
44 | 44 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param object $logger the log object |
51 | 51 | * @return object the log instance |
52 | 52 | */ |
53 | - public static function setLogger($logger){ |
|
53 | + public static function setLogger($logger) { |
|
54 | 54 | self::$logger = $logger; |
55 | 55 | return self::$logger; |
56 | 56 | } |
@@ -1,52 +1,52 @@ |
||
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 | - if (!function_exists('__')) { |
|
28 | - /** |
|
29 | - * function for the shortcut to Lang::get() |
|
30 | - * @param string $key the language key to retrieve |
|
31 | - * @param mixed $default the default value to return if can not find the value |
|
32 | - * for the given key |
|
33 | - * @return string the language value |
|
34 | - */ |
|
35 | - function __($key, $default = 'LANGUAGE_ERROR') { |
|
36 | - return get_instance()->lang->get($key, $default); |
|
37 | - } |
|
27 | + if (!function_exists('__')) { |
|
28 | + /** |
|
29 | + * function for the shortcut to Lang::get() |
|
30 | + * @param string $key the language key to retrieve |
|
31 | + * @param mixed $default the default value to return if can not find the value |
|
32 | + * for the given key |
|
33 | + * @return string the language value |
|
34 | + */ |
|
35 | + function __($key, $default = 'LANGUAGE_ERROR') { |
|
36 | + return get_instance()->lang->get($key, $default); |
|
37 | + } |
|
38 | 38 | |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - if (!function_exists('get_languages')) { |
|
43 | - /** |
|
44 | - * function for the shortcut to Lang::getSupported() |
|
45 | - * |
|
46 | - * @return array all the supported languages |
|
47 | - */ |
|
48 | - function get_languages() { |
|
49 | - return get_instance()->lang->getSupported(); |
|
50 | - } |
|
42 | + if (!function_exists('get_languages')) { |
|
43 | + /** |
|
44 | + * function for the shortcut to Lang::getSupported() |
|
45 | + * |
|
46 | + * @return array all the supported languages |
|
47 | + */ |
|
48 | + function get_languages() { |
|
49 | + return get_instance()->lang->getSupported(); |
|
50 | + } |
|
51 | 51 | |
52 | - } |
|
53 | 52 | \ No newline at end of file |
53 | + } |
|
54 | 54 | \ No newline at end of file |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | |
43 | 43 | |
44 | - if(! function_exists('get_ip')){ |
|
44 | + if (!function_exists('get_ip')) { |
|
45 | 45 | /** |
46 | 46 | * Retrieves the user's IP address |
47 | 47 | * |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return string the IP address. |
52 | 52 | */ |
53 | - function get_ip(){ |
|
53 | + function get_ip() { |
|
54 | 54 | $ip = '127.0.0.1'; |
55 | 55 | $ipServerVars = array( |
56 | 56 | 'REMOTE_ADDR', |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'HTTP_FORWARDED' |
62 | 62 | ); |
63 | 63 | foreach ($ipServerVars as $var) { |
64 | - if(isset($_SERVER[$var])){ |
|
64 | + if (isset($_SERVER[$var])) { |
|
65 | 65 | $ip = $_SERVER[$var]; |
66 | 66 | break; |
67 | 67 | } |