@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Session{ |
|
26 | + class Session { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * The session flash key to use |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * Get the logger singleton instance |
42 | 42 | * @return Log the logger instance |
43 | 43 | */ |
44 | - private static function getLogger(){ |
|
45 | - if(static::$logger == null){ |
|
46 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
44 | + private static function getLogger() { |
|
45 | + if (static::$logger == null) { |
|
46 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
47 | 47 | static::$logger[0]->setLogger('Library::Session'); |
48 | 48 | } |
49 | 49 | return static::$logger[0]; |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | * @param mixed $default the default value to use if can not find the session item in the list |
56 | 56 | * @return mixed the session value if exist or the default value |
57 | 57 | */ |
58 | - public static function get($item, $default = null){ |
|
58 | + public static function get($item, $default = null) { |
|
59 | 59 | $logger = static::getLogger(); |
60 | - $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
61 | - if(array_key_exists($item, $_SESSION)){ |
|
60 | + $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
61 | + if (array_key_exists($item, $_SESSION)) { |
|
62 | 62 | $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
63 | 63 | return $_SESSION[$item]; |
64 | 64 | } |
65 | - $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
65 | + $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
66 | 66 | return $default; |
67 | 67 | } |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param string $item the session item name to set |
72 | 72 | * @param mixed $value the session item value |
73 | 73 | */ |
74 | - public static function set($item, $value){ |
|
74 | + public static function set($item, $value) { |
|
75 | 75 | $logger = static::getLogger(); |
76 | 76 | $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
77 | 77 | $_SESSION[$item] = $value; |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * @param mixed $default the default value to use if can not find the session flash item in the list |
84 | 84 | * @return mixed the session flash value if exist or the default value |
85 | 85 | */ |
86 | - public static function getFlash($item, $default = null){ |
|
86 | + public static function getFlash($item, $default = null) { |
|
87 | 87 | $logger = static::getLogger(); |
88 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
88 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
89 | 89 | $return = array_key_exists($key, $_SESSION) ? |
90 | 90 | ($_SESSION[$key]) : $default; |
91 | - if(array_key_exists($key, $_SESSION)){ |
|
91 | + if (array_key_exists($key, $_SESSION)) { |
|
92 | 92 | unset($_SESSION[$key]); |
93 | 93 | } |
94 | - else{ |
|
95 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
94 | + else { |
|
95 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
96 | 96 | } |
97 | 97 | return $return; |
98 | 98 | } |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | * @param string $item the session flash item name |
103 | 103 | * @return boolean |
104 | 104 | */ |
105 | - public static function hasFlash($item){ |
|
106 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
105 | + public static function hasFlash($item) { |
|
106 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
107 | 107 | return array_key_exists($key, $_SESSION); |
108 | 108 | } |
109 | 109 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param string $item the session flash item name to set |
113 | 113 | * @param mixed $value the session flash item value |
114 | 114 | */ |
115 | - public static function setFlash($item, $value){ |
|
116 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
115 | + public static function setFlash($item, $value) { |
|
116 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
117 | 117 | $_SESSION[$key] = $value; |
118 | 118 | } |
119 | 119 | |
@@ -121,14 +121,14 @@ discard block |
||
121 | 121 | * Clear the session item in the list |
122 | 122 | * @param string $item the session item name to be deleted |
123 | 123 | */ |
124 | - public static function clear($item){ |
|
124 | + public static function clear($item) { |
|
125 | 125 | $logger = static::getLogger(); |
126 | - if(array_key_exists($item, $_SESSION)){ |
|
127 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
126 | + if (array_key_exists($item, $_SESSION)) { |
|
127 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
128 | 128 | unset($_SESSION[$item]); |
129 | 129 | } |
130 | - else{ |
|
131 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
130 | + else { |
|
131 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | * Clear the session flash item in the list |
137 | 137 | * @param string $item the session flash item name to be deleted |
138 | 138 | */ |
139 | - public static function clearFlash($item){ |
|
139 | + public static function clearFlash($item) { |
|
140 | 140 | $logger = static::getLogger(); |
141 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
142 | - if(array_key_exists($key, $_SESSION)){ |
|
143 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
141 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
142 | + if (array_key_exists($key, $_SESSION)) { |
|
143 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
144 | 144 | unset($_SESSION[$item]); |
145 | 145 | } |
146 | - else{ |
|
147 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
146 | + else { |
|
147 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | * @param string $item the session item name |
154 | 154 | * @return boolean |
155 | 155 | */ |
156 | - public static function exists($item){ |
|
156 | + public static function exists($item) { |
|
157 | 157 | return array_key_exists($item, $_SESSION); |
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | 161 | * Destroy all session data values |
162 | 162 | */ |
163 | - public static function clearAll(){ |
|
163 | + public static function clearAll() { |
|
164 | 164 | session_unset(); |
165 | 165 | session_destroy(); |
166 | 166 | } |
@@ -92,39 +92,39 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * Construct the new Router instance |
94 | 94 | */ |
95 | - public function __construct(){ |
|
96 | - $this->logger =& class_loader('Log', 'classes'); |
|
95 | + public function __construct() { |
|
96 | + $this->logger = & class_loader('Log', 'classes'); |
|
97 | 97 | $this->logger->setLogger('Library::Router'); |
98 | 98 | $routesPath = CONFIG_PATH . 'routes.php'; |
99 | 99 | $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...'); |
100 | - if(file_exists($routesPath)){ |
|
101 | - $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it'); |
|
100 | + if (file_exists($routesPath)) { |
|
101 | + $this->logger->info('Found routes configuration file --> ' . $routesPath . ' now load it'); |
|
102 | 102 | require_once $routesPath; |
103 | - if(! empty($route) && is_array($route)){ |
|
103 | + if (!empty($route) && is_array($route)) { |
|
104 | 104 | $this->routes = $route; |
105 | 105 | unset($route); |
106 | 106 | } |
107 | - else{ |
|
107 | + else { |
|
108 | 108 | show_error('No routing configuration found in [' . $routesPath . ']'); |
109 | 109 | } |
110 | 110 | } |
111 | - else{ |
|
111 | + else { |
|
112 | 112 | show_error('Unable to find the routes configuration file [' . $routesPath . ']'); |
113 | 113 | } |
114 | 114 | |
115 | 115 | //loading routes for module |
116 | 116 | $this->logger->debug('Loading of modules routes ... '); |
117 | 117 | $modulesRoutes = Module::getModulesRoutes(); |
118 | - if($modulesRoutes && is_array($modulesRoutes)){ |
|
118 | + if ($modulesRoutes && is_array($modulesRoutes)) { |
|
119 | 119 | $this->routes = array_merge($this->routes, $modulesRoutes); |
120 | 120 | $this->logger->info('Routes for all modules loaded successfully'); |
121 | 121 | } |
122 | - else{ |
|
122 | + else { |
|
123 | 123 | $this->logger->info('No routes found for all modules skipping.'); |
124 | 124 | } |
125 | 125 | $this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes)); |
126 | 126 | |
127 | - foreach($this->routes as $pattern => $callback){ |
|
127 | + foreach ($this->routes as $pattern => $callback) { |
|
128 | 128 | $this->add($pattern, $callback); |
129 | 129 | } |
130 | 130 | |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; |
133 | 133 | $this->logger->debug('Check if URL suffix is enabled in the configuration'); |
134 | 134 | //remove url suffix from the request URI |
135 | - if($suffix = get_config('url_suffix')){ |
|
136 | - $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' ); |
|
135 | + if ($suffix = get_config('url_suffix')) { |
|
136 | + $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']'); |
|
137 | 137 | $uri = str_ireplace($suffix, '', $uri); |
138 | 138 | } |
139 | - else{ |
|
139 | + else { |
|
140 | 140 | $this->logger->info('URL suffix is not enabled in the configuration'); |
141 | 141 | } |
142 | - if(strpos($uri, '?') !== false){ |
|
142 | + if (strpos($uri, '?') !== false) { |
|
143 | 143 | $uri = substr($uri, 0, strpos($uri, '?')); |
144 | 144 | } |
145 | 145 | $uri = trim($uri, $this->uriTrim); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function add($uri, $callback) { |
156 | 156 | $uri = trim($uri, $this->uriTrim); |
157 | - if(in_array($uri, $this->pattern)){ |
|
157 | + if (in_array($uri, $this->pattern)) { |
|
158 | 158 | $this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict'); |
159 | 159 | } |
160 | 160 | $this->pattern[] = $uri; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * Get the module name |
166 | 166 | * @return string |
167 | 167 | */ |
168 | - public function getModule(){ |
|
168 | + public function getModule() { |
|
169 | 169 | return $this->module; |
170 | 170 | } |
171 | 171 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * Get the controller name |
174 | 174 | * @return string |
175 | 175 | */ |
176 | - public function getController(){ |
|
176 | + public function getController() { |
|
177 | 177 | return $this->controller; |
178 | 178 | } |
179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Get the controller file path |
182 | 182 | * @return string |
183 | 183 | */ |
184 | - public function getControllerPath(){ |
|
184 | + public function getControllerPath() { |
|
185 | 185 | return $this->controllerPath; |
186 | 186 | } |
187 | 187 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * Get the controller method |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - public function getMethod(){ |
|
192 | + public function getMethod() { |
|
193 | 193 | return $this->method; |
194 | 194 | } |
195 | 195 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * Get the request arguments |
198 | 198 | * @return array |
199 | 199 | */ |
200 | - public function getArgs(){ |
|
200 | + public function getArgs() { |
|
201 | 201 | return $this->args; |
202 | 202 | } |
203 | 203 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * Get the URL segments array |
206 | 206 | * @return array |
207 | 207 | */ |
208 | - public function getSegments(){ |
|
208 | + public function getSegments() { |
|
209 | 209 | return $this->segments; |
210 | 210 | } |
211 | 211 | |
@@ -214,27 +214,27 @@ discard block |
||
214 | 214 | * otherwise send 404 error. |
215 | 215 | */ |
216 | 216 | public function run() { |
217 | - $benchmark =& class_loader('Benchmark'); |
|
217 | + $benchmark = & class_loader('Benchmark'); |
|
218 | 218 | $benchmark->mark('ROUTING_PROCESS_START'); |
219 | 219 | $this->logger->debug('Routing process start ...'); |
220 | 220 | $segment = $this->segments; |
221 | 221 | $baseUrl = get_config('base_url'); |
222 | 222 | //check if the app is not in DOCUMENT_ROOT |
223 | - if(isset($segment[0]) && stripos($baseUrl, $segment[0]) != false){ |
|
223 | + if (isset($segment[0]) && stripos($baseUrl, $segment[0]) != false) { |
|
224 | 224 | array_shift($segment); |
225 | 225 | $this->segments = $segment; |
226 | 226 | } |
227 | 227 | $this->logger->debug('Check if the request URI contains the front controller'); |
228 | - if(isset($segment[0]) && $segment[0] == SELF){ |
|
228 | + if (isset($segment[0]) && $segment[0] == SELF) { |
|
229 | 229 | $this->logger->info('The request URI contains the front controller'); |
230 | 230 | array_shift($segment); |
231 | 231 | $this->segments = $segment; |
232 | 232 | } |
233 | - else{ |
|
233 | + else { |
|
234 | 234 | $this->logger->info('The request URI does not contain the front controller'); |
235 | 235 | } |
236 | 236 | $uri = implode('/', $segment); |
237 | - $this->logger->info('The final Request URI is [' . $uri . ']' ); |
|
237 | + $this->logger->info('The final Request URI is [' . $uri . ']'); |
|
238 | 238 | //generic routes |
239 | 239 | $pattern = array(':num', ':alpha', ':alnum', ':any'); |
240 | 240 | $replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*'); |
@@ -248,20 +248,20 @@ discard block |
||
248 | 248 | array_shift($args); |
249 | 249 | //check if this contains an module |
250 | 250 | $moduleControllerMethod = explode('#', $this->callback[$index]); |
251 | - if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){ |
|
252 | - $this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']'); |
|
251 | + if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) { |
|
252 | + $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']'); |
|
253 | 253 | $this->module = $moduleControllerMethod[0]; |
254 | 254 | $moduleControllerMethod = explode('@', $moduleControllerMethod[1]); |
255 | 255 | } |
256 | - else{ |
|
256 | + else { |
|
257 | 257 | $this->logger->info('The current request does not use the module'); |
258 | 258 | $moduleControllerMethod = explode('@', $this->callback[$index]); |
259 | 259 | } |
260 | - if(is_array($moduleControllerMethod)){ |
|
261 | - if(isset($moduleControllerMethod[0])){ |
|
260 | + if (is_array($moduleControllerMethod)) { |
|
261 | + if (isset($moduleControllerMethod[0])) { |
|
262 | 262 | $this->controller = $moduleControllerMethod[0]; |
263 | 263 | } |
264 | - if(isset($moduleControllerMethod[1])){ |
|
264 | + if (isset($moduleControllerMethod[1])) { |
|
265 | 265 | $this->method = $moduleControllerMethod[1]; |
266 | 266 | } |
267 | 267 | $this->args = $args; |
@@ -271,73 +271,73 @@ discard block |
||
271 | 271 | } |
272 | 272 | } |
273 | 273 | //first if the controller is not set and the module is set use the module name as the controller |
274 | - if(! $this->getController() && $this->getModule()){ |
|
274 | + if (!$this->getController() && $this->getModule()) { |
|
275 | 275 | $this->logger->info('After loop in predefined routes configuration, the module name is set but the controller is not set, so we will use module as the controller'); |
276 | 276 | $this->controller = $this->getModule(); |
277 | 277 | } |
278 | 278 | //if can not determine the module/controller/method via the defined routes configuration we will use |
279 | 279 | //the URL like http://domain.com/module/controller/method/arg1/arg2 |
280 | - if(! $this->getController()){ |
|
280 | + if (!$this->getController()) { |
|
281 | 281 | $this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters'); |
282 | 282 | $nbSegment = count($segment); |
283 | 283 | //if segment is null so means no need to perform |
284 | - if($nbSegment > 0){ |
|
284 | + if ($nbSegment > 0) { |
|
285 | 285 | //get the module list |
286 | 286 | $modules = Module::getModuleList(); |
287 | 287 | //first check if no module |
288 | - if(! $modules){ |
|
288 | + if (!$modules) { |
|
289 | 289 | $this->logger->info('No module was loaded will skip the module checking'); |
290 | 290 | //the application don't use module |
291 | 291 | //controller |
292 | - if(isset($segment[0])){ |
|
292 | + if (isset($segment[0])) { |
|
293 | 293 | $this->controller = $segment[0]; |
294 | 294 | array_shift($segment); |
295 | 295 | } |
296 | 296 | //method |
297 | - if(isset($segment[0])){ |
|
297 | + if (isset($segment[0])) { |
|
298 | 298 | $this->method = $segment[0]; |
299 | 299 | array_shift($segment); |
300 | 300 | } |
301 | 301 | //args |
302 | 302 | $this->args = $segment; |
303 | 303 | } |
304 | - else{ |
|
304 | + else { |
|
305 | 305 | $this->logger->info('The application contains a loaded module will check if the current request is found in the module list'); |
306 | - if(in_array($segment[0], $modules)){ |
|
306 | + if (in_array($segment[0], $modules)) { |
|
307 | 307 | $this->logger->info('Found, the current request use the module [' . $segment[0] . ']'); |
308 | 308 | $this->module = $segment[0]; |
309 | 309 | array_shift($segment); |
310 | 310 | //check if the second arg is the controller from module |
311 | - if(isset($segment[0])){ |
|
311 | + if (isset($segment[0])) { |
|
312 | 312 | $this->controller = $segment[0]; |
313 | 313 | //check if the request use the same module name and controller |
314 | 314 | $path = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
315 | - if(! $path){ |
|
315 | + if (!$path) { |
|
316 | 316 | $this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller'); |
317 | 317 | $this->controller = $this->getModule(); |
318 | 318 | } |
319 | - else{ |
|
319 | + else { |
|
320 | 320 | $this->controllerPath = $path; |
321 | 321 | array_shift($segment); |
322 | 322 | } |
323 | 323 | } |
324 | 324 | //check for method |
325 | - if(isset($segment[0])){ |
|
325 | + if (isset($segment[0])) { |
|
326 | 326 | $this->method = $segment[0]; |
327 | 327 | array_shift($segment); |
328 | 328 | } |
329 | 329 | //the remaining is for args |
330 | 330 | $this->args = $segment; |
331 | 331 | } |
332 | - else{ |
|
332 | + else { |
|
333 | 333 | $this->logger->info('The current request information is not found in the module list'); |
334 | 334 | //controller |
335 | - if(isset($segment[0])){ |
|
335 | + if (isset($segment[0])) { |
|
336 | 336 | $this->controller = $segment[0]; |
337 | 337 | array_shift($segment); |
338 | 338 | } |
339 | 339 | //method |
340 | - if(isset($segment[0])){ |
|
340 | + if (isset($segment[0])) { |
|
341 | 341 | $this->method = $segment[0]; |
342 | 342 | array_shift($segment); |
343 | 343 | } |
@@ -347,18 +347,18 @@ discard block |
||
347 | 347 | } |
348 | 348 | } |
349 | 349 | } |
350 | - if(! $this->getController() && $this->getModule()){ |
|
350 | + if (!$this->getController() && $this->getModule()) { |
|
351 | 351 | $this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller'); |
352 | 352 | $this->controller = $this->getModule(); |
353 | 353 | } |
354 | 354 | //did we set the controller, so set the controller path |
355 | - if($this->getController() && ! $this->getControllerPath()){ |
|
355 | + if ($this->getController() && !$this->getControllerPath()) { |
|
356 | 356 | $this->logger->debug('Setting the file path for the controller [' . $this->getController() . ']'); |
357 | 357 | //if it is the module controller |
358 | - if($this->getModule()){ |
|
358 | + if ($this->getModule()) { |
|
359 | 359 | $this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
360 | 360 | } |
361 | - else{ |
|
361 | + else { |
|
362 | 362 | $this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php'; |
363 | 363 | } |
364 | 364 | } |
@@ -368,20 +368,20 @@ discard block |
||
368 | 368 | $this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...'); |
369 | 369 | $benchmark->mark('ROUTING_PROCESS_END'); |
370 | 370 | $e404 = false; |
371 | - if(file_exists($classFilePath)){ |
|
371 | + if (file_exists($classFilePath)) { |
|
372 | 372 | require_once $classFilePath; |
373 | - if(! class_exists($controller, false)){ |
|
373 | + if (!class_exists($controller, false)) { |
|
374 | 374 | $e404 = true; |
375 | - $this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']'); |
|
375 | + $this->logger->info('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']'); |
|
376 | 376 | } |
377 | - else{ |
|
377 | + else { |
|
378 | 378 | $controllerInstance = new $controller(); |
379 | 379 | $controllerMethod = $this->getMethod(); |
380 | - if(! method_exists($controllerInstance, $controllerMethod)){ |
|
380 | + if (!method_exists($controllerInstance, $controllerMethod)) { |
|
381 | 381 | $e404 = true; |
382 | 382 | $this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']'); |
383 | 383 | } |
384 | - else{ |
|
384 | + else { |
|
385 | 385 | $this->logger->info('Routing data is set correctly now GO!'); |
386 | 386 | call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs()); |
387 | 387 | $obj = & get_instance(); |
@@ -391,12 +391,12 @@ discard block |
||
391 | 391 | } |
392 | 392 | } |
393 | 393 | } |
394 | - else{ |
|
394 | + else { |
|
395 | 395 | $this->logger->info('The controller file path [' . $classFilePath . '] does not exist'); |
396 | 396 | $e404 = true; |
397 | 397 | } |
398 | - if($e404){ |
|
399 | - $response =& class_loader('Response', 'classes'); |
|
398 | + if ($e404) { |
|
399 | + $response = & class_loader('Response', 'classes'); |
|
400 | 400 | $response->send404(); |
401 | 401 | } |
402 | 402 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * For application languages management |
29 | 29 | */ |
30 | - class Lang{ |
|
30 | + class Lang { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The supported available language for this application. |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * Construct new Lang instance |
69 | 69 | */ |
70 | - public function __construct(){ |
|
71 | - $this->logger =& class_loader('Log', 'classes'); |
|
70 | + public function __construct() { |
|
71 | + $this->logger = & class_loader('Log', 'classes'); |
|
72 | 72 | $this->logger->setLogger('Library::Lang'); |
73 | 73 | |
74 | 74 | $this->default = get_config('default_language', 'en'); |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | $language = null; |
77 | 77 | //if the language exists in cookie use it |
78 | 78 | $cfgKey = get_config('language_cookie_name'); |
79 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
79 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
80 | 80 | $objCookie = & class_loader('Cookie'); |
81 | 81 | $cookieLang = $objCookie->get($cfgKey); |
82 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
82 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
83 | 83 | $this->current = $cookieLang; |
84 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
84 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
85 | 85 | } |
86 | - else{ |
|
87 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
86 | + else { |
|
87 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
88 | 88 | $this->current = $this->getDefault(); |
89 | 89 | } |
90 | 90 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return array the language message list |
96 | 96 | */ |
97 | - public function getAll(){ |
|
97 | + public function getAll() { |
|
98 | 98 | return $this->languages; |
99 | 99 | } |
100 | 100 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param string $key the language key to identify |
105 | 105 | * @param string $value the language message value |
106 | 106 | */ |
107 | - public function set($key, $value){ |
|
107 | + public function set($key, $value) { |
|
108 | 108 | $this->languages[$key] = $value; |
109 | 109 | } |
110 | 110 | |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return string the language message value |
118 | 118 | */ |
119 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
120 | - if(isset($this->languages[$key])){ |
|
119 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
120 | + if (isset($this->languages[$key])) { |
|
121 | 121 | return $this->languages[$key]; |
122 | 122 | } |
123 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
123 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
124 | 124 | return $default; |
125 | 125 | } |
126 | 126 | |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return boolean true if the language directory exists, false or not |
133 | 133 | */ |
134 | - public function isValid($language){ |
|
134 | + public function isValid($language) { |
|
135 | 135 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
136 | - foreach($searchDir as $dir){ |
|
137 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
136 | + foreach ($searchDir as $dir) { |
|
137 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @return string the default language |
148 | 148 | */ |
149 | - public function getDefault(){ |
|
149 | + public function getDefault() { |
|
150 | 150 | return $this->default; |
151 | 151 | } |
152 | 152 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return string the current language |
157 | 157 | */ |
158 | - public function getCurrent(){ |
|
158 | + public function getCurrent() { |
|
159 | 159 | return $this->current; |
160 | 160 | } |
161 | 161 | |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | * @param string $name the short language name like "en", "fr". |
166 | 166 | * @param string $description the human readable description of this language |
167 | 167 | */ |
168 | - public function addLang($name, $description){ |
|
169 | - if(isset($this->availables[$name])){ |
|
168 | + public function addLang($name, $description) { |
|
169 | + if (isset($this->availables[$name])) { |
|
170 | 170 | return; //already added cost in performance |
171 | 171 | } |
172 | - if($this->isValid($name)){ |
|
172 | + if ($this->isValid($name)) { |
|
173 | 173 | $this->availables[$name] = $description; |
174 | 174 | } |
175 | - else{ |
|
175 | + else { |
|
176 | 176 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
177 | 177 | } |
178 | 178 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return array the list of the application language |
184 | 184 | */ |
185 | - public function getSupported(){ |
|
185 | + public function getSupported() { |
|
186 | 186 | return $this->availables; |
187 | 187 | } |
188 | 188 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @param array $langs the languages array of the messages to be added |
193 | 193 | */ |
194 | - public function addLangMessages(array $langs){ |
|
194 | + public function addLangMessages(array $langs) { |
|
195 | 195 | foreach ($langs as $key => $value) { |
196 | 196 | $this->set($key, $value); |
197 | 197 | } |
@@ -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 Security{ |
|
27 | + class Security { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The logger instance |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * Get the logger singleton instance |
37 | 37 | * @return Log the logger instance |
38 | 38 | */ |
39 | - private static function getLogger(){ |
|
40 | - if(static::$logger == null){ |
|
41 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
39 | + private static function getLogger() { |
|
40 | + if (static::$logger == null) { |
|
41 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
42 | 42 | static::$logger[0]->setLogger('Library::Security'); |
43 | 43 | } |
44 | 44 | return static::$logger[0]; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * This method is used to generate the CSRF token |
50 | 50 | * @return string the generated CSRF token |
51 | 51 | */ |
52 | - public static function generateCSRF(){ |
|
52 | + public static function generateCSRF() { |
|
53 | 53 | $logger = static::getLogger(); |
54 | 54 | $logger->debug('Generation of CSRF ...'); |
55 | 55 | |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | $expire = get_config('csrf_expire', 60); |
58 | 58 | $keyExpire = 'csrf_expire'; |
59 | 59 | $currentTime = time(); |
60 | - if(Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime){ |
|
60 | + if (Session::exists($key) && Session::exists($keyExpire) && Session::get($keyExpire) > $currentTime) { |
|
61 | 61 | $logger->info('The CSRF token not yet expire just return it'); |
62 | 62 | return Session::get($key); |
63 | 63 | } |
64 | - else{ |
|
64 | + else { |
|
65 | 65 | $newTime = $currentTime + $expire; |
66 | 66 | $token = sha1(uniqid()) . sha1(uniqid()); |
67 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. '], token [' .$token. ']'); |
|
67 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . '], token [' . $token . ']'); |
|
68 | 68 | Session::set($keyExpire, $newTime); |
69 | 69 | Session::set($key, $token); |
70 | 70 | return Session::get($key); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * This method is used to check the CSRF if is valid, not yet expire, etc. |
76 | 76 | * @return boolean true if valid, false if not valid |
77 | 77 | */ |
78 | - public static function validateCSRF(){ |
|
78 | + public static function validateCSRF() { |
|
79 | 79 | $logger = static::getLogger(); |
80 | 80 | $logger->debug('Validation of CSRF ...'); |
81 | 81 | |
@@ -83,23 +83,23 @@ discard block |
||
83 | 83 | $expire = get_config('csrf_expire', 60); |
84 | 84 | $keyExpire = 'csrf_expire'; |
85 | 85 | $currentTime = time(); |
86 | - $logger->info('The CSRF informations are listed below: key [' .$key. '], key expire [' .$keyExpire. '], expire time [' .$expire. ']'); |
|
87 | - if(! Session::exists($key) || Session::get($keyExpire) <= $currentTime){ |
|
86 | + $logger->info('The CSRF informations are listed below: key [' . $key . '], key expire [' . $keyExpire . '], expire time [' . $expire . ']'); |
|
87 | + if (!Session::exists($key) || Session::get($keyExpire) <= $currentTime) { |
|
88 | 88 | $logger->warning('The CSRF session data is not valide'); |
89 | 89 | return false; |
90 | 90 | } |
91 | - else{ |
|
91 | + else { |
|
92 | 92 | //perform form data |
93 | 93 | //need use request->query() for best retrieve |
94 | 94 | //super instance |
95 | 95 | $obj = & get_instance(); |
96 | 96 | $token = $obj->request->query($key); |
97 | - if(! $token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime){ |
|
98 | - $logger->warning('The CSRF data [' .$token. '] is not valide may be attacker do his job'); |
|
97 | + if (!$token || $token !== Session::get($key) || Session::get($keyExpire) <= $currentTime) { |
|
98 | + $logger->warning('The CSRF data [' . $token . '] is not valide may be attacker do his job'); |
|
99 | 99 | return false; |
100 | 100 | } |
101 | - else{ |
|
102 | - $logger->info('The CSRF data [' .$token. '] is valide the form data is safe continue'); |
|
101 | + else { |
|
102 | + $logger->info('The CSRF data [' . $token . '] is valide the form data is safe continue'); |
|
103 | 103 | //remove the token from session |
104 | 104 | Session::clear($key); |
105 | 105 | Session::clear($keyExpire); |
@@ -111,24 +111,24 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * This method is used to check the whitelist IP address access |
113 | 113 | */ |
114 | - public static function checkWhiteListIpAccess(){ |
|
114 | + public static function checkWhiteListIpAccess() { |
|
115 | 115 | $logger = static::getLogger(); |
116 | 116 | $logger->debug('Validation of the IP address access ...'); |
117 | 117 | $logger->debug('Check if whitelist IP access is enabled in the configuration ...'); |
118 | 118 | $isEnable = get_config('white_list_ip_enable', false); |
119 | - if($isEnable){ |
|
119 | + if ($isEnable) { |
|
120 | 120 | $logger->info('Whitelist IP access is enabled in the configuration'); |
121 | 121 | $list = get_config('white_list_ip_addresses', array()); |
122 | - if(! empty($list)){ |
|
122 | + if (!empty($list)) { |
|
123 | 123 | //Can't use Loader::functions() at this time because teh "Loader" library is loader after the security prossessing |
124 | 124 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
125 | 125 | $ip = get_ip(); |
126 | - if(count($list) == 1 && $list[0] == '*' || in_array($ip, $list)){ |
|
126 | + if (count($list) == 1 && $list[0] == '*' || in_array($ip, $list)) { |
|
127 | 127 | $logger->info('IP address ' . $ip . ' allowed using the wildcard "*" or the full IP'); |
128 | 128 | //wildcard to access all ip address |
129 | 129 | return; |
130 | 130 | } |
131 | - else{ |
|
131 | + else { |
|
132 | 132 | // go through all whitelisted ips |
133 | 133 | foreach ($list as $ipaddr) { |
134 | 134 | // find the wild card * in whitelisted ip (f.e. find position in "127.0.*" or "127*") |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | } |
157 | - else{ |
|
157 | + else { |
|
158 | 158 | $logger->info('Whitelist IP access is not enabled in the configuration, ignore checking'); |
159 | 159 | } |
160 | 160 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * also to dispatch the event |
30 | 30 | */ |
31 | 31 | |
32 | - class EventDispatcher{ |
|
32 | + class EventDispatcher { |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * The list of the registered listeners |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | */ |
45 | 45 | private $logger; |
46 | 46 | |
47 | - public function __construct(){ |
|
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
47 | + public function __construct() { |
|
48 | + $this->logger = & class_loader('Log', 'classes'); |
|
49 | 49 | $this->logger->setLogger('Library::EventDispatcher'); |
50 | 50 | } |
51 | 51 | |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | * @param string $eventName the name of the event to register for |
55 | 55 | * @param callable $listener the function or class method to receive the event information after dispatch |
56 | 56 | */ |
57 | - public function addListener($eventName, callable $listener){ |
|
58 | - $this->logger->debug('Adding new Event Listener for the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
59 | - if(! isset($this->listeners[$eventName])){ |
|
57 | + public function addListener($eventName, callable $listener) { |
|
58 | + $this->logger->debug('Adding new Event Listener for the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']'); |
|
59 | + if (!isset($this->listeners[$eventName])) { |
|
60 | 60 | $this->logger->info('This event does not have the registered event listener before, adding new one'); |
61 | 61 | $this->listeners[$eventName] = array(); |
62 | 62 | } |
63 | - else{ |
|
63 | + else { |
|
64 | 64 | $this->logger->info('This event already have the registered listener, add this listener to the list'); |
65 | 65 | } |
66 | 66 | $this->listeners[$eventName][] = $listener; |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | * @param string $eventName the event name |
72 | 72 | * @param callable $listener the listener callback |
73 | 73 | */ |
74 | - public function removeListener($eventName, callable $listener){ |
|
75 | - $this->logger->debug('Removing of the Event Listener, the event name [' .$eventName. '], listener [' .stringfy_vars($listener). ']'); |
|
76 | - if(isset($this->listeners[$eventName])){ |
|
74 | + public function removeListener($eventName, callable $listener) { |
|
75 | + $this->logger->debug('Removing of the Event Listener, the event name [' . $eventName . '], listener [' . stringfy_vars($listener) . ']'); |
|
76 | + if (isset($this->listeners[$eventName])) { |
|
77 | 77 | $this->logger->info('This event have the listeners, check if this listener exists'); |
78 | - if(false !== $index = array_search($listener, $this->listeners[$eventName], true)){ |
|
79 | - $this->logger->info('Found the listener at index [' .$index. '] remove it'); |
|
78 | + if (false !== $index = array_search($listener, $this->listeners[$eventName], true)) { |
|
79 | + $this->logger->info('Found the listener at index [' . $index . '] remove it'); |
|
80 | 80 | unset($this->listeners[$eventName][$index]); |
81 | 81 | } |
82 | - else{ |
|
82 | + else { |
|
83 | 83 | $this->logger->info('Cannot found this listener in the event listener list'); |
84 | 84 | } |
85 | 85 | } |
86 | - else{ |
|
86 | + else { |
|
87 | 87 | $this->logger->info('This event does not have this listener ignore remove'); |
88 | 88 | } |
89 | 89 | } |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | * remove all listeners for this event |
94 | 94 | * @param string $eventName the event name |
95 | 95 | */ |
96 | - public function removeAllListener($eventName = null){ |
|
97 | - $this->logger->debug('Removing of all Event Listener, the event name [' .$eventName. ']'); |
|
98 | - if($eventName != null && isset($this->listeners[$eventName])){ |
|
96 | + public function removeAllListener($eventName = null) { |
|
97 | + $this->logger->debug('Removing of all Event Listener, the event name [' . $eventName . ']'); |
|
98 | + if ($eventName != null && isset($this->listeners[$eventName])) { |
|
99 | 99 | $this->logger->info('The Event name is set of exist in the listener just remove all Event Listener for this event'); |
100 | 100 | unset($this->listeners[$eventName]); |
101 | 101 | } |
102 | - else{ |
|
102 | + else { |
|
103 | 103 | $this->logger->info('The Event name is not set or does not exist in the listener, so remove all Event Listener'); |
104 | 104 | $this->listeners = array(); |
105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string $eventName the event name |
111 | 111 | * @return array the listeners for this event or empty array if this event does not contain any listener |
112 | 112 | */ |
113 | - public function getListeners($eventName){ |
|
113 | + public function getListeners($eventName) { |
|
114 | 114 | return isset($this->listeners[$eventName]) ? $this->listeners[$eventName] : array(); |
115 | 115 | } |
116 | 116 | |
@@ -119,21 +119,21 @@ discard block |
||
119 | 119 | * @param mixed|Event $event the event information |
120 | 120 | * @return void|Event if event need return, will return the final Event object. |
121 | 121 | */ |
122 | - public function dispatch($event){ |
|
123 | - if(! $event || !$event instanceof Event){ |
|
122 | + public function dispatch($event) { |
|
123 | + if (!$event || !$event instanceof Event) { |
|
124 | 124 | $this->logger->info('The event is not set or is not an instance of "Event" create the default "Event" object to use instead of.'); |
125 | 125 | $event = new Event((string) $event); |
126 | 126 | } |
127 | - $this->logger->debug('Dispatch to the Event Listener, the event [' .stringfy_vars($event). ']'); |
|
128 | - if(isset($event->stop) && $event->stop){ |
|
127 | + $this->logger->debug('Dispatch to the Event Listener, the event [' . stringfy_vars($event) . ']'); |
|
128 | + if (isset($event->stop) && $event->stop) { |
|
129 | 129 | $this->logger->info('This event need stopped, no need call any listener'); |
130 | 130 | return; |
131 | 131 | } |
132 | - if($event->returnBack){ |
|
132 | + if ($event->returnBack) { |
|
133 | 133 | $this->logger->info('This event need return back, return the result for future use'); |
134 | 134 | return $this->dispatchToListerners($event); |
135 | 135 | } |
136 | - else{ |
|
136 | + else { |
|
137 | 137 | $this->logger->info('This event no need return back the result, just dispatch it'); |
138 | 138 | $this->dispatchToListerners($event); |
139 | 139 | } |
@@ -144,38 +144,38 @@ discard block |
||
144 | 144 | * @param Event $event the event information |
145 | 145 | * @return void|Event if event need return, will return the final Event instance. |
146 | 146 | */ |
147 | - private function dispatchToListerners(Event $event){ |
|
147 | + private function dispatchToListerners(Event $event) { |
|
148 | 148 | $eBackup = $event; |
149 | 149 | $list = $this->getListeners($event->name); |
150 | - if(empty($list)){ |
|
151 | - $this->logger->info('No event listener is registered for the event [' .$event->name. '] skipping.'); |
|
152 | - if($event->returnBack){ |
|
150 | + if (empty($list)) { |
|
151 | + $this->logger->info('No event listener is registered for the event [' . $event->name . '] skipping.'); |
|
152 | + if ($event->returnBack) { |
|
153 | 153 | return $event; |
154 | 154 | } |
155 | 155 | return; |
156 | 156 | } |
157 | - else{ |
|
158 | - $this->logger->info('Found the registered Event listener for the event [' .$event->name. '] the list are: ' . stringfy_vars($list)); |
|
157 | + else { |
|
158 | + $this->logger->info('Found the registered Event listener for the event [' . $event->name . '] the list are: ' . stringfy_vars($list)); |
|
159 | 159 | } |
160 | - foreach($list as $listener){ |
|
161 | - if($eBackup->returnBack){ |
|
160 | + foreach ($list as $listener) { |
|
161 | + if ($eBackup->returnBack) { |
|
162 | 162 | $returnedEvent = call_user_func_array($listener, array($event)); |
163 | - if($returnedEvent instanceof Event){ |
|
163 | + if ($returnedEvent instanceof Event) { |
|
164 | 164 | $event = $returnedEvent; |
165 | 165 | } |
166 | - else{ |
|
167 | - show_error('This event [' .$event->name. '] need you return the event object after processing'); |
|
166 | + else { |
|
167 | + show_error('This event [' . $event->name . '] need you return the event object after processing'); |
|
168 | 168 | } |
169 | 169 | } |
170 | - else{ |
|
170 | + else { |
|
171 | 171 | call_user_func_array($listener, array($event)); |
172 | 172 | } |
173 | - if($event->stop){ |
|
173 | + if ($event->stop) { |
|
174 | 174 | break; |
175 | 175 | } |
176 | 176 | } |
177 | 177 | //only test for original event may be during the flow some listeners change this parameter |
178 | - if($eBackup->returnBack){ |
|
178 | + if ($eBackup->returnBack) { |
|
179 | 179 | return $event; |
180 | 180 | } |
181 | 181 | } |
@@ -23,165 +23,165 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Database{ |
|
26 | + class Database { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * The PDO instance |
30 | 30 | * @var object |
31 | 31 | */ |
32 | - private $pdo = null; |
|
32 | + private $pdo = null; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * The database name used for the application |
36 | 36 | * @var string |
37 | 37 | */ |
38 | - private $databaseName = null; |
|
38 | + private $databaseName = null; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * The SQL SELECT statment |
42 | 42 | * @var string |
43 | 43 | */ |
44 | - private $select = '*'; |
|
44 | + private $select = '*'; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * The SQL FROM statment |
48 | 48 | * @var string |
49 | 49 | */ |
50 | - private $from = null; |
|
50 | + private $from = null; |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * The SQL WHERE statment |
54 | 54 | * @var string |
55 | 55 | */ |
56 | - private $where = null; |
|
56 | + private $where = null; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * The SQL LIMIT statment |
60 | 60 | * @var string |
61 | 61 | */ |
62 | - private $limit = null; |
|
62 | + private $limit = null; |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * The SQL JOIN statment |
66 | 66 | * @var string |
67 | 67 | */ |
68 | - private $join = null; |
|
68 | + private $join = null; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * The SQL ORDER BY statment |
72 | 72 | * @var string |
73 | 73 | */ |
74 | - private $orderBy = null; |
|
74 | + private $orderBy = null; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * The SQL GROUP BY statment |
78 | 78 | * @var string |
79 | 79 | */ |
80 | - private $groupBy = null; |
|
80 | + private $groupBy = null; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * The SQL HAVING statment |
84 | 84 | * @var string |
85 | 85 | */ |
86 | - private $having = null; |
|
86 | + private $having = null; |
|
87 | 87 | |
88 | 88 | /** |
89 | 89 | * The number of rows returned by the last query |
90 | 90 | * @var int |
91 | 91 | */ |
92 | - private $numRows = 0; |
|
92 | + private $numRows = 0; |
|
93 | 93 | |
94 | 94 | /** |
95 | 95 | * The last insert id for the primary key column that have auto increment or sequence |
96 | 96 | * @var mixed |
97 | 97 | */ |
98 | - private $insertId = null; |
|
98 | + private $insertId = null; |
|
99 | 99 | |
100 | 100 | /** |
101 | 101 | * The full SQL query statment after build for each command |
102 | 102 | * @var string |
103 | 103 | */ |
104 | - private $query = null; |
|
104 | + private $query = null; |
|
105 | 105 | |
106 | 106 | /** |
107 | 107 | * The error returned for the last query |
108 | 108 | * @var string |
109 | 109 | */ |
110 | - private $error = null; |
|
110 | + private $error = null; |
|
111 | 111 | |
112 | 112 | /** |
113 | 113 | * The result returned for the last query |
114 | 114 | * @var mixed |
115 | 115 | */ |
116 | - private $result = array(); |
|
116 | + private $result = array(); |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * The prefix used in each database table |
120 | 120 | * @var string |
121 | 121 | */ |
122 | - private $prefix = null; |
|
122 | + private $prefix = null; |
|
123 | 123 | |
124 | 124 | /** |
125 | 125 | * The list of SQL valid operators |
126 | 126 | * @var array |
127 | 127 | */ |
128 | - private $operatorList = array('=','!=','<','>','<=','>=','<>'); |
|
128 | + private $operatorList = array('=', '!=', '<', '>', '<=', '>=', '<>'); |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * The cache default time to live in second. 0 means no need to use the cache feature |
132 | 132 | * @var int |
133 | 133 | */ |
134 | - private $cacheTtl = 0; |
|
134 | + private $cacheTtl = 0; |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * The cache current time to live. 0 means no need to use the cache feature |
138 | 138 | * @var int |
139 | 139 | */ |
140 | - private $temporaryCacheTtl = 0; |
|
140 | + private $temporaryCacheTtl = 0; |
|
141 | 141 | |
142 | 142 | /** |
143 | 143 | * The number of executed query for the current request |
144 | 144 | * @var int |
145 | 145 | */ |
146 | - private $queryCount = 0; |
|
146 | + private $queryCount = 0; |
|
147 | 147 | |
148 | 148 | /** |
149 | 149 | * The default data to be used in the statments query INSERT, UPDATE |
150 | 150 | * @var array |
151 | 151 | */ |
152 | - private $data = array(); |
|
152 | + private $data = array(); |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * The database configuration |
156 | 156 | * @var array |
157 | 157 | */ |
158 | - private static $config = array(); |
|
158 | + private static $config = array(); |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * The logger instance |
162 | 162 | * @var Log |
163 | 163 | */ |
164 | - private $logger = null; |
|
164 | + private $logger = null; |
|
165 | 165 | |
166 | 166 | /** |
167 | 167 | * Construct new database |
168 | 168 | * @param array $overwriteConfig the config to overwrite with the config set in database.php |
169 | 169 | */ |
170 | - public function __construct($overwriteConfig = array()){ |
|
170 | + public function __construct($overwriteConfig = array()) { |
|
171 | 171 | /** |
172 | 172 | * instance of the Log class |
173 | 173 | */ |
174 | - $this->logger =& class_loader('Log', 'classes'); |
|
174 | + $this->logger = & class_loader('Log', 'classes'); |
|
175 | 175 | $this->logger->setLogger('Library::Database'); |
176 | 176 | |
177 | - if(file_exists(CONFIG_PATH . 'database.php')){ |
|
177 | + if (file_exists(CONFIG_PATH . 'database.php')) { |
|
178 | 178 | //here don't use require_once because somewhere user can create database instance directly |
179 | 179 | require CONFIG_PATH . 'database.php'; |
180 | - if(empty($db) || !is_array($db)){ |
|
180 | + if (empty($db) || !is_array($db)) { |
|
181 | 181 | show_error('No database configuration found in database.php'); |
182 | 182 | } |
183 | - else{ |
|
184 | - if(! empty($overwriteConfig)){ |
|
183 | + else { |
|
184 | + if (!empty($overwriteConfig)) { |
|
185 | 185 | $db = array_merge($db, $overwriteConfig); |
186 | 186 | } |
187 | 187 | $config['driver'] = isset($db['driver']) ? $db['driver'] : 'mysql'; |
@@ -197,25 +197,25 @@ discard block |
||
197 | 197 | $this->databaseName = $config['database']; |
198 | 198 | |
199 | 199 | $dsn = ''; |
200 | - if($config['driver'] == 'mysql' || $config['driver'] == '' || $config['driver'] == 'pgsql'){ |
|
200 | + if ($config['driver'] == 'mysql' || $config['driver'] == '' || $config['driver'] == 'pgsql') { |
|
201 | 201 | $dsn = $config['driver'] . ':host=' . $config['hostname'] . ';' |
202 | 202 | . (($config['port']) != '' ? 'port=' . $config['port'] . ';' : '') |
203 | 203 | . 'dbname=' . $config['database']; |
204 | 204 | } |
205 | - else if ($config['driver'] == 'sqlite'){ |
|
205 | + else if ($config['driver'] == 'sqlite') { |
|
206 | 206 | $dsn = 'sqlite:' . $config['database']; |
207 | 207 | } |
208 | - else if($config['driver'] == 'oracle'){ |
|
208 | + else if ($config['driver'] == 'oracle') { |
|
209 | 209 | $dsn = 'oci:dbname=' . $config['host'] . '/' . $config['database']; |
210 | 210 | } |
211 | 211 | |
212 | - try{ |
|
212 | + try { |
|
213 | 213 | $this->pdo = new PDO($dsn, $config['username'], $config['password']); |
214 | 214 | $this->pdo->exec("SET NAMES '" . $config['charset'] . "' COLLATE '" . $config['collation'] . "'"); |
215 | 215 | $this->pdo->exec("SET CHARACTER SET '" . $config['charset'] . "'"); |
216 | 216 | $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); |
217 | 217 | } |
218 | - catch (PDOException $e){ |
|
218 | + catch (PDOException $e) { |
|
219 | 219 | $this->logger->fatal($e->getMessage()); |
220 | 220 | show_error('Cannot connect to Database.'); |
221 | 221 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $this->logger->info('The database configuration are listed below: ' . stringfy_vars(array_merge($config, array('password' => string_hidden($config['password']))))); |
225 | 225 | } |
226 | 226 | } |
227 | - else{ |
|
227 | + else { |
|
228 | 228 | show_error('Unable to find database configuration'); |
229 | 229 | } |
230 | 230 | } |
@@ -234,15 +234,15 @@ discard block |
||
234 | 234 | * @param string|array $table the table name or array of table list |
235 | 235 | * @return object the current Database instance |
236 | 236 | */ |
237 | - public function from($table){ |
|
238 | - if(is_array($table)){ |
|
237 | + public function from($table) { |
|
238 | + if (is_array($table)) { |
|
239 | 239 | $froms = ''; |
240 | - foreach($table as $key){ |
|
240 | + foreach ($table as $key) { |
|
241 | 241 | $froms .= $this->prefix . $key . ', '; |
242 | 242 | } |
243 | 243 | $this->from = rtrim($froms, ', '); |
244 | 244 | } |
245 | - else{ |
|
245 | + else { |
|
246 | 246 | $this->from = $this->prefix . $table; |
247 | 247 | } |
248 | 248 | return $this; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @param string|array $fields the field name or array of field list |
254 | 254 | * @return object the current Database instance |
255 | 255 | */ |
256 | - public function select($fields){ |
|
256 | + public function select($fields) { |
|
257 | 257 | $select = (is_array($fields) ? implode(', ', $fields) : $fields); |
258 | 258 | $this->select = ($this->select == '*' ? $select : $this->select . ', ' . $select); |
259 | 259 | return $this; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @param string $field the field name to distinct |
265 | 265 | * @return object the current Database instance |
266 | 266 | */ |
267 | - public function distinct($field){ |
|
267 | + public function distinct($field) { |
|
268 | 268 | $distinct = ' DISTINCT ' . $field; |
269 | 269 | $this->select = ($this->select == '*' ? $distinct : $this->select . ', ' . $distinct); |
270 | 270 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param string $name if is not null represent the alias used for this field in the result |
278 | 278 | * @return object the current Database instance |
279 | 279 | */ |
280 | - public function max($field, $name = null){ |
|
280 | + public function max($field, $name = null) { |
|
281 | 281 | $func = 'MAX(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
282 | 282 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
283 | 283 | return $this; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @param string $name if is not null represent the alias used for this field in the result |
290 | 290 | * @return object the current Database instance |
291 | 291 | */ |
292 | - public function min($field, $name = null){ |
|
292 | + public function min($field, $name = null) { |
|
293 | 293 | $func = 'MIN(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
294 | 294 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
295 | 295 | return $this; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @param string $name if is not null represent the alias used for this field in the result |
302 | 302 | * @return object the current Database instance |
303 | 303 | */ |
304 | - public function sum($field, $name = null){ |
|
304 | + public function sum($field, $name = null) { |
|
305 | 305 | $func = 'SUM(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
306 | 306 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
307 | 307 | return $this; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * @param string $name if is not null represent the alias used for this field in the result |
314 | 314 | * @return object the current Database instance |
315 | 315 | */ |
316 | - public function count($field = '*', $name = null){ |
|
316 | + public function count($field = '*', $name = null) { |
|
317 | 317 | $func = 'COUNT(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
318 | 318 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
319 | 319 | return $this; |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $name if is not null represent the alias used for this field in the result |
326 | 326 | * @return object the current Database instance |
327 | 327 | */ |
328 | - public function avg($field, $name = null){ |
|
328 | + public function avg($field, $name = null) { |
|
329 | 329 | $func = 'AVG(' . $field . ')' . (!is_null($name) ? ' AS ' . $name : ''); |
330 | 330 | $this->select = ($this->select == '*' ? $func : $this->select . ', ' . $func); |
331 | 331 | return $this; |
@@ -340,16 +340,16 @@ discard block |
||
340 | 340 | * @param string $type the type of join (INNER, LEFT, RIGHT) |
341 | 341 | * @return object the current Database instance |
342 | 342 | */ |
343 | - public function join($table, $field1 = null, $op = null, $field2 = null, $type = ''){ |
|
343 | + public function join($table, $field1 = null, $op = null, $field2 = null, $type = '') { |
|
344 | 344 | $on = $field1; |
345 | 345 | $table = $this->prefix . $table; |
346 | - if(! is_null($op)){ |
|
347 | - $on = (! in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
346 | + if (!is_null($op)) { |
|
347 | + $on = (!in_array($op, $this->operatorList) ? $this->prefix . $field1 . ' = ' . $this->prefix . $op : $this->prefix . $field1 . ' ' . $op . ' ' . $this->prefix . $field2); |
|
348 | 348 | } |
349 | - if (is_null($this->join)){ |
|
349 | + if (is_null($this->join)) { |
|
350 | 350 | $this->join = ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
351 | 351 | } |
352 | - else{ |
|
352 | + else { |
|
353 | 353 | $this->join = $this->join . ' ' . $type . 'JOIN' . ' ' . $table . ' ON ' . $on; |
354 | 354 | } |
355 | 355 | return $this; |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @see Database::join() |
361 | 361 | * @return object the current Database instance |
362 | 362 | */ |
363 | - public function innerJoin($table, $field1, $op = null, $field2 = ''){ |
|
363 | + public function innerJoin($table, $field1, $op = null, $field2 = '') { |
|
364 | 364 | return $this->join($table, $field1, $op, $field2, 'INNER '); |
365 | 365 | } |
366 | 366 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @see Database::join() |
370 | 370 | * @return object the current Database instance |
371 | 371 | */ |
372 | - public function leftJoin($table, $field1, $op = null, $field2 = ''){ |
|
372 | + public function leftJoin($table, $field1, $op = null, $field2 = '') { |
|
373 | 373 | return $this->join($table, $field1, $op, $field2, 'LEFT '); |
374 | 374 | } |
375 | 375 | |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @see Database::join() |
379 | 379 | * @return object the current Database instance |
380 | 380 | */ |
381 | - public function rightJoin($table, $field1, $op = null, $field2 = ''){ |
|
381 | + public function rightJoin($table, $field1, $op = null, $field2 = '') { |
|
382 | 382 | return $this->join($table, $field1, $op, $field2, 'RIGHT '); |
383 | 383 | } |
384 | 384 | |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @see Database::join() |
388 | 388 | * @return object the current Database instance |
389 | 389 | */ |
390 | - public function fullOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
390 | + public function fullOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
391 | 391 | return $this->join($table, $field1, $op, $field2, 'FULL OUTER '); |
392 | 392 | } |
393 | 393 | |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @see Database::join() |
397 | 397 | * @return object the current Database instance |
398 | 398 | */ |
399 | - public function leftOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
399 | + public function leftOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
400 | 400 | return $this->join($table, $field1, $op, $field2, 'LEFT OUTER '); |
401 | 401 | } |
402 | 402 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * @see Database::join() |
406 | 406 | * @return object the current Database instance |
407 | 407 | */ |
408 | - public function rightOuterJoin($table, $field1, $op = null, $field2 = ''){ |
|
408 | + public function rightOuterJoin($table, $field1, $op = null, $field2 = '') { |
|
409 | 409 | return $this->join($table, $field1, $op, $field2, 'RIGHT OUTER '); |
410 | 410 | } |
411 | 411 | |
@@ -415,18 +415,18 @@ discard block |
||
415 | 415 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
416 | 416 | * @return object the current Database instance |
417 | 417 | */ |
418 | - public function whereIsNull($field, $andOr = 'AND'){ |
|
419 | - if(is_array($field)){ |
|
420 | - foreach($field as $f){ |
|
418 | + public function whereIsNull($field, $andOr = 'AND') { |
|
419 | + if (is_array($field)) { |
|
420 | + foreach ($field as $f) { |
|
421 | 421 | $this->whereIsNull($f, $andOr); |
422 | 422 | } |
423 | 423 | } |
424 | - else{ |
|
425 | - if (! $this->where){ |
|
426 | - $this->where = $field.' IS NULL '; |
|
424 | + else { |
|
425 | + if (!$this->where) { |
|
426 | + $this->where = $field . ' IS NULL '; |
|
427 | 427 | } |
428 | - else{ |
|
429 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NULL '; |
|
428 | + else { |
|
429 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NULL '; |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | return $this; |
@@ -438,18 +438,18 @@ discard block |
||
438 | 438 | * @param string $andOr the separator type used 'AND', 'OR', etc. |
439 | 439 | * @return object the current Database instance |
440 | 440 | */ |
441 | - public function whereIsNotNull($field, $andOr = 'AND'){ |
|
442 | - if(is_array($field)){ |
|
443 | - foreach($field as $f){ |
|
441 | + public function whereIsNotNull($field, $andOr = 'AND') { |
|
442 | + if (is_array($field)) { |
|
443 | + foreach ($field as $f) { |
|
444 | 444 | $this->whereIsNotNull($f, $andOr); |
445 | 445 | } |
446 | 446 | } |
447 | - else{ |
|
448 | - if (! $this->where){ |
|
449 | - $this->where = $field.' IS NOT NULL '; |
|
447 | + else { |
|
448 | + if (!$this->where) { |
|
449 | + $this->where = $field . ' IS NOT NULL '; |
|
450 | 450 | } |
451 | - else{ |
|
452 | - $this->where = $this->where . ' '.$andOr.' ' . $field.' IS NOT NULL '; |
|
451 | + else { |
|
452 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' IS NOT NULL '; |
|
453 | 453 | } |
454 | 454 | } |
455 | 455 | return $this; |
@@ -465,24 +465,24 @@ discard block |
||
465 | 465 | * @param boolean $escape whether to escape or not the $val |
466 | 466 | * @return object the current Database instance |
467 | 467 | */ |
468 | - public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true){ |
|
469 | - if (is_array($where)){ |
|
468 | + public function where($where, $op = null, $val = null, $type = '', $andOr = 'AND', $escape = true) { |
|
469 | + if (is_array($where)) { |
|
470 | 470 | $_where = array(); |
471 | - foreach ($where as $column => $data){ |
|
472 | - if(is_null($data)){ |
|
471 | + foreach ($where as $column => $data) { |
|
472 | + if (is_null($data)) { |
|
473 | 473 | $data = ''; |
474 | 474 | } |
475 | 475 | $_where[] = $type . $column . '=' . ($escape ? $this->escape($data) : $data); |
476 | 476 | } |
477 | - $where = implode(' '.$andOr.' ', $_where); |
|
477 | + $where = implode(' ' . $andOr . ' ', $_where); |
|
478 | 478 | } |
479 | - else{ |
|
480 | - if(is_array($op)){ |
|
479 | + else { |
|
480 | + if (is_array($op)) { |
|
481 | 481 | $x = explode('?', $where); |
482 | 482 | $w = ''; |
483 | - foreach($x as $k => $v){ |
|
484 | - if(! empty($v)){ |
|
485 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
483 | + foreach ($x as $k => $v) { |
|
484 | + if (!empty($v)) { |
|
485 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
486 | 486 | $op[$k] = ''; |
487 | 487 | } |
488 | 488 | $w .= $type . $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
@@ -490,28 +490,28 @@ discard block |
||
490 | 490 | } |
491 | 491 | $where = $w; |
492 | 492 | } |
493 | - else if (! in_array((string)$op, $this->operatorList)){ |
|
494 | - if(is_null($op)){ |
|
493 | + else if (!in_array((string) $op, $this->operatorList)) { |
|
494 | + if (is_null($op)) { |
|
495 | 495 | $op = ''; |
496 | 496 | } |
497 | 497 | $where = $type . $where . ' = ' . ($escape ? $this->escape($op) : $op); |
498 | 498 | } |
499 | - else{ |
|
500 | - if(is_null($val)){ |
|
499 | + else { |
|
500 | + if (is_null($val)) { |
|
501 | 501 | $val = ''; |
502 | 502 | } |
503 | 503 | $where = $type . $where . $op . ($escape ? $this->escape($val) : $val); |
504 | 504 | } |
505 | 505 | } |
506 | - if (is_null($this->where)){ |
|
506 | + if (is_null($this->where)) { |
|
507 | 507 | $this->where = $where; |
508 | 508 | } |
509 | - else{ |
|
510 | - if(substr($this->where, -1) == '('){ |
|
509 | + else { |
|
510 | + if (substr($this->where, -1) == '(') { |
|
511 | 511 | $this->where = $this->where . ' ' . $where; |
512 | 512 | } |
513 | - else{ |
|
514 | - $this->where = $this->where . ' '.$andOr.' ' . $where; |
|
513 | + else { |
|
514 | + $this->where = $this->where . ' ' . $andOr . ' ' . $where; |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | return $this; |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | * @see Database::where() |
523 | 523 | * @return object the current Database instance |
524 | 524 | */ |
525 | - public function orWhere($where, $op = null, $val = null, $escape = true){ |
|
525 | + public function orWhere($where, $op = null, $val = null, $escape = true) { |
|
526 | 526 | return $this->where($where, $op, $val, '', 'OR', $escape); |
527 | 527 | } |
528 | 528 | |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | * @see Database::where() |
533 | 533 | * @return object the current Database instance |
534 | 534 | */ |
535 | - public function notWhere($where, $op = null, $val = null, $escape = true){ |
|
535 | + public function notWhere($where, $op = null, $val = null, $escape = true) { |
|
536 | 536 | return $this->where($where, $op, $val, 'NOT ', 'AND', $escape); |
537 | 537 | } |
538 | 538 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * @see Database::where() |
542 | 542 | * @return object the current Database instance |
543 | 543 | */ |
544 | - public function orNotWhere($where, $op = null, $val = null, $escape = true){ |
|
544 | + public function orNotWhere($where, $op = null, $val = null, $escape = true) { |
|
545 | 545 | return $this->where($where, $op, $val, 'NOT ', 'OR', $escape); |
546 | 546 | } |
547 | 547 | |
@@ -551,15 +551,15 @@ discard block |
||
551 | 551 | * @param string $andOr the multiple conditions separator (AND, OR, etc.) |
552 | 552 | * @return object the current Database instance |
553 | 553 | */ |
554 | - public function groupStart($type = '', $andOr = ' AND'){ |
|
555 | - if (is_null($this->where)){ |
|
554 | + public function groupStart($type = '', $andOr = ' AND') { |
|
555 | + if (is_null($this->where)) { |
|
556 | 556 | $this->where = $type . ' ('; |
557 | 557 | } |
558 | - else{ |
|
559 | - if(substr($this->where, -1) == '('){ |
|
558 | + else { |
|
559 | + if (substr($this->where, -1) == '(') { |
|
560 | 560 | $this->where .= $type . ' ('; |
561 | 561 | } |
562 | - else{ |
|
562 | + else { |
|
563 | 563 | $this->where .= $andOr . ' ' . $type . ' ('; |
564 | 564 | } |
565 | 565 | } |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | * @see Database::groupStart() |
572 | 572 | * @return object the current Database instance |
573 | 573 | */ |
574 | - public function notGroupStart(){ |
|
574 | + public function notGroupStart() { |
|
575 | 575 | return $this->groupStart('NOT'); |
576 | 576 | } |
577 | 577 | |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @see Database::groupStart() |
581 | 581 | * @return object the current Database instance |
582 | 582 | */ |
583 | - public function orGroupStart(){ |
|
583 | + public function orGroupStart() { |
|
584 | 584 | return $this->groupStart('', ' OR'); |
585 | 585 | } |
586 | 586 | |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | * @see Database::groupStart() |
590 | 590 | * @return object the current Database instance |
591 | 591 | */ |
592 | - public function orNotGroupStart(){ |
|
592 | + public function orNotGroupStart() { |
|
593 | 593 | return $this->groupStart('NOT', ' OR'); |
594 | 594 | } |
595 | 595 | |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | * Close the parenthesis for the grouped SQL |
598 | 598 | * @return object the current Database instance |
599 | 599 | */ |
600 | - public function groupEnd(){ |
|
600 | + public function groupEnd() { |
|
601 | 601 | $this->where .= ')'; |
602 | 602 | return $this; |
603 | 603 | } |
@@ -611,25 +611,25 @@ discard block |
||
611 | 611 | * @param boolean $escape whether to escape or not the values |
612 | 612 | * @return object the current Database instance |
613 | 613 | */ |
614 | - public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true){ |
|
615 | - if (is_array($keys)){ |
|
614 | + public function in($field, array $keys, $type = '', $andOr = 'AND', $escape = true) { |
|
615 | + if (is_array($keys)) { |
|
616 | 616 | $_keys = array(); |
617 | - foreach ($keys as $k => $v){ |
|
618 | - if(is_null($v)){ |
|
617 | + foreach ($keys as $k => $v) { |
|
618 | + if (is_null($v)) { |
|
619 | 619 | $v = ''; |
620 | 620 | } |
621 | 621 | $_keys[] = (is_numeric($v) ? $v : ($escape ? $this->escape($v) : $v)); |
622 | 622 | } |
623 | 623 | $keys = implode(', ', $_keys); |
624 | - if (is_null($this->where)){ |
|
624 | + if (is_null($this->where)) { |
|
625 | 625 | $this->where = $field . ' ' . $type . 'IN (' . $keys . ')'; |
626 | 626 | } |
627 | - else{ |
|
628 | - if(substr($this->where, -1) == '('){ |
|
629 | - $this->where = $this->where . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
627 | + else { |
|
628 | + if (substr($this->where, -1) == '(') { |
|
629 | + $this->where = $this->where . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
630 | 630 | } |
631 | - else{ |
|
632 | - $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' '.$type.'IN (' . $keys . ')'; |
|
631 | + else { |
|
632 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'IN (' . $keys . ')'; |
|
633 | 633 | } |
634 | 634 | } |
635 | 635 | } |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | * @see Database::in() |
642 | 642 | * @return object the current Database instance |
643 | 643 | */ |
644 | - public function notIn($field, array $keys, $escape = true){ |
|
644 | + public function notIn($field, array $keys, $escape = true) { |
|
645 | 645 | return $this->in($field, $keys, 'NOT ', 'AND', $escape); |
646 | 646 | } |
647 | 647 | |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | * @see Database::in() |
651 | 651 | * @return object the current Database instance |
652 | 652 | */ |
653 | - public function orIn($field, array $keys, $escape = true){ |
|
653 | + public function orIn($field, array $keys, $escape = true) { |
|
654 | 654 | return $this->in($field, $keys, '', 'OR', $escape); |
655 | 655 | } |
656 | 656 | |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | * @see Database::in() |
660 | 660 | * @return object the current Database instance |
661 | 661 | */ |
662 | - public function orNotIn($field, array $keys, $escape = true){ |
|
662 | + public function orNotIn($field, array $keys, $escape = true) { |
|
663 | 663 | return $this->in($field, $keys, 'NOT ', 'OR', $escape); |
664 | 664 | } |
665 | 665 | |
@@ -673,21 +673,21 @@ discard block |
||
673 | 673 | * @param boolean $escape whether to escape or not the values |
674 | 674 | * @return object the current Database instance |
675 | 675 | */ |
676 | - public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true){ |
|
677 | - if(is_null($value1)){ |
|
676 | + public function between($field, $value1, $value2, $type = '', $andOr = 'AND', $escape = true) { |
|
677 | + if (is_null($value1)) { |
|
678 | 678 | $value1 = ''; |
679 | 679 | } |
680 | - if(is_null($value2)){ |
|
680 | + if (is_null($value2)) { |
|
681 | 681 | $value2 = ''; |
682 | 682 | } |
683 | - if (is_null($this->where)){ |
|
683 | + if (is_null($this->where)) { |
|
684 | 684 | $this->where = $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
685 | 685 | } |
686 | - else{ |
|
687 | - if(substr($this->where, -1) == '('){ |
|
686 | + else { |
|
687 | + if (substr($this->where, -1) == '(') { |
|
688 | 688 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
689 | 689 | } |
690 | - else{ |
|
690 | + else { |
|
691 | 691 | $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'BETWEEN ' . ($escape ? $this->escape($value1) : $value1) . ' AND ' . ($escape ? $this->escape($value2) : $value2); |
692 | 692 | } |
693 | 693 | } |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | * @see Database::between() |
700 | 700 | * @return object the current Database instance |
701 | 701 | */ |
702 | - public function notBetween($field, $value1, $value2, $escape = true){ |
|
702 | + public function notBetween($field, $value1, $value2, $escape = true) { |
|
703 | 703 | return $this->between($field, $value1, $value2, 'NOT ', 'AND', $escape); |
704 | 704 | } |
705 | 705 | |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | * @see Database::between() |
709 | 709 | * @return object the current Database instance |
710 | 710 | */ |
711 | - public function orBetween($field, $value1, $value2, $escape = true){ |
|
711 | + public function orBetween($field, $value1, $value2, $escape = true) { |
|
712 | 712 | return $this->between($field, $value1, $value2, '', 'OR', $escape); |
713 | 713 | } |
714 | 714 | |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | * @see Database::between() |
718 | 718 | * @return object the current Database instance |
719 | 719 | */ |
720 | - public function orNotBetween($field, $value1, $value2, $escape = true){ |
|
720 | + public function orNotBetween($field, $value1, $value2, $escape = true) { |
|
721 | 721 | return $this->between($field, $value1, $value2, 'NOT ', 'OR', $escape); |
722 | 722 | } |
723 | 723 | |
@@ -730,20 +730,20 @@ discard block |
||
730 | 730 | * @param boolean $escape whether to escape or not the values |
731 | 731 | * @return object the current Database instance |
732 | 732 | */ |
733 | - public function like($field, $data, $type = '', $andOr = 'AND', $escape = true){ |
|
734 | - if(is_null($data)){ |
|
733 | + public function like($field, $data, $type = '', $andOr = 'AND', $escape = true) { |
|
734 | + if (is_null($data)) { |
|
735 | 735 | $data = ''; |
736 | 736 | } |
737 | 737 | $like = $escape ? $this->escape($data) : $data; |
738 | - if (is_null($this->where)){ |
|
738 | + if (is_null($this->where)) { |
|
739 | 739 | $this->where = $field . ' ' . $type . 'LIKE ' . $like; |
740 | 740 | } |
741 | - else{ |
|
742 | - if(substr($this->where, -1) == '('){ |
|
741 | + else { |
|
742 | + if (substr($this->where, -1) == '(') { |
|
743 | 743 | $this->where = $this->where . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
744 | 744 | } |
745 | - else{ |
|
746 | - $this->where = $this->where . ' '.$andOr.' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
745 | + else { |
|
746 | + $this->where = $this->where . ' ' . $andOr . ' ' . $field . ' ' . $type . 'LIKE ' . $like; |
|
747 | 747 | } |
748 | 748 | } |
749 | 749 | return $this; |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | * @see Database::like() |
755 | 755 | * @return object the current Database instance |
756 | 756 | */ |
757 | - public function orLike($field, $data, $escape = true){ |
|
757 | + public function orLike($field, $data, $escape = true) { |
|
758 | 758 | return $this->like($field, $data, '', 'OR', $escape); |
759 | 759 | } |
760 | 760 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | * @see Database::like() |
764 | 764 | * @return object the current Database instance |
765 | 765 | */ |
766 | - public function notLike($field, $data, $escape = true){ |
|
766 | + public function notLike($field, $data, $escape = true) { |
|
767 | 767 | return $this->like($field, $data, 'NOT ', 'AND', $escape); |
768 | 768 | } |
769 | 769 | |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | * @see Database::like() |
773 | 773 | * @return object the current Database instance |
774 | 774 | */ |
775 | - public function orNotLike($field, $data, $escape = true){ |
|
775 | + public function orNotLike($field, $data, $escape = true) { |
|
776 | 776 | return $this->like($field, $data, 'NOT ', 'OR', $escape); |
777 | 777 | } |
778 | 778 | |
@@ -783,14 +783,14 @@ discard block |
||
783 | 783 | * @param int $limitEnd the limit count |
784 | 784 | * @return object the current Database instance |
785 | 785 | */ |
786 | - public function limit($limit, $limitEnd = null){ |
|
787 | - if(is_null($limit)){ |
|
786 | + public function limit($limit, $limitEnd = null) { |
|
787 | + if (is_null($limit)) { |
|
788 | 788 | return; |
789 | 789 | } |
790 | - if (! is_null($limitEnd)){ |
|
790 | + if (!is_null($limitEnd)) { |
|
791 | 791 | $this->limit = $limit . ', ' . $limitEnd; |
792 | 792 | } |
793 | - else{ |
|
793 | + else { |
|
794 | 794 | $this->limit = $limit; |
795 | 795 | } |
796 | 796 | return $this; |
@@ -802,16 +802,16 @@ discard block |
||
802 | 802 | * @param string $orderDir the order direction (ASC or DESC) |
803 | 803 | * @return object the current Database instance |
804 | 804 | */ |
805 | - public function orderBy($orderBy, $orderDir = ' ASC'){ |
|
806 | - if (! is_null($orderDir)){ |
|
807 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
805 | + public function orderBy($orderBy, $orderDir = ' ASC') { |
|
806 | + if (!is_null($orderDir)) { |
|
807 | + $this->orderBy = !$this->orderBy ? ($orderBy . ' ' . strtoupper($orderDir)) : $this->orderBy . ', ' . $orderBy . ' ' . strtoupper($orderDir); |
|
808 | 808 | } |
809 | - else{ |
|
810 | - if(stristr($orderBy, ' ') || $orderBy == 'rand()'){ |
|
811 | - $this->orderBy = ! $this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
809 | + else { |
|
810 | + if (stristr($orderBy, ' ') || $orderBy == 'rand()') { |
|
811 | + $this->orderBy = !$this->orderBy ? $orderBy : $this->orderBy . ', ' . $orderBy; |
|
812 | 812 | } |
813 | - else{ |
|
814 | - $this->orderBy = ! $this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
813 | + else { |
|
814 | + $this->orderBy = !$this->orderBy ? ($orderBy . ' ASC') : $this->orderBy . ', ' . ($orderBy . ' ASC'); |
|
815 | 815 | } |
816 | 816 | } |
817 | 817 | return $this; |
@@ -822,11 +822,11 @@ discard block |
||
822 | 822 | * @param string|array $field the field name used or array of field list |
823 | 823 | * @return object the current Database instance |
824 | 824 | */ |
825 | - public function groupBy($field){ |
|
826 | - if(is_array($field)){ |
|
825 | + public function groupBy($field) { |
|
826 | + if (is_array($field)) { |
|
827 | 827 | $this->groupBy = implode(', ', $field); |
828 | 828 | } |
829 | - else{ |
|
829 | + else { |
|
830 | 830 | $this->groupBy = $field; |
831 | 831 | } |
832 | 832 | return $this; |
@@ -840,13 +840,13 @@ discard block |
||
840 | 840 | * @param boolean $escape whether to escape or not the values |
841 | 841 | * @return object the current Database instance |
842 | 842 | */ |
843 | - public function having($field, $op = null, $val = null, $escape = true){ |
|
844 | - if(is_array($op)){ |
|
843 | + public function having($field, $op = null, $val = null, $escape = true) { |
|
844 | + if (is_array($op)) { |
|
845 | 845 | $x = explode('?', $field); |
846 | 846 | $w = ''; |
847 | - foreach($x as $k => $v){ |
|
848 | - if(!empty($v)){ |
|
849 | - if(isset($op[$k]) && is_null($op[$k])){ |
|
847 | + foreach ($x as $k => $v) { |
|
848 | + if (!empty($v)) { |
|
849 | + if (isset($op[$k]) && is_null($op[$k])) { |
|
850 | 850 | $op[$k] = ''; |
851 | 851 | } |
852 | 852 | $w .= $v . (isset($op[$k]) ? ($escape ? $this->escape($op[$k]) : $op[$k]) : ''); |
@@ -854,14 +854,14 @@ discard block |
||
854 | 854 | } |
855 | 855 | $this->having = $w; |
856 | 856 | } |
857 | - else if (! in_array($op, $this->operatorList)){ |
|
858 | - if(is_null($op)){ |
|
857 | + else if (!in_array($op, $this->operatorList)) { |
|
858 | + if (is_null($op)) { |
|
859 | 859 | $op = ''; |
860 | 860 | } |
861 | 861 | $this->having = $field . ' > ' . ($escape ? $this->escape($op) : $op); |
862 | 862 | } |
863 | - else{ |
|
864 | - if(is_null($val)){ |
|
863 | + else { |
|
864 | + if (is_null($val)) { |
|
865 | 865 | $val = ''; |
866 | 866 | } |
867 | 867 | $this->having = $field . ' ' . $op . ' ' . ($escape ? $this->escape($val) : $val); |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | * Return the number of rows returned by the current query |
874 | 874 | * @return int |
875 | 875 | */ |
876 | - public function numRows(){ |
|
876 | + public function numRows() { |
|
877 | 877 | return $this->numRows; |
878 | 878 | } |
879 | 879 | |
@@ -881,15 +881,15 @@ discard block |
||
881 | 881 | * Return the last insert id value |
882 | 882 | * @return mixed |
883 | 883 | */ |
884 | - public function insertId(){ |
|
884 | + public function insertId() { |
|
885 | 885 | return $this->insertId; |
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
889 | 889 | * Show an error got from the current query (SQL command synthax error, database driver returned error, etc.) |
890 | 890 | */ |
891 | - public function error(){ |
|
892 | - if($this->error){ |
|
891 | + public function error() { |
|
892 | + if ($this->error) { |
|
893 | 893 | show_error('Query: "' . $this->query . '" Error: ' . $this->error, 'Database Error'); |
894 | 894 | } |
895 | 895 | } |
@@ -900,14 +900,14 @@ discard block |
||
900 | 900 | * If is string will determine the result type "array" or "object" |
901 | 901 | * @return mixed the query SQL string or the record result |
902 | 902 | */ |
903 | - public function get($returnSQLQueryOrResultType = false){ |
|
903 | + public function get($returnSQLQueryOrResultType = false) { |
|
904 | 904 | $this->limit = 1; |
905 | 905 | $query = $this->getAll(true); |
906 | - if($returnSQLQueryOrResultType === true){ |
|
906 | + if ($returnSQLQueryOrResultType === true) { |
|
907 | 907 | return $query; |
908 | 908 | } |
909 | - else{ |
|
910 | - return $this->query( $query, false, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
909 | + else { |
|
910 | + return $this->query($query, false, (($returnSQLQueryOrResultType == 'array') ? true : false)); |
|
911 | 911 | } |
912 | 912 | } |
913 | 913 | |
@@ -917,37 +917,37 @@ discard block |
||
917 | 917 | * If is string will determine the result type "array" or "object" |
918 | 918 | * @return mixed the query SQL string or the record result |
919 | 919 | */ |
920 | - public function getAll($returnSQLQueryOrResultType = false){ |
|
920 | + public function getAll($returnSQLQueryOrResultType = false) { |
|
921 | 921 | $query = 'SELECT ' . $this->select . ' FROM ' . $this->from; |
922 | - if (! is_null($this->join)){ |
|
922 | + if (!is_null($this->join)) { |
|
923 | 923 | $query .= $this->join; |
924 | 924 | } |
925 | 925 | |
926 | - if (! is_null($this->where)){ |
|
926 | + if (!is_null($this->where)) { |
|
927 | 927 | $query .= ' WHERE ' . $this->where; |
928 | 928 | } |
929 | 929 | |
930 | - if (! is_null($this->groupBy)){ |
|
930 | + if (!is_null($this->groupBy)) { |
|
931 | 931 | $query .= ' GROUP BY ' . $this->groupBy; |
932 | 932 | } |
933 | 933 | |
934 | - if (! is_null($this->having)){ |
|
934 | + if (!is_null($this->having)) { |
|
935 | 935 | $query .= ' HAVING ' . $this->having; |
936 | 936 | } |
937 | 937 | |
938 | - if (! is_null($this->orderBy)){ |
|
938 | + if (!is_null($this->orderBy)) { |
|
939 | 939 | $query .= ' ORDER BY ' . $this->orderBy; |
940 | 940 | } |
941 | 941 | |
942 | - if(! is_null($this->limit)){ |
|
942 | + if (!is_null($this->limit)) { |
|
943 | 943 | $query .= ' LIMIT ' . $this->limit; |
944 | 944 | } |
945 | 945 | |
946 | - if($returnSQLQueryOrResultType === true){ |
|
946 | + if ($returnSQLQueryOrResultType === true) { |
|
947 | 947 | return $query; |
948 | 948 | } |
949 | - else{ |
|
950 | - return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false) ); |
|
949 | + else { |
|
950 | + return $this->query($query, true, (($returnSQLQueryOrResultType == 'array') ? true : false)); |
|
951 | 951 | } |
952 | 952 | } |
953 | 953 | |
@@ -957,15 +957,15 @@ discard block |
||
957 | 957 | * @param boolean $escape whether to escape or not the values |
958 | 958 | * @return mixed the insert id of the new record or null |
959 | 959 | */ |
960 | - public function insert($data = array(), $escape = true){ |
|
960 | + public function insert($data = array(), $escape = true) { |
|
961 | 961 | $column = array(); |
962 | 962 | $val = array(); |
963 | - if(! $data && $this->getData()){ |
|
963 | + if (!$data && $this->getData()) { |
|
964 | 964 | $columns = array_keys($this->getData()); |
965 | 965 | $column = implode(',', $columns); |
966 | 966 | $val = implode(', ', $this->getData()); |
967 | 967 | } |
968 | - else{ |
|
968 | + else { |
|
969 | 969 | $columns = array_keys($data); |
970 | 970 | $column = implode(',', $columns); |
971 | 971 | $val = implode(', ', ($escape ? array_map(array($this, 'escape'), $data) : $data)); |
@@ -974,11 +974,11 @@ discard block |
||
974 | 974 | $query = 'INSERT INTO ' . $this->from . ' (' . $column . ') VALUES (' . $val . ')'; |
975 | 975 | $query = $this->query($query); |
976 | 976 | |
977 | - if ($query){ |
|
977 | + if ($query) { |
|
978 | 978 | $this->insertId = $this->pdo->lastInsertId(); |
979 | 979 | return $this->insertId(); |
980 | 980 | } |
981 | - else{ |
|
981 | + else { |
|
982 | 982 | return false; |
983 | 983 | } |
984 | 984 | } |
@@ -989,29 +989,29 @@ discard block |
||
989 | 989 | * @param boolean $escape whether to escape or not the values |
990 | 990 | * @return mixed the update status |
991 | 991 | */ |
992 | - public function update($data = array(), $escape = true){ |
|
992 | + public function update($data = array(), $escape = true) { |
|
993 | 993 | $query = 'UPDATE ' . $this->from . ' SET '; |
994 | 994 | $values = array(); |
995 | - if(! $data && $this->getData()){ |
|
996 | - foreach ($this->getData() as $column => $val){ |
|
995 | + if (!$data && $this->getData()) { |
|
996 | + foreach ($this->getData() as $column => $val) { |
|
997 | 997 | $values[] = $column . ' = ' . $val; |
998 | 998 | } |
999 | 999 | } |
1000 | - else{ |
|
1001 | - foreach ($data as $column => $val){ |
|
1000 | + else { |
|
1001 | + foreach ($data as $column => $val) { |
|
1002 | 1002 | $values[] = $column . '=' . ($escape ? $this->escape($val) : $val); |
1003 | 1003 | } |
1004 | 1004 | } |
1005 | 1005 | $query .= (is_array($data) ? implode(', ', $values) : $data); |
1006 | - if (! is_null($this->where)){ |
|
1006 | + if (!is_null($this->where)) { |
|
1007 | 1007 | $query .= ' WHERE ' . $this->where; |
1008 | 1008 | } |
1009 | 1009 | |
1010 | - if (! is_null($this->orderBy)){ |
|
1010 | + if (!is_null($this->orderBy)) { |
|
1011 | 1011 | $query .= ' ORDER BY ' . $this->orderBy; |
1012 | 1012 | } |
1013 | 1013 | |
1014 | - if (! is_null($this->limit)){ |
|
1014 | + if (!is_null($this->limit)) { |
|
1015 | 1015 | $query .= ' LIMIT ' . $this->limit; |
1016 | 1016 | } |
1017 | 1017 | return $this->query($query); |
@@ -1021,22 +1021,22 @@ discard block |
||
1021 | 1021 | * Delete the record in database |
1022 | 1022 | * @return mixed the delete status |
1023 | 1023 | */ |
1024 | - public function delete(){ |
|
1024 | + public function delete() { |
|
1025 | 1025 | $query = 'DELETE FROM ' . $this->from; |
1026 | 1026 | |
1027 | - if (! is_null($this->where)){ |
|
1027 | + if (!is_null($this->where)) { |
|
1028 | 1028 | $query .= ' WHERE ' . $this->where; |
1029 | 1029 | } |
1030 | 1030 | |
1031 | - if (! is_null($this->orderBy)){ |
|
1031 | + if (!is_null($this->orderBy)) { |
|
1032 | 1032 | $query .= ' ORDER BY ' . $this->orderBy; |
1033 | 1033 | } |
1034 | 1034 | |
1035 | - if (! is_null($this->limit)){ |
|
1035 | + if (!is_null($this->limit)) { |
|
1036 | 1036 | $query .= ' LIMIT ' . $this->limit; |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - if($query == 'DELETE FROM ' . $this->from){ |
|
1039 | + if ($query == 'DELETE FROM ' . $this->from) { |
|
1040 | 1040 | $query = 'TRUNCATE TABLE ' . $this->from; |
1041 | 1041 | } |
1042 | 1042 | return $this->query($query); |
@@ -1049,13 +1049,13 @@ discard block |
||
1049 | 1049 | * @param boolean $array return the result as array |
1050 | 1050 | * @return mixed the query result |
1051 | 1051 | */ |
1052 | - public function query($query, $all = true, $array = false){ |
|
1052 | + public function query($query, $all = true, $array = false) { |
|
1053 | 1053 | $this->reset(); |
1054 | - if(is_array($all)){ |
|
1054 | + if (is_array($all)) { |
|
1055 | 1055 | $x = explode('?', $query); |
1056 | 1056 | $q = ''; |
1057 | - foreach($x as $k => $v){ |
|
1058 | - if(! empty($v)){ |
|
1057 | + foreach ($x as $k => $v) { |
|
1058 | + if (!empty($v)) { |
|
1059 | 1059 | $q .= $v . (isset($all[$k]) ? $this->escape($all[$k]) : ''); |
1060 | 1060 | } |
1061 | 1061 | } |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | |
1065 | 1065 | $this->query = preg_replace('/\s\s+|\t\t+/', ' ', trim($query)); |
1066 | 1066 | $sqlSELECTQuery = stristr($this->query, 'SELECT'); |
1067 | - $this->logger->info('Execute SQL query ['.$this->query.'], return type: ' . ($array?'ARRAY':'OBJECT') .', return as list: ' . ($all ? 'YES':'NO')); |
|
1067 | + $this->logger->info('Execute SQL query [' . $this->query . '], return type: ' . ($array ? 'ARRAY' : 'OBJECT') . ', return as list: ' . ($all ? 'YES' : 'NO')); |
|
1068 | 1068 | //cache expire time |
1069 | 1069 | $cacheExpire = $this->temporaryCacheTtl; |
1070 | 1070 | |
@@ -1089,17 +1089,17 @@ discard block |
||
1089 | 1089 | //if can use cache feature for this query |
1090 | 1090 | $dbCacheStatus = $cacheEnable && $cacheExpire > 0; |
1091 | 1091 | |
1092 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1092 | + if ($dbCacheStatus && $sqlSELECTQuery) { |
|
1093 | 1093 | $this->logger->info('The cache is enabled for this query, try to get result from cache'); |
1094 | 1094 | $cacheKey = md5($query . $all . $array); |
1095 | 1095 | $cacheInstance = $obj->cache; |
1096 | 1096 | $cacheContent = $cacheInstance->get($cacheKey); |
1097 | 1097 | } |
1098 | - else{ |
|
1098 | + else { |
|
1099 | 1099 | $this->logger->info('The cache is not enabled for this query or is not the SELECT query, get the result directly from real database'); |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if (! $cacheContent && $sqlSELECTQuery){ |
|
1102 | + if (!$cacheContent && $sqlSELECTQuery) { |
|
1103 | 1103 | //for database query execution time |
1104 | 1104 | $benchmarkMarkerKey = md5($query . $all . $array); |
1105 | 1105 | $obj->benchmark->mark('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')'); |
@@ -1109,52 +1109,52 @@ discard block |
||
1109 | 1109 | //get response time for this query |
1110 | 1110 | $responseTime = $obj->benchmark->elapsedTime('DATABASE_QUERY_START(' . $benchmarkMarkerKey . ')', 'DATABASE_QUERY_END(' . $benchmarkMarkerKey . ')'); |
1111 | 1111 | //TODO use the configuration value for the high response time currently is 1 second |
1112 | - if($responseTime >= 1 ){ |
|
1113 | - $this->logger->warning('High response time while processing database query [' .$query. ']. The response time is [' .$responseTime. '] sec.'); |
|
1112 | + if ($responseTime >= 1) { |
|
1113 | + $this->logger->warning('High response time while processing database query [' . $query . ']. The response time is [' . $responseTime . '] sec.'); |
|
1114 | 1114 | } |
1115 | - if ($sqlQuery){ |
|
1115 | + if ($sqlQuery) { |
|
1116 | 1116 | $this->numRows = $sqlQuery->rowCount(); |
1117 | - if (($this->numRows > 0)){ |
|
1117 | + if (($this->numRows > 0)) { |
|
1118 | 1118 | //if need return all result like list of record |
1119 | - if ($all){ |
|
1119 | + if ($all) { |
|
1120 | 1120 | $this->result = ($array == false) ? $sqlQuery->fetchAll(PDO::FETCH_OBJ) : $sqlQuery->fetchAll(PDO::FETCH_ASSOC); |
1121 | 1121 | } |
1122 | - else{ |
|
1122 | + else { |
|
1123 | 1123 | $this->result = ($array == false) ? $sqlQuery->fetch(PDO::FETCH_OBJ) : $sqlQuery->fetch(PDO::FETCH_ASSOC); |
1124 | 1124 | } |
1125 | 1125 | } |
1126 | - if ($dbCacheStatus && $sqlSELECTQuery){ |
|
1127 | - $this->logger->info('Save the result for query [' .$this->query. '] into cache for future use'); |
|
1126 | + if ($dbCacheStatus && $sqlSELECTQuery) { |
|
1127 | + $this->logger->info('Save the result for query [' . $this->query . '] into cache for future use'); |
|
1128 | 1128 | $cacheInstance->set($cacheKey, $this->result, $cacheExpire); |
1129 | 1129 | } |
1130 | 1130 | } |
1131 | - else{ |
|
1131 | + else { |
|
1132 | 1132 | $error = $this->pdo->errorInfo(); |
1133 | 1133 | $this->error = $error[2]; |
1134 | 1134 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
1135 | 1135 | $this->error(); |
1136 | 1136 | } |
1137 | 1137 | } |
1138 | - else if ((! $cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)){ |
|
1138 | + else if ((!$cacheContent && !$sqlSELECTQuery) || ($cacheContent && !$sqlSELECTQuery)) { |
|
1139 | 1139 | $queryStr = $this->pdo->query($this->query); |
1140 | - if($queryStr){ |
|
1140 | + if ($queryStr) { |
|
1141 | 1141 | $this->result = $queryStr->rowCount() >= 0; //to test the result for the query like UPDATE, INSERT, DELETE |
1142 | 1142 | $this->numRows = $queryStr->rowCount(); |
1143 | 1143 | } |
1144 | - if (! $this->result){ |
|
1144 | + if (!$this->result) { |
|
1145 | 1145 | $error = $this->pdo->errorInfo(); |
1146 | 1146 | $this->error = $error[2]; |
1147 | 1147 | $this->logger->fatal('The database query execution got error: ' . stringfy_vars($error)); |
1148 | 1148 | $this->error(); |
1149 | 1149 | } |
1150 | 1150 | } |
1151 | - else{ |
|
1152 | - $this->logger->info('The result for query [' .$this->query. '] already cached use it'); |
|
1151 | + else { |
|
1152 | + $this->logger->info('The result for query [' . $this->query . '] already cached use it'); |
|
1153 | 1153 | $this->result = $cacheContent; |
1154 | 1154 | $this->numRows = count($this->result); |
1155 | 1155 | } |
1156 | 1156 | $this->queryCount++; |
1157 | - if(! $this->result){ |
|
1157 | + if (!$this->result) { |
|
1158 | 1158 | $this->logger->info('No result where found for the query [' . $query . ']'); |
1159 | 1159 | } |
1160 | 1160 | return $this->result; |
@@ -1165,8 +1165,8 @@ discard block |
||
1165 | 1165 | * @param integer $ttl the cache time to live in second |
1166 | 1166 | * @return object the current Database instance |
1167 | 1167 | */ |
1168 | - public function setCache($ttl = 0){ |
|
1169 | - if($ttl > 0){ |
|
1168 | + public function setCache($ttl = 0) { |
|
1169 | + if ($ttl > 0) { |
|
1170 | 1170 | $this->cacheTtl = $ttl; |
1171 | 1171 | $this->temporaryCacheTtl = $ttl; |
1172 | 1172 | } |
@@ -1178,8 +1178,8 @@ discard block |
||
1178 | 1178 | * @param integer $ttl the cache time to live in second |
1179 | 1179 | * @return object the current Database instance |
1180 | 1180 | */ |
1181 | - public function cached($ttl = 0){ |
|
1182 | - if($ttl > 0){ |
|
1181 | + public function cached($ttl = 0) { |
|
1182 | + if ($ttl > 0) { |
|
1183 | 1183 | $this->temporaryCacheTtl = $ttl; |
1184 | 1184 | } |
1185 | 1185 | return $this; |
@@ -1190,8 +1190,8 @@ discard block |
||
1190 | 1190 | * @param mixed $data the data to be escaped |
1191 | 1191 | * @return mixed the data after escaped |
1192 | 1192 | */ |
1193 | - public function escape($data){ |
|
1194 | - if(is_null($data)){ |
|
1193 | + public function escape($data) { |
|
1194 | + if (is_null($data)) { |
|
1195 | 1195 | return null; |
1196 | 1196 | } |
1197 | 1197 | return $this->pdo->quote(trim($data)); |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | * Return the number query executed count for the current request |
1202 | 1202 | * @return int |
1203 | 1203 | */ |
1204 | - public function queryCount(){ |
|
1204 | + public function queryCount() { |
|
1205 | 1205 | return $this->queryCount; |
1206 | 1206 | } |
1207 | 1207 | |
@@ -1209,7 +1209,7 @@ discard block |
||
1209 | 1209 | * Return the current query SQL string |
1210 | 1210 | * @return string |
1211 | 1211 | */ |
1212 | - public function getQuery(){ |
|
1212 | + public function getQuery() { |
|
1213 | 1213 | return $this->query; |
1214 | 1214 | } |
1215 | 1215 | |
@@ -1217,7 +1217,7 @@ discard block |
||
1217 | 1217 | * Return the application database name |
1218 | 1218 | * @return string |
1219 | 1219 | */ |
1220 | - public function getDatabaseName(){ |
|
1220 | + public function getDatabaseName() { |
|
1221 | 1221 | return $this->databaseName; |
1222 | 1222 | } |
1223 | 1223 | |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | * Return the database configuration |
1226 | 1226 | * @return array |
1227 | 1227 | */ |
1228 | - public static function getDatabaseConfiguration(){ |
|
1228 | + public static function getDatabaseConfiguration() { |
|
1229 | 1229 | return static::$config; |
1230 | 1230 | } |
1231 | 1231 | |
@@ -1233,7 +1233,7 @@ discard block |
||
1233 | 1233 | * Return the PDO instance |
1234 | 1234 | * @return PDO |
1235 | 1235 | */ |
1236 | - public function getPdo(){ |
|
1236 | + public function getPdo() { |
|
1237 | 1237 | return $this->pdo; |
1238 | 1238 | } |
1239 | 1239 | |
@@ -1241,7 +1241,7 @@ discard block |
||
1241 | 1241 | * Return the data to be used for insert, update, etc. |
1242 | 1242 | * @return array |
1243 | 1243 | */ |
1244 | - public function getData(){ |
|
1244 | + public function getData() { |
|
1245 | 1245 | return $this->data; |
1246 | 1246 | } |
1247 | 1247 | |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | * @param boolean $escape whether to escape or not the $value |
1253 | 1253 | * @return object the current Database instance |
1254 | 1254 | */ |
1255 | - public function setData($key, $value, $escape = true){ |
|
1255 | + public function setData($key, $value, $escape = true) { |
|
1256 | 1256 | $this->data[$key] = $escape ? $this->escape($value) : $value; |
1257 | 1257 | return $this; |
1258 | 1258 | } |
@@ -1261,7 +1261,7 @@ discard block |
||
1261 | 1261 | /** |
1262 | 1262 | * Reset the database class attributs to the initail values before each query. |
1263 | 1263 | */ |
1264 | - private function reset(){ |
|
1264 | + private function reset() { |
|
1265 | 1265 | $this->select = '*'; |
1266 | 1266 | $this->from = null; |
1267 | 1267 | $this->where = null; |
@@ -1281,7 +1281,7 @@ discard block |
||
1281 | 1281 | /** |
1282 | 1282 | * The class destructor |
1283 | 1283 | */ |
1284 | - function __destruct(){ |
|
1284 | + function __destruct() { |
|
1285 | 1285 | $this->pdo = null; |
1286 | 1286 | } |
1287 | 1287 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Response{ |
|
27 | + class Response { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of request header to send with response |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Construct new response instance |
67 | 67 | */ |
68 | - public function __construct(){ |
|
69 | - $this->_currentUrl = (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' ) |
|
70 | - . (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' ); |
|
68 | + public function __construct() { |
|
69 | + $this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') |
|
70 | + . (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : ''); |
|
71 | 71 | |
72 | 72 | $this->_currentUrlCacheKey = md5($this->_currentUrl); |
73 | 73 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * Get the logger singleton instance |
83 | 83 | * @return Log the logger instance |
84 | 84 | */ |
85 | - private static function getLogger(){ |
|
86 | - if(static::$logger == null){ |
|
87 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
85 | + private static function getLogger() { |
|
86 | + if (static::$logger == null) { |
|
87 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
88 | 88 | static::$logger[0]->setLogger('Library::Response'); |
89 | 89 | } |
90 | 90 | return static::$logger[0]; |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | * @param integer $httpCode the HTTP status code |
96 | 96 | * @param array $headers the additional headers to add to the existing headers list |
97 | 97 | */ |
98 | - public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
98 | + public static function sendHeaders($httpCode = 200, array $headers = array()) { |
|
99 | 99 | set_http_status_header($httpCode); |
100 | 100 | static::setHeaders($headers); |
101 | - if(! headers_sent()){ |
|
102 | - foreach(static::getHeaders() as $key => $value){ |
|
103 | - header($key .': '.$value); |
|
101 | + if (!headers_sent()) { |
|
102 | + foreach (static::getHeaders() as $key => $value) { |
|
103 | + header($key . ': ' . $value); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * Get the list of the headers |
110 | 110 | * @return array the headers list |
111 | 111 | */ |
112 | - public static function getHeaders(){ |
|
112 | + public static function getHeaders() { |
|
113 | 113 | return static::$headers; |
114 | 114 | } |
115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string $name the header name |
119 | 119 | * @return string the header value |
120 | 120 | */ |
121 | - public static function getHeader($name){ |
|
121 | + public static function getHeader($name) { |
|
122 | 122 | return array_key_exists($name, static::$headers) ? static::$headers[$name] : null; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param string $name the header name |
129 | 129 | * @param string $value the header value to be set |
130 | 130 | */ |
131 | - public static function setHeader($name, $value){ |
|
131 | + public static function setHeader($name, $value) { |
|
132 | 132 | static::$headers[$name] = $value; |
133 | 133 | } |
134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param array $headers the list of the headers to set. |
138 | 138 | * Note: this will merge with the existing headers |
139 | 139 | */ |
140 | - public static function setHeaders(array $headers){ |
|
140 | + public static function setHeaders(array $headers) { |
|
141 | 141 | static::$headers = array_merge(static::getHeaders(), $headers); |
142 | 142 | } |
143 | 143 | |
@@ -145,17 +145,17 @@ discard block |
||
145 | 145 | * Redirect user in the specified page |
146 | 146 | * @param string $path the URL or URI to be redirect to |
147 | 147 | */ |
148 | - public static function redirect($path = ''){ |
|
148 | + public static function redirect($path = '') { |
|
149 | 149 | $logger = static::getLogger(); |
150 | 150 | $url = Url::site_url($path); |
151 | - $logger->info('Redirect to URL [' .$url. ']'); |
|
152 | - if(! headers_sent()){ |
|
153 | - header('Location: '.$url); |
|
151 | + $logger->info('Redirect to URL [' . $url . ']'); |
|
152 | + if (!headers_sent()) { |
|
153 | + header('Location: ' . $url); |
|
154 | 154 | exit; |
155 | 155 | } |
156 | - else{ |
|
156 | + else { |
|
157 | 157 | echo '<script> |
158 | - location.href = "'.$url.'"; |
|
158 | + location.href = "'.$url . '"; |
|
159 | 159 | </script>'; |
160 | 160 | } |
161 | 161 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | * @return void|string if $return is true will return the view content otherwise |
169 | 169 | * will display the view content. |
170 | 170 | */ |
171 | - public function render($view, $data = array(), $return = false){ |
|
171 | + public function render($view, $data = array(), $return = false) { |
|
172 | 172 | $logger = static::getLogger(); |
173 | 173 | //convert data to an array |
174 | - $data = ! is_array($data) ? (array) $data : $data; |
|
174 | + $data = !is_array($data) ? (array) $data : $data; |
|
175 | 175 | $view = str_ireplace('.php', '', $view); |
176 | 176 | $view = trim($view, '/\\'); |
177 | 177 | $viewFile = $view . '.php'; |
@@ -180,42 +180,42 @@ discard block |
||
180 | 180 | //super instance |
181 | 181 | $obj = & get_instance(); |
182 | 182 | |
183 | - if(Module::hasModule()){ |
|
183 | + if (Module::hasModule()) { |
|
184 | 184 | //check in module first |
185 | 185 | $logger->debug('Checking the view [' . $view . '] from module list ...'); |
186 | 186 | $mod = null; |
187 | 187 | //check if the request class contains module name |
188 | - if(strpos($view, '/') !== false){ |
|
188 | + if (strpos($view, '/') !== false) { |
|
189 | 189 | $viewPath = explode('/', $view); |
190 | - if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
190 | + if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) { |
|
191 | 191 | $mod = $viewPath[0]; |
192 | 192 | array_shift($viewPath); |
193 | 193 | $view = implode('/', $viewPath); |
194 | 194 | $viewFile = $view . '.php'; |
195 | 195 | } |
196 | 196 | } |
197 | - if(! $mod && !empty($obj->moduleName)){ |
|
197 | + if (!$mod && !empty($obj->moduleName)) { |
|
198 | 198 | $mod = $obj->moduleName; |
199 | 199 | } |
200 | - if($mod){ |
|
200 | + if ($mod) { |
|
201 | 201 | $moduleViewPath = Module::findViewFullPath($view, $mod); |
202 | - if($moduleViewPath){ |
|
202 | + if ($moduleViewPath) { |
|
203 | 203 | $path = $moduleViewPath; |
204 | - $logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
204 | + $logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it'); |
|
205 | 205 | } |
206 | - else{ |
|
207 | - $logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location'); |
|
206 | + else { |
|
207 | + $logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location'); |
|
208 | 208 | } |
209 | 209 | } |
210 | - else{ |
|
210 | + else { |
|
211 | 211 | $logger->info('The current request does not use module using the default location.'); |
212 | 212 | } |
213 | 213 | } |
214 | 214 | $logger->info('The view file path to be loaded is [' . $path . ']'); |
215 | 215 | $found = false; |
216 | - if(file_exists($path)){ |
|
217 | - foreach(get_object_vars($obj) as $key => $value){ |
|
218 | - if(! isset($this->{$key})){ |
|
216 | + if (file_exists($path)) { |
|
217 | + foreach (get_object_vars($obj) as $key => $value) { |
|
218 | + if (!isset($this->{$key})) { |
|
219 | 219 | $this->{$key} = & $obj->{$key}; |
220 | 220 | } |
221 | 221 | } |
@@ -224,39 +224,39 @@ discard block |
||
224 | 224 | //need use require() instead of require_once because can load this view many time |
225 | 225 | require $path; |
226 | 226 | $content = ob_get_clean(); |
227 | - if($return){ |
|
227 | + if ($return) { |
|
228 | 228 | return $content; |
229 | 229 | } |
230 | 230 | $this->_pageRender .= $content; |
231 | 231 | $found = true; |
232 | 232 | } |
233 | - if(! $found){ |
|
234 | - show_error('Unable to find view [' .$view . ']'); |
|
233 | + if (!$found) { |
|
234 | + show_error('Unable to find view [' . $view . ']'); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
239 | 239 | * Send the final page output to user |
240 | 240 | */ |
241 | - public function renderFinalPage(){ |
|
241 | + public function renderFinalPage() { |
|
242 | 242 | $logger = static::getLogger(); |
243 | 243 | $obj = & get_instance(); |
244 | 244 | $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
245 | 245 | $dispatcher = $obj->eventdispatcher; |
246 | 246 | $content = $this->_pageRender; |
247 | - if(! $content){ |
|
247 | + if (!$content) { |
|
248 | 248 | $logger->warning('The final view content is empty.'); |
249 | 249 | return; |
250 | 250 | } |
251 | 251 | //dispatch |
252 | 252 | $event = $dispatcher->dispatch(new Event('FINAL_VIEW_READY', $content, true)); |
253 | - $content = ! empty($event->payload) ? $event->payload : null; |
|
254 | - if(empty($content)){ |
|
253 | + $content = !empty($event->payload) ? $event->payload : null; |
|
254 | + if (empty($content)) { |
|
255 | 255 | $logger->warning('The view content is empty after dispatch to Event Listeners.'); |
256 | 256 | } |
257 | 257 | |
258 | 258 | //check whether need save the page into cache. |
259 | - if($cachePageStatus){ |
|
259 | + if ($cachePageStatus) { |
|
260 | 260 | //current page URL |
261 | 261 | $url = $this->_currentUrl; |
262 | 262 | //Cache view Time to live in second |
@@ -271,14 +271,14 @@ discard block |
||
271 | 271 | |
272 | 272 | //get the cache information to prepare header to send to browser |
273 | 273 | $cacheInfo = $cacheInstance->getInfo($cacheKey); |
274 | - if($cacheInfo){ |
|
274 | + if ($cacheInfo) { |
|
275 | 275 | $lastModified = $cacheInfo['mtime']; |
276 | 276 | $expire = $cacheInfo['expire']; |
277 | 277 | $maxAge = $expire - time(); |
278 | 278 | static::setHeader('Pragma', 'public'); |
279 | 279 | static::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
280 | - static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
281 | - static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
280 | + static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
281 | + static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | $content = str_replace(array('{elapsed_time}', '{memory_usage}'), array($elapsedTime, $memoryUsage), $content); |
290 | 290 | |
291 | 291 | //compress the output if is available |
292 | - if (static::$_canCompressOutput){ |
|
292 | + if (static::$_canCompressOutput) { |
|
293 | 293 | ob_start('ob_gzhandler'); |
294 | 294 | } |
295 | - else{ |
|
295 | + else { |
|
296 | 296 | ob_start(); |
297 | 297 | } |
298 | 298 | static::sendHeaders(200); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | /** |
304 | 304 | * Send the final page output to user if is cached |
305 | 305 | */ |
306 | - public function renderFinalPageFromCache(&$cache){ |
|
306 | + public function renderFinalPageFromCache(&$cache) { |
|
307 | 307 | $logger = static::getLogger(); |
308 | 308 | $url = $this->_currentUrl; |
309 | 309 | //the current page cache key for identification |
@@ -312,25 +312,25 @@ discard block |
||
312 | 312 | $logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...'); |
313 | 313 | //get the cache information to prepare header to send to browser |
314 | 314 | $cacheInfo = $cache->getInfo($pageCacheKey); |
315 | - if($cacheInfo){ |
|
315 | + if ($cacheInfo) { |
|
316 | 316 | $lastModified = $cacheInfo['mtime']; |
317 | 317 | $expire = $cacheInfo['expire']; |
318 | 318 | $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
319 | 319 | static::setHeader('Pragma', 'public'); |
320 | 320 | static::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
321 | - static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
322 | - static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
323 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
321 | + static::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
322 | + static::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
323 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { |
|
324 | 324 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
325 | 325 | static::sendHeaders(304); |
326 | 326 | exit; |
327 | 327 | } |
328 | - else{ |
|
328 | + else { |
|
329 | 329 | $logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser'); |
330 | 330 | static::sendHeaders(200); |
331 | 331 | //get the cache content |
332 | 332 | $content = $cache->get($pageCacheKey); |
333 | - if($content){ |
|
333 | + if ($content) { |
|
334 | 334 | $logger->info('The page content for the URL [' . $url . '] already cached just display it'); |
335 | 335 | //load benchmark class |
336 | 336 | $benchmark = & class_loader('Benchmark'); |
@@ -343,17 +343,17 @@ discard block |
||
343 | 343 | |
344 | 344 | ///display the final output |
345 | 345 | //compress the output if is available |
346 | - if (static::$_canCompressOutput){ |
|
346 | + if (static::$_canCompressOutput) { |
|
347 | 347 | ob_start('ob_gzhandler'); |
348 | 348 | } |
349 | - else{ |
|
349 | + else { |
|
350 | 350 | ob_start(); |
351 | 351 | } |
352 | 352 | echo $content; |
353 | 353 | @ob_end_flush(); |
354 | 354 | exit; |
355 | 355 | } |
356 | - else{ |
|
356 | + else { |
|
357 | 357 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
358 | 358 | $cache->delete($pageCacheKey); |
359 | 359 | } |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * Get the final page to be rendered |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public function getFinalPageRendered(){ |
|
368 | + public function getFinalPageRendered() { |
|
369 | 369 | return $this->_pageRender; |
370 | 370 | } |
371 | 371 | |
@@ -373,14 +373,14 @@ discard block |
||
373 | 373 | * Send the HTTP 404 error if can not found the |
374 | 374 | * routing information for the current request |
375 | 375 | */ |
376 | - public static function send404(){ |
|
376 | + public static function send404() { |
|
377 | 377 | /********* for logs **************/ |
378 | 378 | //can't use $obj = & get_instance() here because the global super object will be available until |
379 | 379 | //the main controller is loaded even for Loader::library('xxxx'); |
380 | 380 | $logger = static::getLogger(); |
381 | - $request =& class_loader('Request', 'classes'); |
|
382 | - $userAgent =& class_loader('Browser'); |
|
383 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
381 | + $request = & class_loader('Request', 'classes'); |
|
382 | + $userAgent = & class_loader('Browser'); |
|
383 | + $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion(); |
|
384 | 384 | |
385 | 385 | //here can't use Loader::functions just include the helper manually |
386 | 386 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
@@ -390,12 +390,12 @@ discard block |
||
390 | 390 | $logger->error($str); |
391 | 391 | /***********************************/ |
392 | 392 | $path = CORE_VIEWS_PATH . '404.php'; |
393 | - if(file_exists($path)){ |
|
393 | + if (file_exists($path)) { |
|
394 | 394 | //compress the output if is available |
395 | - if (static::$_canCompressOutput){ |
|
395 | + if (static::$_canCompressOutput) { |
|
396 | 396 | ob_start('ob_gzhandler'); |
397 | 397 | } |
398 | - else{ |
|
398 | + else { |
|
399 | 399 | ob_start(); |
400 | 400 | } |
401 | 401 | require_once $path; |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | static::sendHeaders(404); |
404 | 404 | echo $output; |
405 | 405 | } |
406 | - else{ |
|
407 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
406 | + else { |
|
407 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
408 | 408 | } |
409 | 409 | } |
410 | 410 | |
@@ -412,14 +412,14 @@ discard block |
||
412 | 412 | * Display the error to user |
413 | 413 | * @param array $data the error information |
414 | 414 | */ |
415 | - public static function sendError(array $data = array()){ |
|
415 | + public static function sendError(array $data = array()) { |
|
416 | 416 | $path = CORE_VIEWS_PATH . 'errors.php'; |
417 | - if(file_exists($path)){ |
|
417 | + if (file_exists($path)) { |
|
418 | 418 | //compress the output if exists |
419 | - if (static::$_canCompressOutput){ |
|
419 | + if (static::$_canCompressOutput) { |
|
420 | 420 | ob_start('ob_gzhandler'); |
421 | 421 | } |
422 | - else{ |
|
422 | + else { |
|
423 | 423 | ob_start(); |
424 | 424 | } |
425 | 425 | extract($data); |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | static::sendHeaders(503); |
429 | 429 | echo $output; |
430 | 430 | } |
431 | - else{ |
|
431 | + else { |
|
432 | 432 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
433 | 433 | set_http_status_header(503); |
434 | 434 | echo 'The error view [' . $path . '] does not exist'; |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
29 | 29 | */ |
30 | - if( !interface_exists('SessionHandlerInterface')){ |
|
30 | + if (!interface_exists('SessionHandlerInterface')) { |
|
31 | 31 | show_error('"SessionHandlerInterface" interface does not exists or is disabled can not use it to handler database session.'); |
32 | 32 | } |
33 | 33 | |
34 | - class DBSessionHandler implements SessionHandlerInterface{ |
|
34 | + class DBSessionHandler implements SessionHandlerInterface { |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * The encryption method to use to encrypt session data in database |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | */ |
83 | 83 | private $logger; |
84 | 84 | |
85 | - public function __construct(){ |
|
86 | - $this->logger =& class_loader('Log', 'classes'); |
|
85 | + public function __construct() { |
|
86 | + $this->logger = & class_loader('Log', 'classes'); |
|
87 | 87 | $this->logger->setLogger('Library::DBSessionHandler'); |
88 | 88 | $this->OBJ = & get_instance(); |
89 | 89 | |
90 | 90 | $secret = get_config('session_secret', false); |
91 | 91 | //try to check if session secret is set and the length is >= SESSION_SECRET_MIN_LENGTH |
92 | - if(! $secret || strlen($secret) < self::SESSION_SECRET_MIN_LENGTH){ |
|
93 | - show_error('Session secret is not set or the length is below to '.self::SESSION_SECRET_MIN_LENGTH.' caracters'); |
|
92 | + if (!$secret || strlen($secret) < self::SESSION_SECRET_MIN_LENGTH) { |
|
93 | + show_error('Session secret is not set or the length is below to ' . self::SESSION_SECRET_MIN_LENGTH . ' caracters'); |
|
94 | 94 | } |
95 | 95 | $this->logger->info('Session secret: ' . $secret); |
96 | 96 | |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | //set model instance name |
102 | 102 | $this->modelInstanceName = $this->OBJ->dbsessionhanlderinstance; |
103 | 103 | |
104 | - if(! $this->modelInstanceName instanceof DBSessionHandlerModel){ |
|
105 | - show_error('To use database session handler, your class model "'.$modelName.'" need extends "DBSessionHandlerModel"'); |
|
104 | + if (!$this->modelInstanceName instanceof DBSessionHandlerModel) { |
|
105 | + show_error('To use database session handler, your class model "' . $modelName . '" need extends "DBSessionHandlerModel"'); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | //set session tables columns |
109 | 109 | $this->sessionTableColumns = $this->modelInstanceName->getSessionTableColumns(); |
110 | 110 | |
111 | - if(empty($this->sessionTableColumns)){ |
|
111 | + if (empty($this->sessionTableColumns)) { |
|
112 | 112 | show_error('The session handler is "database" but the table columns not set'); |
113 | 113 | } |
114 | 114 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param string $sessionName the session name |
131 | 131 | * @return boolean |
132 | 132 | */ |
133 | - public function open($savePath, $sessionName){ |
|
133 | + public function open($savePath, $sessionName) { |
|
134 | 134 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
135 | 135 | return true; |
136 | 136 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * Close the session |
140 | 140 | * @return boolean |
141 | 141 | */ |
142 | - public function close(){ |
|
142 | + public function close() { |
|
143 | 143 | $this->logger->debug('Closing database session handler'); |
144 | 144 | return true; |
145 | 145 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param string $sid the session id to use |
150 | 150 | * @return mixed the session data in serialiaze format |
151 | 151 | */ |
152 | - public function read($sid){ |
|
152 | + public function read($sid) { |
|
153 | 153 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
154 | 154 | $instance = $this->modelInstanceName; |
155 | 155 | $columns = $this->sessionTableColumns; |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | $keyValue = $instance->getKeyValue(); |
159 | 159 | $host = @gethostbyaddr($ip) or null; |
160 | 160 | Loader::library('Browser'); |
161 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
161 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
162 | 162 | |
163 | 163 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
164 | - if($data && isset($data->{$columns['sdata']})){ |
|
164 | + if ($data && isset($data->{$columns['sdata']})) { |
|
165 | 165 | //checking inactivity |
166 | 166 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
167 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
167 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
168 | 168 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
169 | 169 | $this->destroy($sid); |
170 | 170 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param mixed $data the session data to save in serialize format |
182 | 182 | * @return boolean |
183 | 183 | */ |
184 | - public function write($sid, $data){ |
|
184 | + public function write($sid, $data) { |
|
185 | 185 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
186 | 186 | $instance = $this->modelInstanceName; |
187 | 187 | $columns = $this->sessionTableColumns; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $keyValue = $instance->getKeyValue(); |
192 | 192 | $host = @gethostbyaddr($ip) or null; |
193 | 193 | Loader::library('Browser'); |
194 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
194 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
195 | 195 | $data = $this->encode($data); |
196 | 196 | $params = array( |
197 | 197 | $columns['sid'] => $sid, |
@@ -204,13 +204,13 @@ discard block |
||
204 | 204 | ); |
205 | 205 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
206 | 206 | $exists = $instance->get($sid); |
207 | - if($exists){ |
|
207 | + if ($exists) { |
|
208 | 208 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
209 | 209 | //update |
210 | 210 | unset($params[$columns['sid']]); |
211 | 211 | $instance->update($sid, $params); |
212 | 212 | } |
213 | - else{ |
|
213 | + else { |
|
214 | 214 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
215 | 215 | $instance->insert($params); |
216 | 216 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @param string $sid the session id value |
224 | 224 | * @return boolean |
225 | 225 | */ |
226 | - public function destroy($sid){ |
|
226 | + public function destroy($sid) { |
|
227 | 227 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
228 | 228 | $instance = $this->modelInstanceName; |
229 | 229 | $instance->delete($sid); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @param ineteger $maxLifetime the max lifetime |
236 | 236 | * @return boolean |
237 | 237 | */ |
238 | - public function gc($maxLifetime){ |
|
238 | + public function gc($maxLifetime) { |
|
239 | 239 | $instance = $this->modelInstanceName; |
240 | 240 | $time = time() - $maxLifetime; |
241 | 241 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | * @param mixed $data the data to decode |
249 | 249 | * @return mixed the decoded data |
250 | 250 | */ |
251 | - public function decode($data){ |
|
251 | + public function decode($data) { |
|
252 | 252 | $key = base64_decode($this->sessionSecret); |
253 | 253 | $data = base64_decode($data); |
254 | 254 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->iv); |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | * @param mixed $data the session data to encode |
261 | 261 | * @return mixed the encoded session data |
262 | 262 | */ |
263 | - public function encode($data){ |
|
263 | + public function encode($data) { |
|
264 | 264 | $key = base64_decode($this->sessionSecret); |
265 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->iv); |
|
265 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->iv); |
|
266 | 266 | $output = base64_encode($dataEncrypted); |
267 | 267 | return $output; |
268 | 268 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Loader{ |
|
26 | + class Loader { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * List of loaded resources |
@@ -38,85 +38,85 @@ discard block |
||
38 | 38 | private static $logger; |
39 | 39 | |
40 | 40 | |
41 | - public function __construct(){ |
|
41 | + public function __construct() { |
|
42 | 42 | //add the resources already loaded during application bootstrap |
43 | 43 | //in the list to prevent duplicate or loading the resources again. |
44 | 44 | static::$loaded = class_loaded(); |
45 | 45 | |
46 | 46 | $autoloads = array(); |
47 | 47 | //loading of the resources in autoload.php configuration file |
48 | - if(file_exists(CONFIG_PATH . 'autoload.php')){ |
|
48 | + if (file_exists(CONFIG_PATH . 'autoload.php')) { |
|
49 | 49 | require_once CONFIG_PATH . 'autoload.php'; |
50 | - if(! empty($autoload) && is_array($autoload)){ |
|
50 | + if (!empty($autoload) && is_array($autoload)) { |
|
51 | 51 | $autoloads = $autoload; |
52 | 52 | unset($autoload); |
53 | 53 | } |
54 | - else{ |
|
54 | + else { |
|
55 | 55 | show_error('No autoload configuration found in autoload.php'); |
56 | 56 | } |
57 | 57 | } |
58 | 58 | //loading autoload configuration for modules |
59 | 59 | $modulesAutoloads = Module::getModulesAutoloadConfig(); |
60 | - if($modulesAutoloads && is_array($modulesAutoloads)){ |
|
60 | + if ($modulesAutoloads && is_array($modulesAutoloads)) { |
|
61 | 61 | //libraries autoload |
62 | - if(! empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])){ |
|
62 | + if (!empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])) { |
|
63 | 63 | $autoloads['libraries'] = array_merge($autoloads['libraries'], $modulesAutoloads['libraries']); |
64 | 64 | } |
65 | 65 | //config autoload |
66 | - if(! empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])){ |
|
66 | + if (!empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])) { |
|
67 | 67 | $autoloads['config'] = array_merge($autoloads['config'], $modulesAutoloads['config']); |
68 | 68 | } |
69 | 69 | //models autoload |
70 | - if(! empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])){ |
|
70 | + if (!empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])) { |
|
71 | 71 | $autoloads['models'] = array_merge($autoloads['models'], $modulesAutoloads['models']); |
72 | 72 | } |
73 | 73 | //functions autoload |
74 | - if(! empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])){ |
|
74 | + if (!empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])) { |
|
75 | 75 | $autoloads['functions'] = array_merge($autoloads['functions'], $modulesAutoloads['functions']); |
76 | 76 | } |
77 | 77 | //languages autoload |
78 | - if(! empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])){ |
|
78 | + if (!empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])) { |
|
79 | 79 | $autoloads['languages'] = array_merge($autoloads['languages'], $modulesAutoloads['languages']); |
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | 83 | //config autoload |
84 | - if(! empty($autoloads['config']) && is_array($autoloads['config'])){ |
|
85 | - foreach($autoloads['config'] as $c){ |
|
84 | + if (!empty($autoloads['config']) && is_array($autoloads['config'])) { |
|
85 | + foreach ($autoloads['config'] as $c) { |
|
86 | 86 | Loader::config($c); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | 90 | //languages autoload |
91 | - if(! empty($autoloads['languages']) && is_array($autoloads['languages'])){ |
|
92 | - foreach($autoloads['languages'] as $language){ |
|
91 | + if (!empty($autoloads['languages']) && is_array($autoloads['languages'])) { |
|
92 | + foreach ($autoloads['languages'] as $language) { |
|
93 | 93 | Loader::lang($language); |
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | 97 | //libraries autoload |
98 | - if(! empty($autoloads['libraries']) && is_array($autoloads['libraries'])){ |
|
99 | - foreach($autoloads['libraries'] as $library){ |
|
98 | + if (!empty($autoloads['libraries']) && is_array($autoloads['libraries'])) { |
|
99 | + foreach ($autoloads['libraries'] as $library) { |
|
100 | 100 | Loader::library($library); |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | 104 | //before load models check if database library is loaded and then load model library |
105 | 105 | //if Database is loaded load the required library |
106 | - if(isset(static::$loaded['database']) || ! empty($autoloads['models'])){ |
|
106 | + if (isset(static::$loaded['database']) || !empty($autoloads['models'])) { |
|
107 | 107 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
108 | 108 | } |
109 | 109 | |
110 | 110 | //models autoload |
111 | - if(! empty($autoloads['models']) && is_array($autoloads['models'])){ |
|
112 | - foreach($autoloads['models'] as $model){ |
|
111 | + if (!empty($autoloads['models']) && is_array($autoloads['models'])) { |
|
112 | + foreach ($autoloads['models'] as $model) { |
|
113 | 113 | Loader::model($model); |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | 117 | //functions autoload |
118 | - if(! empty($autoloads['functions']) && is_array($autoloads['functions'])){ |
|
119 | - foreach($autoloads['functions'] as $function){ |
|
118 | + if (!empty($autoloads['functions']) && is_array($autoloads['functions'])) { |
|
119 | + foreach ($autoloads['functions'] as $function) { |
|
120 | 120 | Loader::functions($function); |
121 | 121 | } |
122 | 122 | } |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * Get the logger singleton instance |
128 | 128 | * @return Log the logger instance |
129 | 129 | */ |
130 | - private static function getLogger(){ |
|
131 | - if(static::$logger == null){ |
|
132 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
130 | + private static function getLogger() { |
|
131 | + if (static::$logger == null) { |
|
132 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
133 | 133 | static::$logger[0]->setLogger('Library::Loader'); |
134 | 134 | } |
135 | 135 | return static::$logger[0]; |
@@ -143,25 +143,25 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - public static function model($class, $instance = null){ |
|
146 | + public static function model($class, $instance = null) { |
|
147 | 147 | $logger = static::getLogger(); |
148 | 148 | $class = str_ireplace('.php', '', $class); |
149 | 149 | $class = trim($class, '/\\'); |
150 | - $file = ucfirst($class).'.php'; |
|
150 | + $file = ucfirst($class) . '.php'; |
|
151 | 151 | $logger->debug('Loading model [' . $class . '] ...'); |
152 | - if(! $instance){ |
|
152 | + if (!$instance) { |
|
153 | 153 | //for module |
154 | - if(strpos($class, '/') !== false){ |
|
154 | + if (strpos($class, '/') !== false) { |
|
155 | 155 | $path = explode('/', $class); |
156 | - if(isset($path[1])){ |
|
156 | + if (isset($path[1])) { |
|
157 | 157 | $instance = strtolower($path[1]); |
158 | 158 | } |
159 | 159 | } |
160 | - else{ |
|
160 | + else { |
|
161 | 161 | $instance = strtolower($class); |
162 | 162 | } |
163 | 163 | } |
164 | - if(isset(static::$loaded[$instance])){ |
|
164 | + if (isset(static::$loaded[$instance])) { |
|
165 | 165 | $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
166 | 166 | return; |
167 | 167 | } |
@@ -171,43 +171,43 @@ discard block |
||
171 | 171 | $searchModuleName = null; |
172 | 172 | $obj = & get_instance(); |
173 | 173 | //check if the request class contains module name |
174 | - if(strpos($class, '/') !== false){ |
|
174 | + if (strpos($class, '/') !== false) { |
|
175 | 175 | $path = explode('/', $class); |
176 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
176 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
177 | 177 | $searchModuleName = $path[0]; |
178 | 178 | $class = ucfirst($path[1]); |
179 | 179 | } |
180 | 180 | } |
181 | - else{ |
|
181 | + else { |
|
182 | 182 | $class = ucfirst($class); |
183 | 183 | } |
184 | 184 | |
185 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
185 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
186 | 186 | $searchModuleName = $obj->moduleName; |
187 | 187 | } |
188 | 188 | $moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName); |
189 | - if($moduleModelFilePath){ |
|
190 | - $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
189 | + if ($moduleModelFilePath) { |
|
190 | + $logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
191 | 191 | $classFilePath = $moduleModelFilePath; |
192 | 192 | } |
193 | - else{ |
|
193 | + else { |
|
194 | 194 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
195 | 195 | } |
196 | 196 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
197 | - if(file_exists($classFilePath)){ |
|
197 | + if (file_exists($classFilePath)) { |
|
198 | 198 | require_once $classFilePath; |
199 | - if(class_exists($class)){ |
|
199 | + if (class_exists($class)) { |
|
200 | 200 | $c = new $class(); |
201 | 201 | $obj = & get_instance(); |
202 | 202 | $obj->{$instance} = $c; |
203 | 203 | static::$loaded[$instance] = $class; |
204 | 204 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
205 | 205 | } |
206 | - else{ |
|
207 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
206 | + else { |
|
207 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
208 | 208 | } |
209 | 209 | } |
210 | - else{ |
|
210 | + else { |
|
211 | 211 | show_error('Unable to find the model [' . $class . ']'); |
212 | 212 | } |
213 | 213 | } |
@@ -222,31 +222,31 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return void |
224 | 224 | */ |
225 | - public static function library($class, $instance = null, array $params = array()){ |
|
225 | + public static function library($class, $instance = null, array $params = array()) { |
|
226 | 226 | $logger = static::getLogger(); |
227 | 227 | $class = str_ireplace('.php', '', $class); |
228 | 228 | $class = trim($class, '/\\'); |
229 | - $file = ucfirst($class) .'.php'; |
|
229 | + $file = ucfirst($class) . '.php'; |
|
230 | 230 | $logger->debug('Loading library [' . $class . '] ...'); |
231 | - if(! $instance){ |
|
231 | + if (!$instance) { |
|
232 | 232 | //for module |
233 | - if(strpos($class, '/') !== false){ |
|
233 | + if (strpos($class, '/') !== false) { |
|
234 | 234 | $path = explode('/', $class); |
235 | - if(isset($path[1])){ |
|
235 | + if (isset($path[1])) { |
|
236 | 236 | $instance = strtolower($path[1]); |
237 | 237 | } |
238 | 238 | } |
239 | - else{ |
|
239 | + else { |
|
240 | 240 | $instance = strtolower($class); |
241 | 241 | } |
242 | 242 | } |
243 | - if(isset(static::$loaded[$instance])){ |
|
243 | + if (isset(static::$loaded[$instance])) { |
|
244 | 244 | $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
245 | 245 | return; |
246 | 246 | } |
247 | 247 | $obj = & get_instance(); |
248 | 248 | //TODO for Database library |
249 | - if(strtolower($class) == 'database'){ |
|
249 | + if (strtolower($class) == 'database') { |
|
250 | 250 | $logger->info('This is the Database library ...'); |
251 | 251 | $dbInstance = & class_loader('Database', 'classes', $params); |
252 | 252 | $obj->{$instance} = $dbInstance; |
@@ -257,45 +257,45 @@ discard block |
||
257 | 257 | $libraryFilePath = null; |
258 | 258 | $isSystem = false; |
259 | 259 | $logger->debug('Check if this is a system library ...'); |
260 | - if(file_exists(CORE_LIBRARY_PATH . $file)){ |
|
260 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
261 | 261 | $isSystem = true; |
262 | 262 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
263 | 263 | $class = ucfirst($class); |
264 | 264 | $logger->info('This library is a system library'); |
265 | 265 | } |
266 | - else{ |
|
266 | + else { |
|
267 | 267 | $logger->info('This library is not a system library'); |
268 | 268 | //first check if this library is in the module |
269 | 269 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
270 | 270 | $searchModuleName = null; |
271 | 271 | //check if the request class contains module name |
272 | - if(strpos($class, '/') !== false){ |
|
272 | + if (strpos($class, '/') !== false) { |
|
273 | 273 | $path = explode('/', $class); |
274 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
274 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
275 | 275 | $searchModuleName = $path[0]; |
276 | 276 | $class = ucfirst($path[1]); |
277 | 277 | } |
278 | 278 | } |
279 | - else{ |
|
279 | + else { |
|
280 | 280 | $class = ucfirst($class); |
281 | 281 | } |
282 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
282 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
283 | 283 | $searchModuleName = $obj->moduleName; |
284 | 284 | } |
285 | 285 | $moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName); |
286 | - if($moduleLibraryPath){ |
|
287 | - $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
286 | + if ($moduleLibraryPath) { |
|
287 | + $logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
288 | 288 | $libraryFilePath = $moduleLibraryPath; |
289 | 289 | } |
290 | - else{ |
|
290 | + else { |
|
291 | 291 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
292 | 292 | } |
293 | 293 | } |
294 | - if(! $libraryFilePath){ |
|
294 | + if (!$libraryFilePath) { |
|
295 | 295 | $searchDir = array(LIBRARY_PATH); |
296 | - foreach($searchDir as $dir){ |
|
296 | + foreach ($searchDir as $dir) { |
|
297 | 297 | $filePath = $dir . $file; |
298 | - if(file_exists($filePath)){ |
|
298 | + if (file_exists($filePath)) { |
|
299 | 299 | $libraryFilePath = $filePath; |
300 | 300 | //is already found not to continue |
301 | 301 | break; |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | } |
304 | 304 | } |
305 | 305 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
306 | - if($libraryFilePath){ |
|
306 | + if ($libraryFilePath) { |
|
307 | 307 | require_once $libraryFilePath; |
308 | - if(class_exists($class)){ |
|
308 | + if (class_exists($class)) { |
|
309 | 309 | $c = $params ? new $class($params) : new $class(); |
310 | 310 | $obj = & get_instance(); |
311 | 311 | $obj->{$instance} = $c; |
312 | 312 | static::$loaded[$instance] = $class; |
313 | 313 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
314 | 314 | } |
315 | - else{ |
|
316 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
315 | + else { |
|
316 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
317 | 317 | } |
318 | 318 | } |
319 | - else{ |
|
319 | + else { |
|
320 | 320 | show_error('Unable to find library class [' . $class . ']'); |
321 | 321 | } |
322 | 322 | } |
@@ -328,14 +328,14 @@ discard block |
||
328 | 328 | * |
329 | 329 | * @return void |
330 | 330 | */ |
331 | - public static function functions($function){ |
|
331 | + public static function functions($function) { |
|
332 | 332 | $logger = static::getLogger(); |
333 | 333 | $function = str_ireplace('.php', '', $function); |
334 | 334 | $function = trim($function, '/\\'); |
335 | 335 | $function = str_ireplace('function_', '', $function); |
336 | - $file = 'function_'.$function.'.php'; |
|
336 | + $file = 'function_' . $function . '.php'; |
|
337 | 337 | $logger->debug('Loading helper [' . $function . '] ...'); |
338 | - if(isset(static::$loaded['function_' . $function])){ |
|
338 | + if (isset(static::$loaded['function_' . $function])) { |
|
339 | 339 | $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
340 | 340 | return; |
341 | 341 | } |
@@ -345,30 +345,30 @@ discard block |
||
345 | 345 | $searchModuleName = null; |
346 | 346 | $obj = & get_instance(); |
347 | 347 | //check if the request class contains module name |
348 | - if(strpos($function, '/') !== false){ |
|
348 | + if (strpos($function, '/') !== false) { |
|
349 | 349 | $path = explode('/', $function); |
350 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
350 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
351 | 351 | $searchModuleName = $path[0]; |
352 | 352 | $function = 'function_' . $path[1] . '.php'; |
353 | - $file = $path[0] . DS . 'function_'.$function.'.php'; |
|
353 | + $file = $path[0] . DS . 'function_' . $function . '.php'; |
|
354 | 354 | } |
355 | 355 | } |
356 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
356 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
357 | 357 | $searchModuleName = $obj->moduleName; |
358 | 358 | } |
359 | 359 | $moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName); |
360 | - if($moduleFunctionPath){ |
|
361 | - $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
360 | + if ($moduleFunctionPath) { |
|
361 | + $logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
362 | 362 | $functionFilePath = $moduleFunctionPath; |
363 | 363 | } |
364 | - else{ |
|
364 | + else { |
|
365 | 365 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
366 | 366 | } |
367 | - if(! $functionFilePath){ |
|
367 | + if (!$functionFilePath) { |
|
368 | 368 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
369 | - foreach($searchDir as $dir){ |
|
369 | + foreach ($searchDir as $dir) { |
|
370 | 370 | $filePath = $dir . $file; |
371 | - if(file_exists($filePath)){ |
|
371 | + if (file_exists($filePath)) { |
|
372 | 372 | $functionFilePath = $filePath; |
373 | 373 | //is already found not to continue |
374 | 374 | break; |
@@ -376,12 +376,12 @@ discard block |
||
376 | 376 | } |
377 | 377 | } |
378 | 378 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
379 | - if($functionFilePath){ |
|
379 | + if ($functionFilePath) { |
|
380 | 380 | require_once $functionFilePath; |
381 | 381 | static::$loaded['function_' . $function] = $functionFilePath; |
382 | 382 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
383 | 383 | } |
384 | - else{ |
|
384 | + else { |
|
385 | 385 | show_error('Unable to find helper file [' . $file . ']'); |
386 | 386 | } |
387 | 387 | } |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | * |
394 | 394 | * @return void |
395 | 395 | */ |
396 | - public static function config($filename){ |
|
396 | + public static function config($filename) { |
|
397 | 397 | $logger = static::getLogger(); |
398 | 398 | $filename = str_ireplace('.php', '', $filename); |
399 | 399 | $filename = trim($filename, '/\\'); |
400 | 400 | $filename = str_ireplace('config_', '', $filename); |
401 | - $file = 'config_'.$filename.'.php'; |
|
401 | + $file = 'config_' . $filename . '.php'; |
|
402 | 402 | $logger->debug('Loading configuration [' . $filename . '] ...'); |
403 | - if(isset(static::$loaded['config_' . $filename])){ |
|
403 | + if (isset(static::$loaded['config_' . $filename])) { |
|
404 | 404 | $logger->info('Configuration [' . $path . '] already loaded no need to load it again, cost in performance'); |
405 | 405 | return; |
406 | 406 | } |
@@ -410,37 +410,37 @@ discard block |
||
410 | 410 | $searchModuleName = null; |
411 | 411 | $obj = & get_instance(); |
412 | 412 | //check if the request class contains module name |
413 | - if(strpos($filename, '/') !== false){ |
|
413 | + if (strpos($filename, '/') !== false) { |
|
414 | 414 | $path = explode('/', $filename); |
415 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
415 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
416 | 416 | $searchModuleName = $path[0]; |
417 | 417 | $filename = $path[1] . '.php'; |
418 | - $file = $path[0] . DS .$filename; |
|
418 | + $file = $path[0] . DS . $filename; |
|
419 | 419 | } |
420 | 420 | } |
421 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
421 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
422 | 422 | $searchModuleName = $obj->moduleName; |
423 | 423 | } |
424 | 424 | $moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName); |
425 | - if($moduleConfigPath){ |
|
426 | - $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
425 | + if ($moduleConfigPath) { |
|
426 | + $logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
427 | 427 | $configFilePath = $moduleConfigPath; |
428 | 428 | } |
429 | - else{ |
|
429 | + else { |
|
430 | 430 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
431 | 431 | } |
432 | 432 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
433 | - if(file_exists($configFilePath)){ |
|
433 | + if (file_exists($configFilePath)) { |
|
434 | 434 | require_once $configFilePath; |
435 | - if(! empty($config) && is_array($config)){ |
|
435 | + if (!empty($config) && is_array($config)) { |
|
436 | 436 | Config::setAll($config); |
437 | 437 | } |
438 | - else{ |
|
439 | - show_error('No configuration found in ['. $configFilePath . ']'); |
|
438 | + else { |
|
439 | + show_error('No configuration found in [' . $configFilePath . ']'); |
|
440 | 440 | } |
441 | 441 | } |
442 | - else{ |
|
443 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
442 | + else { |
|
443 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
444 | 444 | } |
445 | 445 | static::$loaded['config_' . $filename] = $configFilePath; |
446 | 446 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
@@ -456,14 +456,14 @@ discard block |
||
456 | 456 | * |
457 | 457 | * @return void |
458 | 458 | */ |
459 | - public static function lang($language){ |
|
459 | + public static function lang($language) { |
|
460 | 460 | $logger = static::getLogger(); |
461 | 461 | $language = str_ireplace('.php', '', $language); |
462 | 462 | $language = trim($language, '/\\'); |
463 | 463 | $language = str_ireplace('lang_', '', $language); |
464 | - $file = 'lang_'.$language.'.php'; |
|
464 | + $file = 'lang_' . $language . '.php'; |
|
465 | 465 | $logger->debug('Loading language [' . $language . '] ...'); |
466 | - if(isset(static::$loaded['lang_' . $language])){ |
|
466 | + if (isset(static::$loaded['lang_' . $language])) { |
|
467 | 467 | $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
468 | 468 | return; |
469 | 469 | } |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | $cfgKey = get_config('language_cookie_name'); |
474 | 474 | $objCookie = & class_loader('Cookie'); |
475 | 475 | $cookieLang = $objCookie->get($cfgKey); |
476 | - if($cookieLang){ |
|
476 | + if ($cookieLang) { |
|
477 | 477 | $appLang = $cookieLang; |
478 | 478 | } |
479 | 479 | $languageFilePath = null; |
@@ -482,30 +482,30 @@ discard block |
||
482 | 482 | $searchModuleName = null; |
483 | 483 | $obj = & get_instance(); |
484 | 484 | //check if the request class contains module name |
485 | - if(strpos($language, '/') !== false){ |
|
485 | + if (strpos($language, '/') !== false) { |
|
486 | 486 | $path = explode('/', $language); |
487 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
487 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
488 | 488 | $searchModuleName = $path[0]; |
489 | 489 | $language = 'lang_' . $path[1] . '.php'; |
490 | - $file = $path[0] . DS .$language; |
|
490 | + $file = $path[0] . DS . $language; |
|
491 | 491 | } |
492 | 492 | } |
493 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
493 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
494 | 494 | $searchModuleName = $obj->moduleName; |
495 | 495 | } |
496 | 496 | $moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang); |
497 | - if($moduleLanguagePath){ |
|
498 | - $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
497 | + if ($moduleLanguagePath) { |
|
498 | + $logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
499 | 499 | $languageFilePath = $moduleLanguagePath; |
500 | 500 | } |
501 | - else{ |
|
501 | + else { |
|
502 | 502 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
503 | 503 | } |
504 | - if(! $languageFilePath){ |
|
504 | + if (!$languageFilePath) { |
|
505 | 505 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
506 | - foreach($searchDir as $dir){ |
|
506 | + foreach ($searchDir as $dir) { |
|
507 | 507 | $filePath = $dir . $appLang . DS . $file; |
508 | - if(file_exists($filePath)){ |
|
508 | + if (file_exists($filePath)) { |
|
509 | 509 | $languageFilePath = $filePath; |
510 | 510 | //is already found not to continue |
511 | 511 | break; |
@@ -513,23 +513,23 @@ discard block |
||
513 | 513 | } |
514 | 514 | } |
515 | 515 | $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
516 | - if($languageFilePath){ |
|
516 | + if ($languageFilePath) { |
|
517 | 517 | require_once $languageFilePath; |
518 | - if(! empty($lang) && is_array($lang)){ |
|
519 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
518 | + if (!empty($lang) && is_array($lang)) { |
|
519 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
520 | 520 | //Note: may be here the class 'Lang' not yet loaded |
521 | - $langObj =& class_loader('Lang', 'classes'); |
|
521 | + $langObj = & class_loader('Lang', 'classes'); |
|
522 | 522 | $langObj->addLangMessages($lang); |
523 | 523 | //free the memory |
524 | 524 | unset($lang); |
525 | 525 | } |
526 | - else{ |
|
526 | + else { |
|
527 | 527 | show_error('No language messages found in [' . $languageFilePath . ']'); |
528 | 528 | } |
529 | 529 | static::$loaded['lang_' . $language] = $languageFilePath; |
530 | 530 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
531 | 531 | } |
532 | - else{ |
|
532 | + else { |
|
533 | 533 | show_error('Unable to find language file [' . $file . ']'); |
534 | 534 | } |
535 | 535 | } |