@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | - class ClasseModel extends Model{ |
|
| 2 | + class ClasseModel extends Model { |
|
| 3 | 3 | |
| 4 | 4 | protected $_table = 'classe'; |
| 5 | 5 | protected $primary_key = 'cls_id'; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
| 38 | 38 | */ |
| 39 | - define('ROOT_PATH', dirname(realpath(__FILE__)) . DS .'..' . DS); |
|
| 39 | + define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS); |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * Custom application path for tests |
| 59 | 59 | */ |
| 60 | - define('APPS_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS); |
|
| 60 | + define('APPS_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * The path to the controller directory of your application. |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
| 194 | 194 | * in HMVC architecture (hierichical, controllers, models, views). |
| 195 | 195 | */ |
| 196 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
| 196 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS); |
|
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | 199 | * The path to the directory of sources external to your application. |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
| 233 | 233 | $_SESSION = array(); |
| 234 | 234 | |
| 235 | - if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
| 235 | + if (!isset($_SERVER['REMOTE_ADDR'])) { |
|
| 236 | 236 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | require_once 'include/autoloader.php'; |
| 241 | 241 | |
| 242 | 242 | //check for composer autoload file if exists include it |
| 243 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
| 243 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
| 244 | 244 | require_once VENDOR_PATH . 'autoload.php'; |
| 245 | 245 | |
| 246 | 246 | //define the class alias for vstream |
@@ -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 | } |