@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | //put the first letter of class to upper case |
54 | 54 | $class = ucfirst($class); |
55 | 55 | static $classes = array(); |
56 | - if(isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log'){ |
|
56 | + if (isset($classes[$class]) /*hack for duplicate log Logger name*/ && $class != 'Log') { |
|
57 | 57 | return $classes[$class]; |
58 | 58 | } |
59 | 59 | $found = false; |
60 | 60 | foreach (array(ROOT_PATH, CORE_PATH) as $path) { |
61 | 61 | $file = $path . $dir . '/' . $class . '.php'; |
62 | - if(file_exists($file)){ |
|
63 | - if(class_exists($class, false) == false){ |
|
62 | + if (file_exists($file)) { |
|
63 | + if (class_exists($class, false) == false) { |
|
64 | 64 | require_once $file; |
65 | 65 | } |
66 | 66 | //already found |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | break; |
69 | 69 | } |
70 | 70 | } |
71 | - if(! $found){ |
|
71 | + if (!$found) { |
|
72 | 72 | //can't use show_error() at this time because some dependencies not yet loaded |
73 | 73 | set_http_status_header(503); |
74 | 74 | echo 'Cannot find the class [' . $class . ']'; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | /* |
79 | 79 | TODO use the best method to get the Log instance |
80 | 80 | */ |
81 | - if($class == 'Log'){ |
|
81 | + if ($class == 'Log') { |
|
82 | 82 | //can't use the instruction like "return new Log()" |
83 | 83 | //because we need return the reference instance of the loaded class. |
84 | 84 | $log = new Log(); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function & class_loaded($class = null){ |
104 | 104 | static $list = array(); |
105 | - if($class != null){ |
|
105 | + if ($class != null) { |
|
106 | 106 | $list[strtolower($class)] = $class; |
107 | 107 | } |
108 | 108 | return $list; |
@@ -117,22 +117,22 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function & load_configurations(array $overwrite_values = array()){ |
119 | 119 | static $config; |
120 | - if(empty($config)){ |
|
120 | + if (empty($config)) { |
|
121 | 121 | $file = CONFIG_PATH . 'config.php'; |
122 | 122 | $found = false; |
123 | - if(file_exists($file)){ |
|
123 | + if (file_exists($file)) { |
|
124 | 124 | require_once $file; |
125 | 125 | $found = true; |
126 | 126 | } |
127 | - if(! $found){ |
|
127 | + if (!$found) { |
|
128 | 128 | set_http_status_header(503); |
129 | 129 | echo 'Unable to find the configuration file [' . $file . ']'; |
130 | 130 | exit(1); |
131 | 131 | } |
132 | 132 | |
133 | - if(! isset($config) || !is_array($config)){ |
|
133 | + if (!isset($config) || !is_array($config)) { |
|
134 | 134 | set_http_status_header(503); |
135 | - echo 'No configuration found in file [' . $file . ']'; |
|
135 | + echo 'No configuration found in file [' . $file . ']'; |
|
136 | 136 | exit(1); |
137 | 137 | } |
138 | 138 | } |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return mixed the config value |
152 | 152 | */ |
153 | - function get_config($key, $default = null){ |
|
153 | + function get_config($key, $default = null) { |
|
154 | 154 | static $cfg; |
155 | - if(empty($cfg)){ |
|
155 | + if (empty($cfg)) { |
|
156 | 156 | $cfg[0] = & load_configurations(); |
157 | 157 | } |
158 | 158 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @codeCoverageIgnore |
168 | 168 | */ |
169 | - function save_to_log($level, $message, $logger = null){ |
|
170 | - $log =& class_loader('Log', 'classes'); |
|
171 | - if($logger){ |
|
169 | + function save_to_log($level, $message, $logger = null) { |
|
170 | + $log = & class_loader('Log', 'classes'); |
|
171 | + if ($logger) { |
|
172 | 172 | $log->setLogger($logger); |
173 | 173 | } |
174 | 174 | $log->writeLog($message, $level); |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @codeCoverageIgnore |
183 | 183 | */ |
184 | - function set_http_status_header($code = 200, $text = null){ |
|
185 | - if(! $code || !is_numeric($code)){ |
|
184 | + function set_http_status_header($code = 200, $text = null) { |
|
185 | + if (!$code || !is_numeric($code)) { |
|
186 | 186 | show_error('HTTP status code must be an integer'); |
187 | 187 | } |
188 | - if(empty($text)){ |
|
188 | + if (empty($text)) { |
|
189 | 189 | $code = abs($code); |
190 | 190 | $http_status = array( |
191 | 191 | 100 => 'Continue', |
@@ -234,18 +234,18 @@ discard block |
||
234 | 234 | 504 => 'Gateway Timeout', |
235 | 235 | 505 => 'HTTP Version Not Supported', |
236 | 236 | ); |
237 | - if(isset($http_status[$code])){ |
|
237 | + if (isset($http_status[$code])) { |
|
238 | 238 | $text = $http_status[$code]; |
239 | 239 | } |
240 | - else{ |
|
240 | + else { |
|
241 | 241 | show_error('No HTTP status text found for your code please check it.'); |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | - if(strpos(php_sapi_name(), 'cgi') === 0){ |
|
245 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
246 | 246 | header('Status: ' . $code . ' ' . $text, TRUE); |
247 | 247 | } |
248 | - else{ |
|
248 | + else { |
|
249 | 249 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
250 | 250 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
251 | 251 | } |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | * |
261 | 261 | * @codeCoverageIgnore |
262 | 262 | */ |
263 | - function show_error($msg, $title = 'error', $logging = true){ |
|
263 | + function show_error($msg, $title = 'error', $logging = true) { |
|
264 | 264 | $title = strtoupper($title); |
265 | 265 | $data['error'] = $msg; |
266 | 266 | $data['title'] = $title; |
267 | - if($logging){ |
|
268 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
267 | + if ($logging) { |
|
268 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
269 | 269 | } |
270 | 270 | $response = & class_loader('Response', 'classes'); |
271 | 271 | $response->sendError($data); |
@@ -279,18 +279,18 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return boolean true if the web server uses the https protocol, false if not. |
281 | 281 | */ |
282 | - function is_https(){ |
|
282 | + function is_https() { |
|
283 | 283 | /* |
284 | 284 | * some servers pass the "HTTPS" parameter in the server variable, |
285 | 285 | * if is the case, check if the value is "on", "true", "1". |
286 | 286 | */ |
287 | - if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
287 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
288 | 288 | return true; |
289 | 289 | } |
290 | - else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
290 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
291 | 291 | return true; |
292 | 292 | } |
293 | - else if(isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
293 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
294 | 294 | return true; |
295 | 295 | } |
296 | 296 | return false; |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * |
306 | 306 | * @return boolean true if is a valid URL address or false. |
307 | 307 | */ |
308 | - function is_url($url){ |
|
308 | + function is_url($url) { |
|
309 | 309 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url); |
310 | 310 | } |
311 | 311 | |
@@ -315,8 +315,8 @@ discard block |
||
315 | 315 | * @param string $controllerClass the controller class name to be loaded |
316 | 316 | * @codeCoverageIgnore |
317 | 317 | */ |
318 | - function autoload_controller($controllerClass){ |
|
319 | - if(file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
318 | + function autoload_controller($controllerClass) { |
|
319 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
320 | 320 | require_once $path; |
321 | 321 | } |
322 | 322 | } |
@@ -330,11 +330,11 @@ discard block |
||
330 | 330 | * |
331 | 331 | * @return boolean |
332 | 332 | */ |
333 | - function php_exception_handler($ex){ |
|
334 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
335 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
333 | + function php_exception_handler($ex) { |
|
334 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
335 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
336 | 336 | } |
337 | - else{ |
|
337 | + else { |
|
338 | 338 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
339 | 339 | } |
340 | 340 | exit(1); |
@@ -353,16 +353,16 @@ discard block |
||
353 | 353 | * |
354 | 354 | * @return boolean |
355 | 355 | */ |
356 | - function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){ |
|
356 | + function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) { |
|
357 | 357 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
358 | - if($isError){ |
|
358 | + if ($isError) { |
|
359 | 359 | set_http_status_header(500); |
360 | 360 | } |
361 | - if (! (error_reporting() & $errno)) { |
|
361 | + if (!(error_reporting() & $errno)) { |
|
362 | 362 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ' . $error_type, 'PHP ERROR'); |
363 | 363 | return; |
364 | 364 | } |
365 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
365 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
366 | 366 | $errorType = 'error'; |
367 | 367 | switch ($errno) { |
368 | 368 | case E_USER_ERROR: |
@@ -378,9 +378,9 @@ discard block |
||
378 | 378 | $errorType = 'error'; |
379 | 379 | break; |
380 | 380 | } |
381 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
381 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
382 | 382 | } |
383 | - if ($isError){ |
|
383 | + if ($isError) { |
|
384 | 384 | exit(1); |
385 | 385 | } |
386 | 386 | return true; |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | * This function is used to run in shutdown situation of the script |
391 | 391 | * @codeCoverageIgnore |
392 | 392 | */ |
393 | - function php_shudown_handler(){ |
|
393 | + function php_shudown_handler() { |
|
394 | 394 | $lastError = error_get_last(); |
395 | 395 | if (isset($lastError) && |
396 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
396 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
397 | 397 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
398 | 398 | } |
399 | 399 | } |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | * |
413 | 413 | * @return string string of the HTML attribute. |
414 | 414 | */ |
415 | - function attributes_to_string(array $attributes){ |
|
415 | + function attributes_to_string(array $attributes) { |
|
416 | 416 | $str = ' '; |
417 | 417 | //we check that the array passed as an argument is not empty. |
418 | - if(! empty($attributes)){ |
|
419 | - foreach($attributes as $key => $value){ |
|
418 | + if (!empty($attributes)) { |
|
419 | + foreach ($attributes as $key => $value) { |
|
420 | 420 | $key = trim(htmlspecialchars($key)); |
421 | 421 | $value = trim(htmlspecialchars($value)); |
422 | 422 | /* |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | * $attr = array('placeholder' => 'I am a "puple"') |
427 | 427 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
428 | 428 | */ |
429 | - if($value && strpos('"', $value) !== false){ |
|
429 | + if ($value && strpos('"', $value) !== false) { |
|
430 | 430 | $value = addslashes($value); |
431 | 431 | } |
432 | - $str .= $key.' = "'.$value.'" '; |
|
432 | + $str .= $key . ' = "' . $value . '" '; |
|
433 | 433 | } |
434 | 434 | } |
435 | 435 | //remove the space after using rtrim() |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | * |
446 | 446 | * @return string the stringfy value |
447 | 447 | */ |
448 | - function stringfy_vars($var){ |
|
448 | + function stringfy_vars($var) { |
|
449 | 449 | return print_r($var, true); |
450 | 450 | } |
451 | 451 | |
@@ -456,18 +456,18 @@ discard block |
||
456 | 456 | * |
457 | 457 | * @return mixed the sanitize value |
458 | 458 | */ |
459 | - function clean_input($str){ |
|
460 | - if(is_array($str)){ |
|
459 | + function clean_input($str) { |
|
460 | + if (is_array($str)) { |
|
461 | 461 | $str = array_map('clean_input', $str); |
462 | 462 | } |
463 | - else if(is_object($str)){ |
|
463 | + else if (is_object($str)) { |
|
464 | 464 | $obj = $str; |
465 | 465 | foreach ($str as $var => $value) { |
466 | 466 | $obj->$var = clean_input($value); |
467 | 467 | } |
468 | 468 | $str = $obj; |
469 | 469 | } |
470 | - else{ |
|
470 | + else { |
|
471 | 471 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
472 | 472 | } |
473 | 473 | return $str; |
@@ -485,11 +485,11 @@ discard block |
||
485 | 485 | * |
486 | 486 | * @return string the string with the hidden part. |
487 | 487 | */ |
488 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
488 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
489 | 489 | //get the string length |
490 | 490 | $len = strlen($str); |
491 | 491 | //if str is empty |
492 | - if($len <= 0){ |
|
492 | + if ($len <= 0) { |
|
493 | 493 | return str_repeat($hiddenChar, 6); |
494 | 494 | } |
495 | 495 | //if the length is less than startCount and endCount |
@@ -497,14 +497,14 @@ discard block |
||
497 | 497 | //or startCount is negative or endCount is negative |
498 | 498 | //return the full string hidden |
499 | 499 | |
500 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
500 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
501 | 501 | return str_repeat($hiddenChar, $len); |
502 | 502 | } |
503 | 503 | //the start non hidden string |
504 | 504 | $startNonHiddenStr = substr($str, 0, $startCount); |
505 | 505 | //the end non hidden string |
506 | 506 | $endNonHiddenStr = null; |
507 | - if($endCount > 0){ |
|
507 | + if ($endCount > 0) { |
|
508 | 508 | $endNonHiddenStr = substr($str, - $endCount); |
509 | 509 | } |
510 | 510 | //the hidden string |
@@ -517,31 +517,31 @@ discard block |
||
517 | 517 | * This function is used to set the initial session config regarding the configuration |
518 | 518 | * @codeCoverageIgnore |
519 | 519 | */ |
520 | - function set_session_config(){ |
|
520 | + function set_session_config() { |
|
521 | 521 | //$_SESSION is not available on cli mode |
522 | - if(! IS_CLI){ |
|
523 | - $logger =& class_loader('Log', 'classes'); |
|
522 | + if (!IS_CLI) { |
|
523 | + $logger = & class_loader('Log', 'classes'); |
|
524 | 524 | $logger->setLogger('PHPSession'); |
525 | 525 | //set session params |
526 | 526 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
527 | 527 | $sessionName = get_config('session_name'); |
528 | - if($sessionName){ |
|
528 | + if ($sessionName) { |
|
529 | 529 | session_name($sessionName); |
530 | 530 | } |
531 | 531 | $logger->info('Session handler: ' . $sessionHandler); |
532 | 532 | $logger->info('Session name: ' . $sessionName); |
533 | 533 | |
534 | - if($sessionHandler == 'files'){ |
|
534 | + if ($sessionHandler == 'files') { |
|
535 | 535 | $sessionSavePath = get_config('session_save_path'); |
536 | - if($sessionSavePath){ |
|
537 | - if(! is_dir($sessionSavePath)){ |
|
536 | + if ($sessionSavePath) { |
|
537 | + if (!is_dir($sessionSavePath)) { |
|
538 | 538 | mkdir($sessionSavePath, 1773); |
539 | 539 | } |
540 | 540 | session_save_path($sessionSavePath); |
541 | 541 | $logger->info('Session save path: ' . $sessionSavePath); |
542 | 542 | } |
543 | 543 | } |
544 | - else if($sessionHandler == 'database'){ |
|
544 | + else if ($sessionHandler == 'database') { |
|
545 | 545 | //load database session handle library |
546 | 546 | //Model |
547 | 547 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | //Database Session handler Model |
550 | 550 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
551 | 551 | |
552 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
552 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
553 | 553 | session_set_save_handler($DBS, true); |
554 | 554 | $logger->info('session save path: ' . get_config('session_save_path')); |
555 | 555 | } |
556 | - else{ |
|
556 | + else { |
|
557 | 557 | show_error('Invalid session handler configuration'); |
558 | 558 | } |
559 | 559 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | $logger->info('Session lifetime: ' . $lifetime); |
577 | 577 | $logger->info('Session cookie path: ' . $path); |
578 | 578 | $logger->info('Session domain: ' . $domain); |
579 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
579 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
580 | 580 | |
581 | - if((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
581 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
582 | 582 | $logger->info('Session not yet start, start it now'); |
583 | 583 | session_start(); |
584 | 584 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | |
43 | 43 | |
44 | - if(! function_exists('get_ip')){ |
|
44 | + if (!function_exists('get_ip')) { |
|
45 | 45 | /** |
46 | 46 | * Retrieves the user's IP address |
47 | 47 | * |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return string the IP address. |
52 | 52 | */ |
53 | - function get_ip(){ |
|
53 | + function get_ip() { |
|
54 | 54 | $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; |
55 | 55 | |
56 | 56 | if (isset($_SERVER["HTTP_CLIENT_IP"])) { |
@@ -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 |
@@ -81,25 +81,25 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected $loader = null; |
83 | 83 | |
84 | - public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){ |
|
84 | + public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null) { |
|
85 | 85 | /** |
86 | 86 | * instance of the Log class |
87 | 87 | */ |
88 | - if(is_object($logger)){ |
|
88 | + if (is_object($logger)) { |
|
89 | 89 | $this->setLogger($logger); |
90 | 90 | } |
91 | - else{ |
|
92 | - $this->logger =& class_loader('Log', 'classes'); |
|
91 | + else { |
|
92 | + $this->logger = & class_loader('Log', 'classes'); |
|
93 | 93 | $this->logger->setLogger('Library::DBSessionHandler'); |
94 | 94 | } |
95 | 95 | |
96 | - if(is_object($loader)){ |
|
96 | + if (is_object($loader)) { |
|
97 | 97 | $this->setLoader($loader); |
98 | 98 | } |
99 | 99 | $this->OBJ = & get_instance(); |
100 | 100 | |
101 | 101 | |
102 | - if(is_object($modelInstance)){ |
|
102 | + if (is_object($modelInstance)) { |
|
103 | 103 | $this->setModelInstance($modelInstance); |
104 | 104 | } |
105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * Set the session secret used to encrypt the data in database |
109 | 109 | * @param string $secret the base64 string secret |
110 | 110 | */ |
111 | - public function setSessionSecret($secret){ |
|
111 | + public function setSessionSecret($secret) { |
|
112 | 112 | $this->sessionSecret = $secret; |
113 | 113 | return $this; |
114 | 114 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * Return the session secret |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - public function getSessionSecret(){ |
|
120 | + public function getSessionSecret() { |
|
121 | 121 | return $this->sessionSecret; |
122 | 122 | } |
123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * Set the initializer vector for openssl |
127 | 127 | * @param string $key the session secret used |
128 | 128 | */ |
129 | - public function setInitializerVector($key){ |
|
129 | + public function setInitializerVector($key) { |
|
130 | 130 | $iv_length = openssl_cipher_iv_length(self::DB_SESSION_HASH_METHOD); |
131 | 131 | $key = base64_decode($key); |
132 | 132 | $this->iv = substr(hash('sha256', $key), 0, $iv_length); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * Return the initializer vector |
138 | 138 | * @return string |
139 | 139 | */ |
140 | - public function getInitializerVector(){ |
|
140 | + public function getInitializerVector() { |
|
141 | 141 | return $this->iv; |
142 | 142 | } |
143 | 143 | |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | * @param string $sessionName the session name |
148 | 148 | * @return boolean |
149 | 149 | */ |
150 | - public function open($savePath, $sessionName){ |
|
150 | + public function open($savePath, $sessionName) { |
|
151 | 151 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
152 | 152 | //try to check if session secret is set before |
153 | - if(! $this->getSessionSecret()){ |
|
153 | + if (!$this->getSessionSecret()) { |
|
154 | 154 | $secret = get_config('session_secret', false); |
155 | 155 | $this->setSessionSecret($secret); |
156 | 156 | } |
157 | 157 | $this->logger->info('Session secret: ' . $this->getSessionSecret()); |
158 | 158 | |
159 | - if(! $this->getModelInstance()){ |
|
159 | + if (!$this->getModelInstance()) { |
|
160 | 160 | $this->setModelInstanceFromConfig(); |
161 | 161 | } |
162 | 162 | $this->setInitializerVector($this->getSessionSecret()); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | //set session tables columns |
165 | 165 | $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns(); |
166 | 166 | |
167 | - if(empty($this->sessionTableColumns)){ |
|
167 | + if (empty($this->sessionTableColumns)) { |
|
168 | 168 | show_error('The session handler is "database" but the table columns not set'); |
169 | 169 | } |
170 | 170 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * Close the session |
181 | 181 | * @return boolean |
182 | 182 | */ |
183 | - public function close(){ |
|
183 | + public function close() { |
|
184 | 184 | $this->logger->debug('Closing database session handler'); |
185 | 185 | return true; |
186 | 186 | } |
@@ -190,15 +190,15 @@ discard block |
||
190 | 190 | * @param string $sid the session id to use |
191 | 191 | * @return mixed the session data in serialiaze format |
192 | 192 | */ |
193 | - public function read($sid){ |
|
193 | + public function read($sid) { |
|
194 | 194 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
195 | 195 | $instance = $this->getModelInstance(); |
196 | 196 | $columns = $this->sessionTableColumns; |
197 | - if($this->getLoader()){ |
|
197 | + if ($this->getLoader()) { |
|
198 | 198 | $this->getLoader()->functions('user_agent'); |
199 | 199 | $this->getLoader()->library('Browser'); |
200 | 200 | } |
201 | - else{ |
|
201 | + else { |
|
202 | 202 | Loader::functions('user_agent'); |
203 | 203 | Loader::library('Browser'); |
204 | 204 | } |
@@ -206,13 +206,13 @@ discard block |
||
206 | 206 | $ip = get_ip(); |
207 | 207 | $keyValue = $instance->getKeyValue(); |
208 | 208 | $host = @gethostbyaddr($ip) or null; |
209 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
209 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
210 | 210 | |
211 | 211 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
212 | - if($data && isset($data->{$columns['sdata']})){ |
|
212 | + if ($data && isset($data->{$columns['sdata']})) { |
|
213 | 213 | //checking inactivity |
214 | 214 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
215 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
215 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
216 | 216 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
217 | 217 | $this->destroy($sid); |
218 | 218 | return false; |
@@ -229,16 +229,16 @@ discard block |
||
229 | 229 | * @param mixed $data the session data to save in serialize format |
230 | 230 | * @return boolean |
231 | 231 | */ |
232 | - public function write($sid, $data){ |
|
232 | + public function write($sid, $data) { |
|
233 | 233 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
234 | 234 | $instance = $this->getModelInstance(); |
235 | 235 | $columns = $this->sessionTableColumns; |
236 | 236 | |
237 | - if($this->getLoader()){ |
|
237 | + if ($this->getLoader()) { |
|
238 | 238 | $this->getLoader()->functions('user_agent'); |
239 | 239 | $this->getLoader()->library('Browser'); |
240 | 240 | } |
241 | - else{ |
|
241 | + else { |
|
242 | 242 | Loader::functions('user_agent'); |
243 | 243 | Loader::library('Browser'); |
244 | 244 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $ip = get_ip(); |
247 | 247 | $keyValue = $instance->getKeyValue(); |
248 | 248 | $host = @gethostbyaddr($ip) or null; |
249 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
249 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
250 | 250 | $data = $this->encode($data); |
251 | 251 | $params = array( |
252 | 252 | $columns['sid'] => $sid, |
@@ -259,13 +259,13 @@ discard block |
||
259 | 259 | ); |
260 | 260 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
261 | 261 | $exists = $instance->get($sid); |
262 | - if($exists){ |
|
262 | + if ($exists) { |
|
263 | 263 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
264 | 264 | //update |
265 | 265 | unset($params[$columns['sid']]); |
266 | 266 | $instance->update($sid, $params); |
267 | 267 | } |
268 | - else{ |
|
268 | + else { |
|
269 | 269 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
270 | 270 | $instance->insert($params); |
271 | 271 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param string $sid the session id value |
279 | 279 | * @return boolean |
280 | 280 | */ |
281 | - public function destroy($sid){ |
|
281 | + public function destroy($sid) { |
|
282 | 282 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
283 | 283 | $instance = $this->modelInstanceName; |
284 | 284 | $instance->delete($sid); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param ineteger $maxLifetime the max lifetime |
291 | 291 | * @return boolean |
292 | 292 | */ |
293 | - public function gc($maxLifetime){ |
|
293 | + public function gc($maxLifetime) { |
|
294 | 294 | $instance = $this->modelInstanceName; |
295 | 295 | $time = time() - $maxLifetime; |
296 | 296 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * @param mixed $data the session data to encode |
304 | 304 | * @return mixed the encoded session data |
305 | 305 | */ |
306 | - public function encode($data){ |
|
306 | + public function encode($data) { |
|
307 | 307 | $key = base64_decode($this->sessionSecret); |
308 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
308 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
309 | 309 | $output = base64_encode($dataEncrypted); |
310 | 310 | return $output; |
311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param mixed $data the data to decode |
317 | 317 | * @return mixed the decoded data |
318 | 318 | */ |
319 | - public function decode($data){ |
|
319 | + public function decode($data) { |
|
320 | 320 | $key = base64_decode($this->sessionSecret); |
321 | 321 | $data = base64_decode($data); |
322 | 322 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * Return the loader instance |
329 | 329 | * @return Loader the loader instance |
330 | 330 | */ |
331 | - public function getLoader(){ |
|
331 | + public function getLoader() { |
|
332 | 332 | return $this->loader; |
333 | 333 | } |
334 | 334 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * set the loader instance for future use |
337 | 337 | * @param Loader $loader the loader object |
338 | 338 | */ |
339 | - public function setLoader($loader){ |
|
339 | + public function setLoader($loader) { |
|
340 | 340 | $this->loader = $loader; |
341 | 341 | return $this; |
342 | 342 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * Return the model instance |
346 | 346 | * @return DBSessionHandlerModel the model instance |
347 | 347 | */ |
348 | - public function getModelInstance(){ |
|
348 | + public function getModelInstance() { |
|
349 | 349 | return $this->modelInstanceName; |
350 | 350 | } |
351 | 351 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * set the model instance for future use |
354 | 354 | * @param DBSessionHandlerModel $modelInstance the model object |
355 | 355 | */ |
356 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
356 | + public function setModelInstance(DBSessionHandlerModel $modelInstance) { |
|
357 | 357 | $this->modelInstanceName = $modelInstance; |
358 | 358 | return $this; |
359 | 359 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * Return the Log instance |
363 | 363 | * @return Log |
364 | 364 | */ |
365 | - public function getLogger(){ |
|
365 | + public function getLogger() { |
|
366 | 366 | return $this->logger; |
367 | 367 | } |
368 | 368 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * Set the log instance |
371 | 371 | * @param Log $logger the log object |
372 | 372 | */ |
373 | - public function setLogger(Log $logger){ |
|
373 | + public function setLogger(Log $logger) { |
|
374 | 374 | $this->logger = $logger; |
375 | 375 | return $this; |
376 | 376 | } |
@@ -378,18 +378,18 @@ discard block |
||
378 | 378 | /** |
379 | 379 | * Set the model instance using the configuration for session |
380 | 380 | */ |
381 | - private function setModelInstanceFromConfig(){ |
|
381 | + private function setModelInstanceFromConfig() { |
|
382 | 382 | $modelName = get_config('session_save_path'); |
383 | 383 | $this->logger->info('The database session model: ' . $modelName); |
384 | - if($this->getLoader()){ |
|
384 | + if ($this->getLoader()) { |
|
385 | 385 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
386 | 386 | } |
387 | 387 | //@codeCoverageIgnoreStart |
388 | - else{ |
|
388 | + else { |
|
389 | 389 | Loader::model($modelName, 'dbsessionhandlerinstance'); |
390 | 390 | } |
391 | - if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
392 | - show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"'); |
|
391 | + if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) { |
|
392 | + show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"'); |
|
393 | 393 | } |
394 | 394 | //@codeCoverageIgnoreEnd |
395 | 395 |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | protected $sessionTableColumns = array(); |
47 | 47 | |
48 | - public function __construct(Database $db = null){ |
|
48 | + public function __construct(Database $db = null) { |
|
49 | 49 | parent::__construct($db); |
50 | 50 | } |
51 | 51 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * Return the session database table columns |
54 | 54 | * @return array |
55 | 55 | */ |
56 | - public function getSessionTableColumns(){ |
|
56 | + public function getSessionTableColumns() { |
|
57 | 57 | return $this->sessionTableColumns; |
58 | 58 | } |
59 | 59 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * Set the session database table columns |
62 | 62 | * @param array $columns the columns definition |
63 | 63 | */ |
64 | - public function setSessionTableColumns(array $columns){ |
|
64 | + public function setSessionTableColumns(array $columns) { |
|
65 | 65 | $this->sessionTableColumns = $columns; |
66 | 66 | return $this; |
67 | 67 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @copyright Copyright (c) 2012, Jamie Rumbelow <http://jamierumbelow.net> |
34 | 34 | */ |
35 | 35 | |
36 | - class Model{ |
|
36 | + class Model { |
|
37 | 37 | |
38 | 38 | /* -------------------------------------------------------------- |
39 | 39 | * VARIABLES |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | * Initialise the model, tie into the CodeIgniter superobject and |
141 | 141 | * try our best to guess the table name. |
142 | 142 | */ |
143 | - public function __construct(Database $db = null){ |
|
144 | - if(is_object($db)){ |
|
143 | + public function __construct(Database $db = null) { |
|
144 | + if (is_object($db)) { |
|
145 | 145 | $this->setDatabaseInstance($db); |
146 | 146 | } |
147 | - else{ |
|
147 | + else { |
|
148 | 148 | $obj = & get_instance(); |
149 | - if(isset($obj->database) && is_object($obj->database)){ |
|
149 | + if (isset($obj->database) && is_object($obj->database)) { |
|
150 | 150 | /** |
151 | 151 | * NOTE: Need use "clone" because some Model need have the personal instance of the database library |
152 | 152 | * to prevent duplication |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | |
183 | 183 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
184 | 184 | { |
185 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
185 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | $this->_set_where($where); |
189 | 189 | |
190 | 190 | $this->trigger('before_get'); |
191 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
191 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
192 | 192 | $row = $this->_database->from($this->_table)->get($type); |
193 | 193 | $this->_temporary_return_type = $this->return_type; |
194 | 194 | $row = $this->trigger('after_get', $row); |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | $this->trigger('before_get'); |
225 | 225 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
226 | 226 | { |
227 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
227 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
228 | 228 | } |
229 | - $type = $this->_temporary_return_type == 'array' ? 'array':false; |
|
229 | + $type = $this->_temporary_return_type == 'array' ? 'array' : false; |
|
230 | 230 | $result = $this->_database->from($this->_table)->getAll($type); |
231 | 231 | $this->_temporary_return_type = $this->return_type; |
232 | 232 | |
@@ -332,13 +332,13 @@ discard block |
||
332 | 332 | { |
333 | 333 | $args = func_get_args(); |
334 | 334 | $data = array(); |
335 | - if(count($args) == 2){ |
|
336 | - if(is_array($args[1])){ |
|
335 | + if (count($args) == 2) { |
|
336 | + if (is_array($args[1])) { |
|
337 | 337 | $data = array_pop($args); |
338 | 338 | } |
339 | 339 | } |
340 | - else if(count($args) == 3){ |
|
341 | - if(is_array($args[2])){ |
|
340 | + else if (count($args) == 3) { |
|
341 | + if (is_array($args[2])) { |
|
342 | 342 | $data = array_pop($args); |
343 | 343 | } |
344 | 344 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | $this->_database->where($this->primary_key, $id); |
377 | 377 | if ($this->soft_delete) |
378 | 378 | { |
379 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
379 | + $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE)); |
|
380 | 380 | } |
381 | 381 | else |
382 | 382 | { |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | $this->_set_where($where); |
398 | 398 | if ($this->soft_delete) |
399 | 399 | { |
400 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
400 | + $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE)); |
|
401 | 401 | } |
402 | 402 | else |
403 | 403 | { |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $this->_database->in($this->primary_key, $primary_values); |
417 | 417 | if ($this->soft_delete) |
418 | 418 | { |
419 | - $result = $this->_database->from($this->_table)->update(array( $this->soft_delete_key => TRUE )); |
|
419 | + $result = $this->_database->from($this->_table)->update(array($this->soft_delete_key => TRUE)); |
|
420 | 420 | } |
421 | 421 | else |
422 | 422 | { |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | if (is_string($value)) |
463 | 463 | { |
464 | 464 | $relationship = $value; |
465 | - $options = array( 'primary_key' => $value . '_id', 'model' => $value . '_model' ); |
|
465 | + $options = array('primary_key' => $value . '_id', 'model' => $value . '_model'); |
|
466 | 466 | } |
467 | 467 | else |
468 | 468 | { |
@@ -472,10 +472,10 @@ discard block |
||
472 | 472 | |
473 | 473 | if (in_array($relationship, $this->_with)) |
474 | 474 | { |
475 | - if(is_object($this->loaderInstance)){ |
|
475 | + if (is_object($this->loaderInstance)) { |
|
476 | 476 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
477 | 477 | } |
478 | - else{ |
|
478 | + else { |
|
479 | 479 | Loader::model($options['model'], $relationship . '_model'); |
480 | 480 | } |
481 | 481 | if (is_object($row)) |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | if (is_string($value)) |
495 | 495 | { |
496 | 496 | $relationship = $value; |
497 | - $options = array( 'primary_key' => $this->_table . '_id', 'model' => $value . '_model' ); |
|
497 | + $options = array('primary_key' => $this->_table . '_id', 'model' => $value . '_model'); |
|
498 | 498 | } |
499 | 499 | else |
500 | 500 | { |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | |
505 | 505 | if (in_array($relationship, $this->_with)) |
506 | 506 | { |
507 | - if(is_object($this->loaderInstance)){ |
|
507 | + if (is_object($this->loaderInstance)) { |
|
508 | 508 | $this->loaderInstance->model($options['model'], $relationship . '_model'); |
509 | 509 | } |
510 | - else{ |
|
510 | + else { |
|
511 | 511 | Loader::model($options['model'], $relationship . '_model'); |
512 | 512 | } |
513 | 513 | if (is_object($row)) |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | public function dropdown() |
534 | 534 | { |
535 | 535 | $args = func_get_args(); |
536 | - if(count($args) == 2) |
|
536 | + if (count($args) == 2) |
|
537 | 537 | { |
538 | 538 | list($key, $value) = $args; |
539 | 539 | } |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | $key = $this->primary_key; |
543 | 543 | $value = $args[0]; |
544 | 544 | } |
545 | - $this->trigger('before_dropdown', array( $key, $value )); |
|
545 | + $this->trigger('before_dropdown', array($key, $value)); |
|
546 | 546 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
547 | 547 | { |
548 | 548 | $this->_database->where($this->soft_delete_key, FALSE); |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | { |
567 | 567 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
568 | 568 | { |
569 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
569 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
570 | 570 | } |
571 | 571 | $where = func_get_args(); |
572 | 572 | $this->_set_where($where); |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | { |
582 | 582 | if ($this->soft_delete && $this->_temporary_with_deleted !== TRUE) |
583 | 583 | { |
584 | - $this->_database->where($this->soft_delete_key, (bool)$this->_temporary_only_deleted); |
|
584 | + $this->_database->where($this->soft_delete_key, (bool) $this->_temporary_only_deleted); |
|
585 | 585 | } |
586 | 586 | $this->_database->from($this->_table)->getAll(); |
587 | 587 | return $this->_database->numRows(); |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | /** |
591 | 591 | * Enabled cache temporary |
592 | 592 | */ |
593 | - public function cached($ttl = 0){ |
|
594 | - if($ttl > 0){ |
|
593 | + public function cached($ttl = 0) { |
|
594 | + if ($ttl > 0) { |
|
595 | 595 | $this->_database = $this->_database->cached($ttl); |
596 | 596 | } |
597 | 597 | return $this; |
@@ -745,13 +745,13 @@ discard block |
||
745 | 745 | { |
746 | 746 | if (is_object($row)) |
747 | 747 | { |
748 | - if(isset($row->$attr)){ |
|
748 | + if (isset($row->$attr)) { |
|
749 | 749 | unset($row->$attr); |
750 | 750 | } |
751 | 751 | } |
752 | 752 | else |
753 | 753 | { |
754 | - if(isset($row[$attr])){ |
|
754 | + if (isset($row[$attr])) { |
|
755 | 755 | unset($row[$attr]); |
756 | 756 | } |
757 | 757 | } |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | * Return the database instance |
764 | 764 | * @return Database the database instance |
765 | 765 | */ |
766 | - public function getDatabaseInstance(){ |
|
766 | + public function getDatabaseInstance() { |
|
767 | 767 | return $this->_database; |
768 | 768 | } |
769 | 769 | |
@@ -771,9 +771,9 @@ discard block |
||
771 | 771 | * set the Database instance for future use |
772 | 772 | * @param Database $db the database object |
773 | 773 | */ |
774 | - public function setDatabaseInstance($db){ |
|
774 | + public function setDatabaseInstance($db) { |
|
775 | 775 | $this->_database = $db; |
776 | - if($this->dbCacheTime > 0){ |
|
776 | + if ($this->dbCacheTime > 0) { |
|
777 | 777 | $this->_database->setCache($this->dbCacheTime); |
778 | 778 | } |
779 | 779 | return $this; |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | * Return the loader instance |
784 | 784 | * @return Loader the loader instance |
785 | 785 | */ |
786 | - public function getLoader(){ |
|
786 | + public function getLoader() { |
|
787 | 787 | return $this->loaderInstance; |
788 | 788 | } |
789 | 789 | |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * set the loader instance for future use |
792 | 792 | * @param Loader $loader the loader object |
793 | 793 | */ |
794 | - public function setLoader($loader){ |
|
794 | + public function setLoader($loader) { |
|
795 | 795 | $this->loaderInstance = $loader; |
796 | 796 | return $this; |
797 | 797 | } |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | * Return the FormValidation instance |
801 | 801 | * @return FormValidation the form validation instance |
802 | 802 | */ |
803 | - public function getFormValidation(){ |
|
803 | + public function getFormValidation() { |
|
804 | 804 | return $this->formValidationInstance; |
805 | 805 | } |
806 | 806 | |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | * set the form validation instance for future use |
809 | 809 | * @param FormValidation $fv the form validation object |
810 | 810 | */ |
811 | - public function setFormValidation($fv){ |
|
811 | + public function setFormValidation($fv) { |
|
812 | 812 | $this->formValidationInstance = $fv; |
813 | 813 | return $this; |
814 | 814 | } |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | */ |
823 | 823 | public function order_by($criteria, $order = 'ASC') |
824 | 824 | { |
825 | - if ( is_array($criteria) ) |
|
825 | + if (is_array($criteria)) |
|
826 | 826 | { |
827 | 827 | foreach ($criteria as $key => $value) |
828 | 828 | { |
@@ -878,22 +878,22 @@ discard block |
||
878 | 878 | */ |
879 | 879 | protected function validate(array $data) |
880 | 880 | { |
881 | - if($this->skip_validation) |
|
881 | + if ($this->skip_validation) |
|
882 | 882 | { |
883 | 883 | return $data; |
884 | 884 | } |
885 | - if(!empty($this->validate)) |
|
885 | + if (!empty($this->validate)) |
|
886 | 886 | { |
887 | 887 | $fv = null; |
888 | - if(is_object($this->formValidationInstance)){ |
|
888 | + if (is_object($this->formValidationInstance)) { |
|
889 | 889 | $fv = $this->formValidationInstance; |
890 | 890 | } |
891 | - else{ |
|
891 | + else { |
|
892 | 892 | Loader::library('FormValidation'); |
893 | 893 | $fv = $this->formvalidation; |
894 | 894 | $this->setFormValidation($fv); |
895 | 895 | } |
896 | - if(is_array($this->validate)) |
|
896 | + if (is_array($this->validate)) |
|
897 | 897 | { |
898 | 898 | $fv->setData($data); |
899 | 899 | $fv->setRules($this->validate); |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | { |
949 | 949 | $this->_database->where($params[0]); |
950 | 950 | } |
951 | - else if(count($params) == 2) |
|
951 | + else if (count($params) == 2) |
|
952 | 952 | { |
953 | 953 | if (is_array($params[1])) |
954 | 954 | { |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | $this->_database->where($params[0], $params[1]); |
960 | 960 | } |
961 | 961 | } |
962 | - else if(count($params) == 3) |
|
962 | + else if (count($params) == 3) |
|
963 | 963 | { |
964 | 964 | $this->_database->where($params[0], $params[1], $params[2]); |
965 | 965 | } |
@@ -979,7 +979,7 @@ discard block |
||
979 | 979 | /** |
980 | 980 | Shortcut to controller |
981 | 981 | */ |
982 | - public function __get($key){ |
|
982 | + public function __get($key) { |
|
983 | 983 | return get_instance()->{$key}; |
984 | 984 | } |
985 | 985 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Config{ |
|
27 | + class Config { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of loaded configuration |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * The signleton of the logger |
43 | 43 | * @return Object the Log instance |
44 | 44 | */ |
45 | - private static function getLogger(){ |
|
46 | - if(static::$logger == null){ |
|
47 | - $logger[0] =& class_loader('Log', 'classes'); |
|
45 | + private static function getLogger() { |
|
46 | + if (static::$logger == null) { |
|
47 | + $logger[0] = & class_loader('Log', 'classes'); |
|
48 | 48 | $logger[0]->setLogger('Library::Config'); |
49 | 49 | static::$logger = $logger[0]; |
50 | 50 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param Log $logger the log object |
57 | 57 | * @return Log the log instance |
58 | 58 | */ |
59 | - public static function setLogger($logger){ |
|
59 | + public static function setLogger($logger) { |
|
60 | 60 | static::$logger = $logger; |
61 | 61 | return static::$logger; |
62 | 62 | } |
@@ -64,35 +64,35 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * Initialize the configuration by loading all the configuration from config file |
66 | 66 | */ |
67 | - public static function init(){ |
|
67 | + public static function init() { |
|
68 | 68 | $logger = static::getLogger(); |
69 | 69 | $logger->debug('Initialization of the configuration'); |
70 | 70 | static::$config = & load_configurations(); |
71 | - if(! static::$config['base_url'] || ! is_url(static::$config['base_url'])){ |
|
72 | - if(ENVIRONMENT == 'production'){ |
|
71 | + if (!static::$config['base_url'] || !is_url(static::$config['base_url'])) { |
|
72 | + if (ENVIRONMENT == 'production') { |
|
73 | 73 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
74 | 74 | } |
75 | 75 | $baseUrl = null; |
76 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
76 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
77 | 77 | //check if the server is running under IPv6 |
78 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
79 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
78 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
79 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
80 | 80 | } |
81 | - else{ |
|
81 | + else { |
|
82 | 82 | $baseUrl = $_SERVER['SERVER_ADDR']; |
83 | 83 | } |
84 | - $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
85 | - $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
|
84 | + $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
85 | + $baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port |
|
86 | 86 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
87 | 87 | } |
88 | - else{ |
|
88 | + else { |
|
89 | 89 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
90 | 90 | $baseUrl = 'http://localhost/'; |
91 | 91 | } |
92 | 92 | self::set('base_url', $baseUrl); |
93 | 93 | } |
94 | - static::$config['base_url'] = rtrim(static::$config['base_url'], '/') .'/'; |
|
95 | - if(ENVIRONMENT == 'production' && in_array(strtolower(static::$config['log_level']), array('debug', 'info','all'))){ |
|
94 | + static::$config['base_url'] = rtrim(static::$config['base_url'], '/') . '/'; |
|
95 | + if (ENVIRONMENT == 'production' && in_array(strtolower(static::$config['log_level']), array('debug', 'info', 'all'))) { |
|
96 | 96 | $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
97 | 97 | } |
98 | 98 | $logger->info('Configuration initialized successfully'); |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | * @param mixed $default the default value to use if can not find the config item in the list |
106 | 106 | * @return mixed the config value if exist or the default value |
107 | 107 | */ |
108 | - public static function get($item, $default = null){ |
|
108 | + public static function get($item, $default = null) { |
|
109 | 109 | $logger = static::getLogger(); |
110 | - if(array_key_exists($item, static::$config)){ |
|
110 | + if (array_key_exists($item, static::$config)) { |
|
111 | 111 | return static::$config[$item]; |
112 | 112 | } |
113 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
113 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
114 | 114 | return $default; |
115 | 115 | } |
116 | 116 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param string $item the config item name to set |
120 | 120 | * @param mixed $value the config item value |
121 | 121 | */ |
122 | - public static function set($item, $value){ |
|
122 | + public static function set($item, $value) { |
|
123 | 123 | static::$config[$item] = $value; |
124 | 124 | } |
125 | 125 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * Get all the configuration values |
128 | 128 | * @return array the config values |
129 | 129 | */ |
130 | - public static function getAll(){ |
|
130 | + public static function getAll() { |
|
131 | 131 | return static::$config; |
132 | 132 | } |
133 | 133 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * Set the configuration values bu merged with the existing configuration |
136 | 136 | * @param array $config the config values to add in the configuration list |
137 | 137 | */ |
138 | - public static function setAll(array $config = array()){ |
|
138 | + public static function setAll(array $config = array()) { |
|
139 | 139 | static::$config = array_merge(static::$config, $config); |
140 | 140 | } |
141 | 141 | |
@@ -144,15 +144,15 @@ discard block |
||
144 | 144 | * @param string $item the config item name to be deleted |
145 | 145 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
146 | 146 | */ |
147 | - public static function delete($item){ |
|
147 | + public static function delete($item) { |
|
148 | 148 | $logger = static::getLogger(); |
149 | - if(array_key_exists($item, static::$config)){ |
|
150 | - $logger->info('Delete config item ['.$item.']'); |
|
149 | + if (array_key_exists($item, static::$config)) { |
|
150 | + $logger->info('Delete config item [' . $item . ']'); |
|
151 | 151 | unset(static::$config[$item]); |
152 | 152 | return true; |
153 | 153 | } |
154 | - else{ |
|
155 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
154 | + else { |
|
155 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * Load the configuration file. This an alias to Loader::config() |
162 | 162 | * @param string $config the config name to be loaded |
163 | 163 | */ |
164 | - public static function load($config){ |
|
164 | + public static function load($config) { |
|
165 | 165 | Loader::config($config); |
166 | 166 | } |
167 | 167 | } |
@@ -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,77 +38,77 @@ 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 | 54 | } |
55 | 55 | //loading autoload configuration for modules |
56 | 56 | $modulesAutoloads = Module::getModulesAutoloadConfig(); |
57 | - if($modulesAutoloads && is_array($modulesAutoloads)){ |
|
57 | + if ($modulesAutoloads && is_array($modulesAutoloads)) { |
|
58 | 58 | //libraries autoload |
59 | - if(! empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])){ |
|
59 | + if (!empty($modulesAutoloads['libraries']) && is_array($modulesAutoloads['libraries'])) { |
|
60 | 60 | $autoloads['libraries'] = array_merge($autoloads['libraries'], $modulesAutoloads['libraries']); |
61 | 61 | } |
62 | 62 | //config autoload |
63 | - if(! empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])){ |
|
63 | + if (!empty($modulesAutoloads['config']) && is_array($modulesAutoloads['config'])) { |
|
64 | 64 | $autoloads['config'] = array_merge($autoloads['config'], $modulesAutoloads['config']); |
65 | 65 | } |
66 | 66 | //models autoload |
67 | - if(! empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])){ |
|
67 | + if (!empty($modulesAutoloads['models']) && is_array($modulesAutoloads['models'])) { |
|
68 | 68 | $autoloads['models'] = array_merge($autoloads['models'], $modulesAutoloads['models']); |
69 | 69 | } |
70 | 70 | //functions autoload |
71 | - if(! empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])){ |
|
71 | + if (!empty($modulesAutoloads['functions']) && is_array($modulesAutoloads['functions'])) { |
|
72 | 72 | $autoloads['functions'] = array_merge($autoloads['functions'], $modulesAutoloads['functions']); |
73 | 73 | } |
74 | 74 | //languages autoload |
75 | - if(! empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])){ |
|
75 | + if (!empty($modulesAutoloads['languages']) && is_array($modulesAutoloads['languages'])) { |
|
76 | 76 | $autoloads['languages'] = array_merge($autoloads['languages'], $modulesAutoloads['languages']); |
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | 80 | //config autoload |
81 | - if(! empty($autoloads['config']) && is_array($autoloads['config'])){ |
|
82 | - foreach($autoloads['config'] as $c){ |
|
81 | + if (!empty($autoloads['config']) && is_array($autoloads['config'])) { |
|
82 | + foreach ($autoloads['config'] as $c) { |
|
83 | 83 | $this->config($c); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | 87 | //languages autoload |
88 | - if(! empty($autoloads['languages']) && is_array($autoloads['languages'])){ |
|
89 | - foreach($autoloads['languages'] as $language){ |
|
88 | + if (!empty($autoloads['languages']) && is_array($autoloads['languages'])) { |
|
89 | + foreach ($autoloads['languages'] as $language) { |
|
90 | 90 | $this->lang($language); |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | //libraries autoload |
95 | - if(! empty($autoloads['libraries']) && is_array($autoloads['libraries'])){ |
|
96 | - foreach($autoloads['libraries'] as $library){ |
|
95 | + if (!empty($autoloads['libraries']) && is_array($autoloads['libraries'])) { |
|
96 | + foreach ($autoloads['libraries'] as $library) { |
|
97 | 97 | $this->library($library); |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | 101 | //models autoload |
102 | - if(! empty($autoloads['models']) && is_array($autoloads['models'])){ |
|
102 | + if (!empty($autoloads['models']) && is_array($autoloads['models'])) { |
|
103 | 103 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
104 | - foreach($autoloads['models'] as $model){ |
|
104 | + foreach ($autoloads['models'] as $model) { |
|
105 | 105 | $this->model($model); |
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
109 | 109 | //functions autoload |
110 | - if(! empty($autoloads['functions']) && is_array($autoloads['functions'])){ |
|
111 | - foreach($autoloads['functions'] as $function){ |
|
110 | + if (!empty($autoloads['functions']) && is_array($autoloads['functions'])) { |
|
111 | + foreach ($autoloads['functions'] as $function) { |
|
112 | 112 | $this->functions($function); |
113 | 113 | } |
114 | 114 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * Get the logger singleton instance |
120 | 120 | * @return Log the logger instance |
121 | 121 | */ |
122 | - private static function getLogger(){ |
|
123 | - if(static::$logger == null){ |
|
124 | - static::$logger[0] =& class_loader('Log', 'classes'); |
|
122 | + private static function getLogger() { |
|
123 | + if (static::$logger == null) { |
|
124 | + static::$logger[0] = & class_loader('Log', 'classes'); |
|
125 | 125 | static::$logger[0]->setLogger('Library::Loader'); |
126 | 126 | } |
127 | 127 | return static::$logger[0]; |
@@ -135,25 +135,25 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return void |
137 | 137 | */ |
138 | - public static function model($class, $instance = null){ |
|
138 | + public static function model($class, $instance = null) { |
|
139 | 139 | $logger = static::getLogger(); |
140 | 140 | $class = str_ireplace('.php', '', $class); |
141 | 141 | $class = trim($class, '/\\'); |
142 | - $file = ucfirst($class).'.php'; |
|
142 | + $file = ucfirst($class) . '.php'; |
|
143 | 143 | $logger->debug('Loading model [' . $class . '] ...'); |
144 | - if(! $instance){ |
|
144 | + if (!$instance) { |
|
145 | 145 | //for module |
146 | - if(strpos($class, '/') !== false){ |
|
146 | + if (strpos($class, '/') !== false) { |
|
147 | 147 | $path = explode('/', $class); |
148 | - if(isset($path[1])){ |
|
148 | + if (isset($path[1])) { |
|
149 | 149 | $instance = strtolower($path[1]); |
150 | 150 | } |
151 | 151 | } |
152 | - else{ |
|
152 | + else { |
|
153 | 153 | $instance = strtolower($class); |
154 | 154 | } |
155 | 155 | } |
156 | - if(isset(static::$loaded[$instance])){ |
|
156 | + if (isset(static::$loaded[$instance])) { |
|
157 | 157 | $logger->info('Model [' . $class . '] already loaded no need to load it again, cost in performance'); |
158 | 158 | return; |
159 | 159 | } |
@@ -163,43 +163,43 @@ discard block |
||
163 | 163 | $searchModuleName = null; |
164 | 164 | $obj = & get_instance(); |
165 | 165 | //check if the request class contains module name |
166 | - if(strpos($class, '/') !== false){ |
|
166 | + if (strpos($class, '/') !== false) { |
|
167 | 167 | $path = explode('/', $class); |
168 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
168 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
169 | 169 | $searchModuleName = $path[0]; |
170 | 170 | $class = ucfirst($path[1]); |
171 | 171 | } |
172 | 172 | } |
173 | - else{ |
|
173 | + else { |
|
174 | 174 | $class = ucfirst($class); |
175 | 175 | } |
176 | 176 | |
177 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
177 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
178 | 178 | $searchModuleName = $obj->moduleName; |
179 | 179 | } |
180 | 180 | $moduleModelFilePath = Module::findModelFullPath($class, $searchModuleName); |
181 | - if($moduleModelFilePath){ |
|
182 | - $logger->info('Found model [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleModelFilePath. '] we will used it'); |
|
181 | + if ($moduleModelFilePath) { |
|
182 | + $logger->info('Found model [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleModelFilePath . '] we will used it'); |
|
183 | 183 | $classFilePath = $moduleModelFilePath; |
184 | 184 | } |
185 | - else{ |
|
185 | + else { |
|
186 | 186 | $logger->info('Cannot find model [' . $class . '] from modules using the default location'); |
187 | 187 | } |
188 | 188 | $logger->info('The model file path to be loaded is [' . $classFilePath . ']'); |
189 | - if(file_exists($classFilePath)){ |
|
189 | + if (file_exists($classFilePath)) { |
|
190 | 190 | require_once $classFilePath; |
191 | - if(class_exists($class)){ |
|
191 | + if (class_exists($class)) { |
|
192 | 192 | $c = new $class(); |
193 | 193 | $obj = & get_instance(); |
194 | 194 | $obj->{$instance} = $c; |
195 | 195 | static::$loaded[$instance] = $class; |
196 | 196 | $logger->info('Model [' . $class . '] --> ' . $classFilePath . ' loaded successfully.'); |
197 | 197 | } |
198 | - else{ |
|
199 | - show_error('The file '.$classFilePath.' exists but does not contain the class ['. $class . ']'); |
|
198 | + else { |
|
199 | + show_error('The file ' . $classFilePath . ' exists but does not contain the class [' . $class . ']'); |
|
200 | 200 | } |
201 | 201 | } |
202 | - else{ |
|
202 | + else { |
|
203 | 203 | show_error('Unable to find the model [' . $class . ']'); |
204 | 204 | } |
205 | 205 | } |
@@ -214,31 +214,31 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return void |
216 | 216 | */ |
217 | - public static function library($class, $instance = null, array $params = array()){ |
|
217 | + public static function library($class, $instance = null, array $params = array()) { |
|
218 | 218 | $logger = static::getLogger(); |
219 | 219 | $class = str_ireplace('.php', '', $class); |
220 | 220 | $class = trim($class, '/\\'); |
221 | - $file = ucfirst($class) .'.php'; |
|
221 | + $file = ucfirst($class) . '.php'; |
|
222 | 222 | $logger->debug('Loading library [' . $class . '] ...'); |
223 | - if(! $instance){ |
|
223 | + if (!$instance) { |
|
224 | 224 | //for module |
225 | - if(strpos($class, '/') !== false){ |
|
225 | + if (strpos($class, '/') !== false) { |
|
226 | 226 | $path = explode('/', $class); |
227 | - if(isset($path[1])){ |
|
227 | + if (isset($path[1])) { |
|
228 | 228 | $instance = strtolower($path[1]); |
229 | 229 | } |
230 | 230 | } |
231 | - else{ |
|
231 | + else { |
|
232 | 232 | $instance = strtolower($class); |
233 | 233 | } |
234 | 234 | } |
235 | - if(isset(static::$loaded[$instance])){ |
|
235 | + if (isset(static::$loaded[$instance])) { |
|
236 | 236 | $logger->info('Library [' . $class . '] already loaded no need to load it again, cost in performance'); |
237 | 237 | return; |
238 | 238 | } |
239 | 239 | $obj = & get_instance(); |
240 | 240 | //TODO for Database library |
241 | - if(strtolower($class) == 'database'){ |
|
241 | + if (strtolower($class) == 'database') { |
|
242 | 242 | $logger->info('This is the Database library ...'); |
243 | 243 | $dbInstance = & class_loader('Database', 'classes', $params); |
244 | 244 | $obj->{$instance} = $dbInstance; |
@@ -249,45 +249,45 @@ discard block |
||
249 | 249 | $libraryFilePath = null; |
250 | 250 | $isSystem = false; |
251 | 251 | $logger->debug('Check if this is a system library ...'); |
252 | - if(file_exists(CORE_LIBRARY_PATH . $file)){ |
|
252 | + if (file_exists(CORE_LIBRARY_PATH . $file)) { |
|
253 | 253 | $isSystem = true; |
254 | 254 | $libraryFilePath = CORE_LIBRARY_PATH . $file; |
255 | 255 | $class = ucfirst($class); |
256 | 256 | $logger->info('This library is a system library'); |
257 | 257 | } |
258 | - else{ |
|
258 | + else { |
|
259 | 259 | $logger->info('This library is not a system library'); |
260 | 260 | //first check if this library is in the module |
261 | 261 | $logger->debug('Checking library [' . $class . '] from module list ...'); |
262 | 262 | $searchModuleName = null; |
263 | 263 | //check if the request class contains module name |
264 | - if(strpos($class, '/') !== false){ |
|
264 | + if (strpos($class, '/') !== false) { |
|
265 | 265 | $path = explode('/', $class); |
266 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
266 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
267 | 267 | $searchModuleName = $path[0]; |
268 | 268 | $class = ucfirst($path[1]); |
269 | 269 | } |
270 | 270 | } |
271 | - else{ |
|
271 | + else { |
|
272 | 272 | $class = ucfirst($class); |
273 | 273 | } |
274 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
274 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
275 | 275 | $searchModuleName = $obj->moduleName; |
276 | 276 | } |
277 | 277 | $moduleLibraryPath = Module::findLibraryFullPath($class, $searchModuleName); |
278 | - if($moduleLibraryPath){ |
|
279 | - $logger->info('Found library [' . $class . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLibraryPath. '] we will used it'); |
|
278 | + if ($moduleLibraryPath) { |
|
279 | + $logger->info('Found library [' . $class . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLibraryPath . '] we will used it'); |
|
280 | 280 | $libraryFilePath = $moduleLibraryPath; |
281 | 281 | } |
282 | - else{ |
|
282 | + else { |
|
283 | 283 | $logger->info('Cannot find library [' . $class . '] from modules using the default location'); |
284 | 284 | } |
285 | 285 | } |
286 | - if(! $libraryFilePath){ |
|
286 | + if (!$libraryFilePath) { |
|
287 | 287 | $searchDir = array(LIBRARY_PATH); |
288 | - foreach($searchDir as $dir){ |
|
288 | + foreach ($searchDir as $dir) { |
|
289 | 289 | $filePath = $dir . $file; |
290 | - if(file_exists($filePath)){ |
|
290 | + if (file_exists($filePath)) { |
|
291 | 291 | $libraryFilePath = $filePath; |
292 | 292 | //is already found not to continue |
293 | 293 | break; |
@@ -295,20 +295,20 @@ discard block |
||
295 | 295 | } |
296 | 296 | } |
297 | 297 | $logger->info('The library file path to be loaded is [' . $libraryFilePath . ']'); |
298 | - if($libraryFilePath){ |
|
298 | + if ($libraryFilePath) { |
|
299 | 299 | require_once $libraryFilePath; |
300 | - if(class_exists($class)){ |
|
300 | + if (class_exists($class)) { |
|
301 | 301 | $c = $params ? new $class($params) : new $class(); |
302 | 302 | $obj = & get_instance(); |
303 | 303 | $obj->{$instance} = $c; |
304 | 304 | static::$loaded[$instance] = $class; |
305 | 305 | $logger->info('Library [' . $class . '] --> ' . $libraryFilePath . ' loaded successfully.'); |
306 | 306 | } |
307 | - else{ |
|
308 | - show_error('The file '.$libraryFilePath.' exists but does not contain the class '.$class); |
|
307 | + else { |
|
308 | + show_error('The file ' . $libraryFilePath . ' exists but does not contain the class ' . $class); |
|
309 | 309 | } |
310 | 310 | } |
311 | - else{ |
|
311 | + else { |
|
312 | 312 | show_error('Unable to find library class [' . $class . ']'); |
313 | 313 | } |
314 | 314 | } |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @return void |
322 | 322 | */ |
323 | - public static function functions($function){ |
|
323 | + public static function functions($function) { |
|
324 | 324 | $logger = static::getLogger(); |
325 | 325 | $function = str_ireplace('.php', '', $function); |
326 | 326 | $function = trim($function, '/\\'); |
327 | 327 | $function = str_ireplace('function_', '', $function); |
328 | - $file = 'function_'.$function.'.php'; |
|
328 | + $file = 'function_' . $function . '.php'; |
|
329 | 329 | $logger->debug('Loading helper [' . $function . '] ...'); |
330 | - if(isset(static::$loaded['function_' . $function])){ |
|
330 | + if (isset(static::$loaded['function_' . $function])) { |
|
331 | 331 | $logger->info('Helper [' . $function . '] already loaded no need to load it again, cost in performance'); |
332 | 332 | return; |
333 | 333 | } |
@@ -337,30 +337,30 @@ discard block |
||
337 | 337 | $searchModuleName = null; |
338 | 338 | $obj = & get_instance(); |
339 | 339 | //check if the request class contains module name |
340 | - if(strpos($function, '/') !== false){ |
|
340 | + if (strpos($function, '/') !== false) { |
|
341 | 341 | $path = explode('/', $function); |
342 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
342 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
343 | 343 | $searchModuleName = $path[0]; |
344 | 344 | $function = 'function_' . $path[1] . '.php'; |
345 | - $file = $path[0] . DS . 'function_'.$function.'.php'; |
|
345 | + $file = $path[0] . DS . 'function_' . $function . '.php'; |
|
346 | 346 | } |
347 | 347 | } |
348 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
348 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
349 | 349 | $searchModuleName = $obj->moduleName; |
350 | 350 | } |
351 | 351 | $moduleFunctionPath = Module::findFunctionFullPath($function, $searchModuleName); |
352 | - if($moduleFunctionPath){ |
|
353 | - $logger->info('Found helper [' . $function . '] from module [' .$searchModuleName. '], the file path is [' .$moduleFunctionPath. '] we will used it'); |
|
352 | + if ($moduleFunctionPath) { |
|
353 | + $logger->info('Found helper [' . $function . '] from module [' . $searchModuleName . '], the file path is [' . $moduleFunctionPath . '] we will used it'); |
|
354 | 354 | $functionFilePath = $moduleFunctionPath; |
355 | 355 | } |
356 | - else{ |
|
356 | + else { |
|
357 | 357 | $logger->info('Cannot find helper [' . $function . '] from modules using the default location'); |
358 | 358 | } |
359 | - if(! $functionFilePath){ |
|
359 | + if (!$functionFilePath) { |
|
360 | 360 | $searchDir = array(FUNCTIONS_PATH, CORE_FUNCTIONS_PATH); |
361 | - foreach($searchDir as $dir){ |
|
361 | + foreach ($searchDir as $dir) { |
|
362 | 362 | $filePath = $dir . $file; |
363 | - if(file_exists($filePath)){ |
|
363 | + if (file_exists($filePath)) { |
|
364 | 364 | $functionFilePath = $filePath; |
365 | 365 | //is already found not to continue |
366 | 366 | break; |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | } |
369 | 369 | } |
370 | 370 | $logger->info('The helper file path to be loaded is [' . $functionFilePath . ']'); |
371 | - if($functionFilePath){ |
|
371 | + if ($functionFilePath) { |
|
372 | 372 | require_once $functionFilePath; |
373 | 373 | static::$loaded['function_' . $function] = $functionFilePath; |
374 | 374 | $logger->info('Helper [' . $function . '] --> ' . $functionFilePath . ' loaded successfully.'); |
375 | 375 | } |
376 | - else{ |
|
376 | + else { |
|
377 | 377 | show_error('Unable to find helper file [' . $file . ']'); |
378 | 378 | } |
379 | 379 | } |
@@ -385,14 +385,14 @@ discard block |
||
385 | 385 | * |
386 | 386 | * @return void |
387 | 387 | */ |
388 | - public static function config($filename){ |
|
388 | + public static function config($filename) { |
|
389 | 389 | $logger = static::getLogger(); |
390 | 390 | $filename = str_ireplace('.php', '', $filename); |
391 | 391 | $filename = trim($filename, '/\\'); |
392 | 392 | $filename = str_ireplace('config_', '', $filename); |
393 | - $file = 'config_'.$filename.'.php'; |
|
393 | + $file = 'config_' . $filename . '.php'; |
|
394 | 394 | $logger->debug('Loading configuration [' . $filename . '] ...'); |
395 | - if(isset(static::$loaded['config_' . $filename])){ |
|
395 | + if (isset(static::$loaded['config_' . $filename])) { |
|
396 | 396 | $logger->info('Configuration [' . $path . '] already loaded no need to load it again, cost in performance'); |
397 | 397 | return; |
398 | 398 | } |
@@ -402,37 +402,37 @@ discard block |
||
402 | 402 | $searchModuleName = null; |
403 | 403 | $obj = & get_instance(); |
404 | 404 | //check if the request class contains module name |
405 | - if(strpos($filename, '/') !== false){ |
|
405 | + if (strpos($filename, '/') !== false) { |
|
406 | 406 | $path = explode('/', $filename); |
407 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
407 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
408 | 408 | $searchModuleName = $path[0]; |
409 | 409 | $filename = $path[1] . '.php'; |
410 | - $file = $path[0] . DS .$filename; |
|
410 | + $file = $path[0] . DS . $filename; |
|
411 | 411 | } |
412 | 412 | } |
413 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
413 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
414 | 414 | $searchModuleName = $obj->moduleName; |
415 | 415 | } |
416 | 416 | $moduleConfigPath = Module::findConfigFullPath($filename, $searchModuleName); |
417 | - if($moduleConfigPath){ |
|
418 | - $logger->info('Found config [' . $filename . '] from module [' .$searchModuleName. '], the file path is [' .$moduleConfigPath. '] we will used it'); |
|
417 | + if ($moduleConfigPath) { |
|
418 | + $logger->info('Found config [' . $filename . '] from module [' . $searchModuleName . '], the file path is [' . $moduleConfigPath . '] we will used it'); |
|
419 | 419 | $configFilePath = $moduleConfigPath; |
420 | 420 | } |
421 | - else{ |
|
421 | + else { |
|
422 | 422 | $logger->info('Cannot find config [' . $filename . '] from modules using the default location'); |
423 | 423 | } |
424 | 424 | $logger->info('The config file path to be loaded is [' . $configFilePath . ']'); |
425 | - if(file_exists($configFilePath)){ |
|
425 | + if (file_exists($configFilePath)) { |
|
426 | 426 | require_once $configFilePath; |
427 | - if(! empty($config) && is_array($config)){ |
|
427 | + if (!empty($config) && is_array($config)) { |
|
428 | 428 | Config::setAll($config); |
429 | 429 | } |
430 | - else{ |
|
431 | - show_error('No configuration found in ['. $configFilePath . ']'); |
|
430 | + else { |
|
431 | + show_error('No configuration found in [' . $configFilePath . ']'); |
|
432 | 432 | } |
433 | 433 | } |
434 | - else{ |
|
435 | - show_error('Unable to find config file ['. $configFilePath . ']'); |
|
434 | + else { |
|
435 | + show_error('Unable to find config file [' . $configFilePath . ']'); |
|
436 | 436 | } |
437 | 437 | static::$loaded['config_' . $filename] = $configFilePath; |
438 | 438 | $logger->info('Configuration [' . $configFilePath . '] loaded successfully.'); |
@@ -448,14 +448,14 @@ discard block |
||
448 | 448 | * |
449 | 449 | * @return void |
450 | 450 | */ |
451 | - public static function lang($language){ |
|
451 | + public static function lang($language) { |
|
452 | 452 | $logger = static::getLogger(); |
453 | 453 | $language = str_ireplace('.php', '', $language); |
454 | 454 | $language = trim($language, '/\\'); |
455 | 455 | $language = str_ireplace('lang_', '', $language); |
456 | - $file = 'lang_'.$language.'.php'; |
|
456 | + $file = 'lang_' . $language . '.php'; |
|
457 | 457 | $logger->debug('Loading language [' . $language . '] ...'); |
458 | - if(isset(static::$loaded['lang_' . $language])){ |
|
458 | + if (isset(static::$loaded['lang_' . $language])) { |
|
459 | 459 | $logger->info('Language [' . $language . '] already loaded no need to load it again, cost in performance'); |
460 | 460 | return; |
461 | 461 | } |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | $cfgKey = get_config('language_cookie_name'); |
466 | 466 | $objCookie = & class_loader('Cookie'); |
467 | 467 | $cookieLang = $objCookie->get($cfgKey); |
468 | - if($cookieLang){ |
|
468 | + if ($cookieLang) { |
|
469 | 469 | $appLang = $cookieLang; |
470 | 470 | } |
471 | 471 | $languageFilePath = null; |
@@ -474,30 +474,30 @@ discard block |
||
474 | 474 | $searchModuleName = null; |
475 | 475 | $obj = & get_instance(); |
476 | 476 | //check if the request class contains module name |
477 | - if(strpos($language, '/') !== false){ |
|
477 | + if (strpos($language, '/') !== false) { |
|
478 | 478 | $path = explode('/', $language); |
479 | - if(isset($path[0]) && in_array($path[0], Module::getModuleList())){ |
|
479 | + if (isset($path[0]) && in_array($path[0], Module::getModuleList())) { |
|
480 | 480 | $searchModuleName = $path[0]; |
481 | 481 | $language = 'lang_' . $path[1] . '.php'; |
482 | - $file = $path[0] . DS .$language; |
|
482 | + $file = $path[0] . DS . $language; |
|
483 | 483 | } |
484 | 484 | } |
485 | - if(! $searchModuleName && !empty($obj->moduleName)){ |
|
485 | + if (!$searchModuleName && !empty($obj->moduleName)) { |
|
486 | 486 | $searchModuleName = $obj->moduleName; |
487 | 487 | } |
488 | 488 | $moduleLanguagePath = Module::findLanguageFullPath($language, $searchModuleName, $appLang); |
489 | - if($moduleLanguagePath){ |
|
490 | - $logger->info('Found language [' . $language . '] from module [' .$searchModuleName. '], the file path is [' .$moduleLanguagePath. '] we will used it'); |
|
489 | + if ($moduleLanguagePath) { |
|
490 | + $logger->info('Found language [' . $language . '] from module [' . $searchModuleName . '], the file path is [' . $moduleLanguagePath . '] we will used it'); |
|
491 | 491 | $languageFilePath = $moduleLanguagePath; |
492 | 492 | } |
493 | - else{ |
|
493 | + else { |
|
494 | 494 | $logger->info('Cannot find language [' . $language . '] from modules using the default location'); |
495 | 495 | } |
496 | - if(! $languageFilePath){ |
|
496 | + if (!$languageFilePath) { |
|
497 | 497 | $searchDir = array(APP_LANG_PATH, CORE_LANG_PATH); |
498 | - foreach($searchDir as $dir){ |
|
498 | + foreach ($searchDir as $dir) { |
|
499 | 499 | $filePath = $dir . $appLang . DS . $file; |
500 | - if(file_exists($filePath)){ |
|
500 | + if (file_exists($filePath)) { |
|
501 | 501 | $languageFilePath = $filePath; |
502 | 502 | //is already found not to continue |
503 | 503 | break; |
@@ -505,12 +505,12 @@ discard block |
||
505 | 505 | } |
506 | 506 | } |
507 | 507 | $logger->info('The language file path to be loaded is [' . $languageFilePath . ']'); |
508 | - if($languageFilePath){ |
|
508 | + if ($languageFilePath) { |
|
509 | 509 | require_once $languageFilePath; |
510 | - if(! empty($lang) && is_array($lang)){ |
|
511 | - $logger->info('Language file [' .$languageFilePath. '] contains the valid languages keys add them to language list'); |
|
510 | + if (!empty($lang) && is_array($lang)) { |
|
511 | + $logger->info('Language file [' . $languageFilePath . '] contains the valid languages keys add them to language list'); |
|
512 | 512 | //Note: may be here the class 'Lang' not yet loaded |
513 | - $langObj =& class_loader('Lang', 'classes'); |
|
513 | + $langObj = & class_loader('Lang', 'classes'); |
|
514 | 514 | $langObj->addLangMessages($lang); |
515 | 515 | //free the memory |
516 | 516 | unset($lang); |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | static::$loaded['lang_' . $language] = $languageFilePath; |
519 | 519 | $logger->info('Language [' . $language . '] --> ' . $languageFilePath . ' loaded successfully.'); |
520 | 520 | } |
521 | - else{ |
|
521 | + else { |
|
522 | 522 | show_error('Unable to find language file [' . $file . ']'); |
523 | 523 | } |
524 | 524 | } |
@@ -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 FileCache implements CacheInterface{ |
|
27 | + class FileCache implements CacheInterface { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Whether to enable compression of the cache data file. |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | private $logger; |
40 | 40 | |
41 | 41 | |
42 | - public function __construct(Log $logger = null){ |
|
43 | - if(! $this->isSupported()){ |
|
42 | + public function __construct(Log $logger = null) { |
|
43 | + if (!$this->isSupported()) { |
|
44 | 44 | show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.'); |
45 | 45 | } |
46 | 46 | /** |
47 | 47 | * instance of the Log class |
48 | 48 | */ |
49 | - if(is_object($logger)){ |
|
49 | + if (is_object($logger)) { |
|
50 | 50 | $this->logger = $logger; |
51 | 51 | } |
52 | - else{ |
|
53 | - $this->logger =& class_loader('Log', 'classes'); |
|
52 | + else { |
|
53 | + $this->logger = & class_loader('Log', 'classes'); |
|
54 | 54 | $this->logger->setLogger('Library::FileCache'); |
55 | 55 | } |
56 | 56 | |
57 | 57 | //if Zlib extension is not loaded set compressCacheData to false |
58 | - if(! extension_loaded('zlib')){ |
|
58 | + if (!extension_loaded('zlib')) { |
|
59 | 59 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
60 | 60 | $this->compressCacheData = false; |
61 | 61 | } |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | * @param string $key the key to identify the cache data |
67 | 67 | * @return mixed the cache data if exists else return false |
68 | 68 | */ |
69 | - public function get($key){ |
|
70 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
69 | + public function get($key) { |
|
70 | + $this->logger->debug('Getting cache data for key [' . $key . ']'); |
|
71 | 71 | $filePath = $this->getFilePath($key); |
72 | - if(! file_exists($filePath)){ |
|
73 | - $this->logger->info('No cache file found for the key ['. $key .'], return false'); |
|
72 | + if (!file_exists($filePath)) { |
|
73 | + $this->logger->info('No cache file found for the key [' . $key . '], return false'); |
|
74 | 74 | return false; |
75 | 75 | } |
76 | - $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid'); |
|
77 | - $handle = fopen($filePath,'r'); |
|
78 | - if( ! $handle){ |
|
79 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
76 | + $this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid'); |
|
77 | + $handle = fopen($filePath, 'r'); |
|
78 | + if (!$handle) { |
|
79 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
80 | 80 | return false; |
81 | 81 | } |
82 | 82 | // Getting a shared lock |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | $data = file_get_contents($filePath); |
85 | 85 | fclose($handle); |
86 | 86 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
87 | - if (! $data) { |
|
88 | - $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
87 | + if (!$data) { |
|
88 | + $this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false'); |
|
89 | 89 | // If unserializing somehow didn't work out, we'll delete the file |
90 | 90 | unlink($filePath); |
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | if (time() > $data['expire']) { |
94 | - $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
94 | + $this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']'); |
|
95 | 95 | // Unlinking when the file was expired |
96 | 96 | unlink($filePath); |
97 | 97 | return false; |
98 | 98 | } |
99 | - else{ |
|
100 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
99 | + else { |
|
100 | + $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
101 | 101 | return $data['data']; |
102 | 102 | } |
103 | 103 | return false; |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | * @param integer $ttl the cache life time |
112 | 112 | * @return boolean true if success otherwise will return false |
113 | 113 | */ |
114 | - public function set($key, $data, $ttl = 0){ |
|
114 | + public function set($key, $data, $ttl = 0) { |
|
115 | 115 | $expire = time() + $ttl; |
116 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
116 | + $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
117 | 117 | $filePath = $this->getFilePath($key); |
118 | - $handle = fopen($filePath,'w'); |
|
119 | - if( ! $handle){ |
|
120 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
118 | + $handle = fopen($filePath, 'w'); |
|
119 | + if (!$handle) { |
|
120 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | ) |
131 | 131 | ); |
132 | 132 | $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
133 | - if(! $result){ |
|
134 | - $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
133 | + if (!$result) { |
|
134 | + $this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false'); |
|
135 | 135 | fclose($handle); |
136 | 136 | return false; |
137 | 137 | } |
138 | - else{ |
|
139 | - $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
138 | + else { |
|
139 | + $this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']'); |
|
140 | 140 | fclose($handle); |
141 | 141 | chmod($filePath, 0640); |
142 | 142 | return true; |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | * @return boolean true if the cache is delete, false if can't delete |
151 | 151 | * the cache or the cache with the given key not exist |
152 | 152 | */ |
153 | - public function delete($key){ |
|
154 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
153 | + public function delete($key) { |
|
154 | + $this->logger->debug('Deleting of cache data for key [' . $key . ']'); |
|
155 | 155 | $filePath = $this->getFilePath($key); |
156 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
157 | - if(! file_exists($filePath)){ |
|
156 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
157 | + if (!file_exists($filePath)) { |
|
158 | 158 | $this->logger->info('This cache file does not exists skipping'); |
159 | 159 | return false; |
160 | 160 | } |
161 | - else{ |
|
162 | - $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
|
161 | + else { |
|
162 | + $this->logger->info('Found cache file [' . $filePath . '] remove it'); |
|
163 | 163 | @unlink($filePath); |
164 | 164 | return true; |
165 | 165 | } |
@@ -173,25 +173,25 @@ discard block |
||
173 | 173 | * 'expire' => expiration time of the cache (Unix timestamp), |
174 | 174 | * 'ttl' => the time to live of the cache in second |
175 | 175 | */ |
176 | - public function getInfo($key){ |
|
177 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
176 | + public function getInfo($key) { |
|
177 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
178 | 178 | $filePath = $this->getFilePath($key); |
179 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
180 | - if(! file_exists($filePath)){ |
|
179 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
180 | + if (!file_exists($filePath)) { |
|
181 | 181 | $this->logger->info('This cache file does not exists skipping'); |
182 | 182 | return false; |
183 | 183 | } |
184 | - else{ |
|
185 | - $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
|
184 | + else { |
|
185 | + $this->logger->info('Found cache file [' . $filePath . '] check the validity'); |
|
186 | 186 | $data = file_get_contents($filePath); |
187 | 187 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
188 | - if(! $data){ |
|
188 | + if (!$data) { |
|
189 | 189 | $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
190 | 190 | return false; |
191 | 191 | } |
192 | - else{ |
|
192 | + else { |
|
193 | 193 | $this->logger->info('This cache data is OK check for expire'); |
194 | - if(isset($data['expire']) && $data['expire'] > time()){ |
|
194 | + if (isset($data['expire']) && $data['expire'] > time()) { |
|
195 | 195 | $this->logger->info('This cache not yet expired return cache informations'); |
196 | 196 | $info = array( |
197 | 197 | 'mtime' => $data['mtime'], |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | ); |
201 | 201 | return $info; |
202 | 202 | } |
203 | - else{ |
|
203 | + else { |
|
204 | 204 | $this->logger->info('This cache already expired return false'); |
205 | 205 | return false; |
206 | 206 | } |
@@ -212,26 +212,26 @@ discard block |
||
212 | 212 | /** |
213 | 213 | * Used to delete expired cache data |
214 | 214 | */ |
215 | - public function deleteExpiredCache(){ |
|
215 | + public function deleteExpiredCache() { |
|
216 | 216 | $this->logger->debug('Deleting of expired cache files'); |
217 | 217 | $list = glob(CACHE_PATH . '*.cache'); |
218 | - if(! $list){ |
|
218 | + if (!$list) { |
|
219 | 219 | $this->logger->info('No cache files were found skipping'); |
220 | 220 | } |
221 | - else{ |
|
221 | + else { |
|
222 | 222 | $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
223 | 223 | foreach ($list as $file) { |
224 | 224 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
225 | 225 | $data = file_get_contents($file); |
226 | 226 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
227 | - if(! $data){ |
|
227 | + if (!$data) { |
|
228 | 228 | $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
229 | 229 | } |
230 | - else if(time() > $data['expire']){ |
|
230 | + else if (time() > $data['expire']) { |
|
231 | 231 | $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
232 | 232 | @unlink($file); |
233 | 233 | } |
234 | - else{ |
|
234 | + else { |
|
235 | 235 | $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
236 | 236 | } |
237 | 237 | } |
@@ -241,13 +241,13 @@ discard block |
||
241 | 241 | /** |
242 | 242 | * Remove all file from cache folder |
243 | 243 | */ |
244 | - public function clean(){ |
|
244 | + public function clean() { |
|
245 | 245 | $this->logger->debug('Deleting of all cache files'); |
246 | 246 | $list = glob(CACHE_PATH . '*.cache'); |
247 | - if(! $list){ |
|
247 | + if (!$list) { |
|
248 | 248 | $this->logger->info('No cache files were found skipping'); |
249 | 249 | } |
250 | - else{ |
|
250 | + else { |
|
251 | 251 | $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
252 | 252 | foreach ($list as $file) { |
253 | 253 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | /** |
260 | 260 | * @return boolean |
261 | 261 | */ |
262 | - public function isCompressCacheData(){ |
|
262 | + public function isCompressCacheData() { |
|
263 | 263 | return $this->compressCacheData; |
264 | 264 | } |
265 | 265 | |
@@ -268,14 +268,14 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @return self |
270 | 270 | */ |
271 | - public function setCompressCacheData($status = true){ |
|
271 | + public function setCompressCacheData($status = true) { |
|
272 | 272 | //if Zlib extension is not loaded set compressCacheData to false |
273 | - if($status === true && ! extension_loaded('zlib')){ |
|
273 | + if ($status === true && !extension_loaded('zlib')) { |
|
274 | 274 | |
275 | 275 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
276 | 276 | $this->compressCacheData = false; |
277 | 277 | } |
278 | - else{ |
|
278 | + else { |
|
279 | 279 | $this->compressCacheData = $status; |
280 | 280 | } |
281 | 281 | return $this; |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @return bool |
288 | 288 | */ |
289 | - public function isSupported(){ |
|
289 | + public function isSupported() { |
|
290 | 290 | return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH); |
291 | 291 | } |
292 | 292 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * Return the Log instance |
295 | 295 | * @return Log |
296 | 296 | */ |
297 | - public function getLogger(){ |
|
297 | + public function getLogger() { |
|
298 | 298 | return $this->logger; |
299 | 299 | } |
300 | 300 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * Set the log instance |
303 | 303 | * @param Log $logger the log object |
304 | 304 | */ |
305 | - public function setLogger(Log $logger){ |
|
305 | + public function setLogger(Log $logger) { |
|
306 | 306 | $this->logger = $logger; |
307 | 307 | return $this; |
308 | 308 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * @param $key the cache item key |
314 | 314 | * @return string the full cache file path for this key |
315 | 315 | */ |
316 | - private function getFilePath($key){ |
|
316 | + private function getFilePath($key) { |
|
317 | 317 | return CACHE_PATH . md5($key) . '.cache'; |
318 | 318 | } |
319 | 319 | } |
@@ -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 ApcCache implements CacheInterface{ |
|
27 | + class ApcCache implements CacheInterface { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The logger instance |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | private $logger; |
34 | 34 | |
35 | 35 | |
36 | - public function __construct(Log $logger = null){ |
|
37 | - if(! $this->isSupported()){ |
|
36 | + public function __construct(Log $logger = null) { |
|
37 | + if (!$this->isSupported()) { |
|
38 | 38 | show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.'); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * instance of the Log class |
43 | 43 | */ |
44 | - if(is_object($logger)){ |
|
44 | + if (is_object($logger)) { |
|
45 | 45 | $this->logger = $logger; |
46 | 46 | } |
47 | - else{ |
|
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
47 | + else { |
|
48 | + $this->logger = & class_loader('Log', 'classes'); |
|
49 | 49 | $this->logger->setLogger('Library::ApcCache'); |
50 | 50 | } |
51 | 51 | } |
@@ -55,21 +55,21 @@ discard block |
||
55 | 55 | * @param string $key the key to identify the cache data |
56 | 56 | * @return mixed the cache data if exists else return false |
57 | 57 | */ |
58 | - public function get($key){ |
|
59 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
58 | + public function get($key) { |
|
59 | + $this->logger->debug('Getting cache data for key [' . $key . ']'); |
|
60 | 60 | $success = false; |
61 | 61 | $data = apc_fetch($key, $success); |
62 | - if($success === false){ |
|
63 | - $this->logger->info('No cache found for the key ['. $key .'], return false'); |
|
62 | + if ($success === false) { |
|
63 | + $this->logger->info('No cache found for the key [' . $key . '], return false'); |
|
64 | 64 | return false; |
65 | 65 | } |
66 | - else{ |
|
66 | + else { |
|
67 | 67 | $cacheInfo = $this->_getCacheInfo($key); |
68 | 68 | $expire = time(); |
69 | - if($cacheInfo){ |
|
69 | + if ($cacheInfo) { |
|
70 | 70 | $expire = $cacheInfo['creation_time'] + $cacheInfo['ttl']; |
71 | 71 | } |
72 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
72 | + $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
73 | 73 | return $data; |
74 | 74 | } |
75 | 75 | } |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | * @param integer $ttl the cache life time |
83 | 83 | * @return boolean true if success otherwise will return false |
84 | 84 | */ |
85 | - public function set($key, $data, $ttl = 0){ |
|
85 | + public function set($key, $data, $ttl = 0) { |
|
86 | 86 | $expire = time() + $ttl; |
87 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
87 | + $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
88 | 88 | $result = apc_store($key, $data, $ttl); |
89 | - if($result === false){ |
|
90 | - $this->logger->error('Can not write cache data for the key ['. $key .'], return false'); |
|
89 | + if ($result === false) { |
|
90 | + $this->logger->error('Can not write cache data for the key [' . $key . '], return false'); |
|
91 | 91 | return false; |
92 | 92 | } |
93 | - else{ |
|
94 | - $this->logger->info('Cache data saved for the key ['. $key .']'); |
|
93 | + else { |
|
94 | + $this->logger->info('Cache data saved for the key [' . $key . ']'); |
|
95 | 95 | return true; |
96 | 96 | } |
97 | 97 | } |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @return boolean true if the cache is deleted, false if can't delete |
104 | 104 | * the cache or the cache with the given key not exist |
105 | 105 | */ |
106 | - public function delete($key){ |
|
107 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
106 | + public function delete($key) { |
|
107 | + $this->logger->debug('Deleting of cache data for key [' . $key . ']'); |
|
108 | 108 | $cacheInfo = $this->_getCacheInfo($key); |
109 | - if($cacheInfo === false){ |
|
109 | + if ($cacheInfo === false) { |
|
110 | 110 | $this->logger->info('This cache data does not exists skipping'); |
111 | 111 | return false; |
112 | 112 | } |
113 | - else{ |
|
114 | - $this->logger->info('Found cache data for the key [' .$key. '] remove it'); |
|
113 | + else { |
|
114 | + $this->logger->info('Found cache data for the key [' . $key . '] remove it'); |
|
115 | 115 | return apc_delete($key); |
116 | 116 | } |
117 | 117 | return false; |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | * 'expire' => expiration time of the cache (Unix timestamp), |
126 | 126 | * 'ttl' => the time to live of the cache in second |
127 | 127 | */ |
128 | - public function getInfo($key){ |
|
129 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
128 | + public function getInfo($key) { |
|
129 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
130 | 130 | $cacheInfos = $this->_getCacheInfo($key); |
131 | - if($cacheInfos){ |
|
131 | + if ($cacheInfos) { |
|
132 | 132 | $data = array( |
133 | 133 | 'mtime' => $cacheInfos['creation_time'], |
134 | 134 | 'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'], |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | ); |
137 | 137 | return $data; |
138 | 138 | } |
139 | - else{ |
|
139 | + else { |
|
140 | 140 | $this->logger->info('This cache does not exists skipping'); |
141 | 141 | return false; |
142 | 142 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | /** |
147 | 147 | * Used to delete expired cache data |
148 | 148 | */ |
149 | - public function deleteExpiredCache(){ |
|
149 | + public function deleteExpiredCache() { |
|
150 | 150 | //for APC[u] is done automatically |
151 | 151 | return true; |
152 | 152 | } |
@@ -154,14 +154,14 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * Remove all cache data |
156 | 156 | */ |
157 | - public function clean(){ |
|
157 | + public function clean() { |
|
158 | 158 | $this->logger->debug('Deleting of all cache data'); |
159 | 159 | $cacheInfos = apc_cache_info('user'); |
160 | - if(empty($cacheInfos['cache_list'])){ |
|
160 | + if (empty($cacheInfos['cache_list'])) { |
|
161 | 161 | $this->logger->info('No cache data were found skipping'); |
162 | 162 | return false; |
163 | 163 | } |
164 | - else{ |
|
164 | + else { |
|
165 | 165 | $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove'); |
166 | 166 | return apc_clear_cache('user'); |
167 | 167 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - public function isSupported(){ |
|
176 | + public function isSupported() { |
|
177 | 177 | return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled'); |
178 | 178 | } |
179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Return the Log instance |
182 | 182 | * @return Log |
183 | 183 | */ |
184 | - public function getLogger(){ |
|
184 | + public function getLogger() { |
|
185 | 185 | return $this->logger; |
186 | 186 | } |
187 | 187 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * Set the log instance |
190 | 190 | * @param Log $logger the log object |
191 | 191 | */ |
192 | - public function setLogger(Log $logger){ |
|
192 | + public function setLogger(Log $logger) { |
|
193 | 193 | $this->logger = $logger; |
194 | 194 | return $this; |
195 | 195 | } |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | * @param string $key the cache key to get the cache information |
201 | 201 | * @return array |
202 | 202 | */ |
203 | - private function _getCacheInfo($key){ |
|
203 | + private function _getCacheInfo($key) { |
|
204 | 204 | $caches = apc_cache_info('user'); |
205 | - if(! empty($caches['cache_list'])){ |
|
205 | + if (!empty($caches['cache_list'])) { |
|
206 | 206 | $cacheLists = $caches['cache_list']; |
207 | - foreach ($cacheLists as $c){ |
|
208 | - if(isset($c['info']) && $c['info'] === $key){ |
|
207 | + foreach ($cacheLists as $c) { |
|
208 | + if (isset($c['info']) && $c['info'] === $key) { |
|
209 | 209 | return $c; |
210 | 210 | } |
211 | 211 | } |