@@ -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,14 +117,14 @@ 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 | die(); |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return mixed the config value |
146 | 146 | */ |
147 | - function get_config($key, $default = null){ |
|
147 | + function get_config($key, $default = null) { |
|
148 | 148 | static $cfg; |
149 | - if(empty($cfg)){ |
|
149 | + if (empty($cfg)) { |
|
150 | 150 | $cfg[0] = & load_configurations(); |
151 | 151 | } |
152 | 152 | return array_key_exists($key, $cfg[0]) ? $cfg[0][$key] : $default; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @codeCoverageIgnore |
162 | 162 | */ |
163 | - function save_to_log($level, $message, $logger = null){ |
|
164 | - $log =& class_loader('Log', 'classes'); |
|
165 | - if($logger){ |
|
163 | + function save_to_log($level, $message, $logger = null) { |
|
164 | + $log = & class_loader('Log', 'classes'); |
|
165 | + if ($logger) { |
|
166 | 166 | $log->setLogger($logger); |
167 | 167 | } |
168 | 168 | $log->writeLog($message, $level); |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @codeCoverageIgnore |
177 | 177 | */ |
178 | - function set_http_status_header($code = 200, $text = null){ |
|
179 | - if(!is_numeric($code) || $code < 0 ){ |
|
178 | + function set_http_status_header($code = 200, $text = null) { |
|
179 | + if (!is_numeric($code) || $code < 0) { |
|
180 | 180 | show_error('HTTP status code must be an integer'); |
181 | 181 | } |
182 | - if(empty($text)){ |
|
182 | + if (empty($text)) { |
|
183 | 183 | $code = abs($code); |
184 | 184 | $http_status = array( |
185 | 185 | 100 => 'Continue', |
@@ -228,18 +228,18 @@ discard block |
||
228 | 228 | 504 => 'Gateway Timeout', |
229 | 229 | 505 => 'HTTP Version Not Supported', |
230 | 230 | ); |
231 | - if(isset($http_status[$code])){ |
|
231 | + if (isset($http_status[$code])) { |
|
232 | 232 | $text = $http_status[$code]; |
233 | 233 | } |
234 | - else{ |
|
234 | + else { |
|
235 | 235 | show_error('No HTTP status text found for your code please check it.'); |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - if(strpos(php_sapi_name(), 'cgi') === 0){ |
|
239 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
240 | 240 | header('Status: ' . $code . ' ' . $text, TRUE); |
241 | 241 | } |
242 | - else{ |
|
242 | + else { |
|
243 | 243 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
244 | 244 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
245 | 245 | } |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @codeCoverageIgnore |
256 | 256 | */ |
257 | - function show_error($msg, $title = 'error', $logging = true){ |
|
257 | + function show_error($msg, $title = 'error', $logging = true) { |
|
258 | 258 | $title = strtoupper($title); |
259 | 259 | $data = array(); |
260 | 260 | $data['error'] = $msg; |
261 | 261 | $data['title'] = $title; |
262 | - if($logging){ |
|
263 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
262 | + if ($logging) { |
|
263 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
264 | 264 | } |
265 | 265 | $response = & class_loader('Response', 'classes'); |
266 | 266 | $response->sendError($data); |
@@ -274,18 +274,18 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return boolean true if the web server uses the https protocol, false if not. |
276 | 276 | */ |
277 | - function is_https(){ |
|
277 | + function is_https() { |
|
278 | 278 | /* |
279 | 279 | * some servers pass the "HTTPS" parameter in the server variable, |
280 | 280 | * if is the case, check if the value is "on", "true", "1". |
281 | 281 | */ |
282 | - if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
282 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
283 | 283 | return true; |
284 | 284 | } |
285 | - else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
285 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
286 | 286 | return true; |
287 | 287 | } |
288 | - else if(isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
288 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
289 | 289 | return true; |
290 | 290 | } |
291 | 291 | return false; |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return boolean true if is a valid URL address or false. |
302 | 302 | */ |
303 | - function is_url($url){ |
|
303 | + function is_url($url) { |
|
304 | 304 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
305 | 305 | } |
306 | 306 | |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | * @param string $controllerClass the controller class name to be loaded |
311 | 311 | * @codeCoverageIgnore |
312 | 312 | */ |
313 | - function autoload_controller($controllerClass){ |
|
314 | - if(file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
313 | + function autoload_controller($controllerClass) { |
|
314 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
315 | 315 | require_once $path; |
316 | 316 | } |
317 | 317 | } |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @return boolean |
327 | 327 | */ |
328 | - function php_exception_handler($ex){ |
|
329 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
330 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
328 | + function php_exception_handler($ex) { |
|
329 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
330 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
331 | 331 | } |
332 | - else{ |
|
332 | + else { |
|
333 | 333 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
334 | 334 | } |
335 | 335 | return true; |
@@ -347,16 +347,16 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @return boolean |
349 | 349 | */ |
350 | - function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){ |
|
350 | + function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) { |
|
351 | 351 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
352 | - if($isError){ |
|
352 | + if ($isError) { |
|
353 | 353 | set_http_status_header(500); |
354 | 354 | } |
355 | - if (! (error_reporting() & $errno)) { |
|
355 | + if (!(error_reporting() & $errno)) { |
|
356 | 356 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
357 | 357 | return; |
358 | 358 | } |
359 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
359 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
360 | 360 | $errorType = 'error'; |
361 | 361 | switch ($errno) { |
362 | 362 | case E_USER_ERROR: |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | $errorType = 'error'; |
373 | 373 | break; |
374 | 374 | } |
375 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
375 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
376 | 376 | } |
377 | - if ($isError){ |
|
377 | + if ($isError) { |
|
378 | 378 | die(); |
379 | 379 | } |
380 | 380 | return true; |
@@ -384,10 +384,10 @@ discard block |
||
384 | 384 | * This function is used to run in shutdown situation of the script |
385 | 385 | * @codeCoverageIgnore |
386 | 386 | */ |
387 | - function php_shudown_handler(){ |
|
387 | + function php_shudown_handler() { |
|
388 | 388 | $lastError = error_get_last(); |
389 | 389 | if (isset($lastError) && |
390 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
390 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
391 | 391 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
392 | 392 | } |
393 | 393 | } |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @return string string of the HTML attribute. |
407 | 407 | */ |
408 | - function attributes_to_string(array $attributes){ |
|
408 | + function attributes_to_string(array $attributes) { |
|
409 | 409 | $str = ' '; |
410 | 410 | //we check that the array passed as an argument is not empty. |
411 | - if(! empty($attributes)){ |
|
412 | - foreach($attributes as $key => $value){ |
|
411 | + if (!empty($attributes)) { |
|
412 | + foreach ($attributes as $key => $value) { |
|
413 | 413 | $key = trim(htmlspecialchars($key)); |
414 | 414 | $value = trim(htmlspecialchars($value)); |
415 | 415 | /* |
@@ -419,10 +419,10 @@ discard block |
||
419 | 419 | * $attr = array('placeholder' => 'I am a "puple"') |
420 | 420 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
421 | 421 | */ |
422 | - if($value && strpos('"', $value) !== false){ |
|
422 | + if ($value && strpos('"', $value) !== false) { |
|
423 | 423 | $value = addslashes($value); |
424 | 424 | } |
425 | - $str .= $key.' = "'.$value.'" '; |
|
425 | + $str .= $key . ' = "' . $value . '" '; |
|
426 | 426 | } |
427 | 427 | } |
428 | 428 | //remove the space after using rtrim() |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | * |
439 | 439 | * @return string the stringfy value |
440 | 440 | */ |
441 | - function stringfy_vars($var){ |
|
441 | + function stringfy_vars($var) { |
|
442 | 442 | return print_r($var, true); |
443 | 443 | } |
444 | 444 | |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | * |
450 | 450 | * @return mixed the sanitize value |
451 | 451 | */ |
452 | - function clean_input($str){ |
|
453 | - if(is_array($str)){ |
|
452 | + function clean_input($str) { |
|
453 | + if (is_array($str)) { |
|
454 | 454 | $str = array_map('clean_input', $str); |
455 | 455 | } |
456 | - else if(is_object($str)){ |
|
456 | + else if (is_object($str)) { |
|
457 | 457 | $obj = $str; |
458 | 458 | foreach ($str as $var => $value) { |
459 | 459 | $obj->$var = clean_input($value); |
460 | 460 | } |
461 | 461 | $str = $obj; |
462 | 462 | } |
463 | - else{ |
|
463 | + else { |
|
464 | 464 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
465 | 465 | } |
466 | 466 | return $str; |
@@ -478,11 +478,11 @@ discard block |
||
478 | 478 | * |
479 | 479 | * @return string the string with the hidden part. |
480 | 480 | */ |
481 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
481 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
482 | 482 | //get the string length |
483 | 483 | $len = strlen($str); |
484 | 484 | //if str is empty |
485 | - if($len <= 0){ |
|
485 | + if ($len <= 0) { |
|
486 | 486 | return str_repeat($hiddenChar, 6); |
487 | 487 | } |
488 | 488 | //if the length is less than startCount and endCount |
@@ -490,14 +490,14 @@ discard block |
||
490 | 490 | //or startCount is negative or endCount is negative |
491 | 491 | //return the full string hidden |
492 | 492 | |
493 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
493 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
494 | 494 | return str_repeat($hiddenChar, $len); |
495 | 495 | } |
496 | 496 | //the start non hidden string |
497 | 497 | $startNonHiddenStr = substr($str, 0, $startCount); |
498 | 498 | //the end non hidden string |
499 | 499 | $endNonHiddenStr = null; |
500 | - if($endCount > 0){ |
|
500 | + if ($endCount > 0) { |
|
501 | 501 | $endNonHiddenStr = substr($str, - $endCount); |
502 | 502 | } |
503 | 503 | //the hidden string |
@@ -510,31 +510,31 @@ discard block |
||
510 | 510 | * This function is used to set the initial session config regarding the configuration |
511 | 511 | * @codeCoverageIgnore |
512 | 512 | */ |
513 | - function set_session_config(){ |
|
513 | + function set_session_config() { |
|
514 | 514 | //$_SESSION is not available on cli mode |
515 | - if(! IS_CLI){ |
|
516 | - $logger =& class_loader('Log', 'classes'); |
|
515 | + if (!IS_CLI) { |
|
516 | + $logger = & class_loader('Log', 'classes'); |
|
517 | 517 | $logger->setLogger('PHPSession'); |
518 | 518 | //set session params |
519 | 519 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
520 | 520 | $sessionName = get_config('session_name'); |
521 | - if($sessionName){ |
|
521 | + if ($sessionName) { |
|
522 | 522 | session_name($sessionName); |
523 | 523 | } |
524 | 524 | $logger->info('Session handler: ' . $sessionHandler); |
525 | 525 | $logger->info('Session name: ' . $sessionName); |
526 | 526 | |
527 | - if($sessionHandler == 'files'){ |
|
527 | + if ($sessionHandler == 'files') { |
|
528 | 528 | $sessionSavePath = get_config('session_save_path'); |
529 | - if($sessionSavePath){ |
|
530 | - if(! is_dir($sessionSavePath)){ |
|
529 | + if ($sessionSavePath) { |
|
530 | + if (!is_dir($sessionSavePath)) { |
|
531 | 531 | mkdir($sessionSavePath, 1773); |
532 | 532 | } |
533 | 533 | session_save_path($sessionSavePath); |
534 | 534 | $logger->info('Session save path: ' . $sessionSavePath); |
535 | 535 | } |
536 | 536 | } |
537 | - else if($sessionHandler == 'database'){ |
|
537 | + else if ($sessionHandler == 'database') { |
|
538 | 538 | //load database session handle library |
539 | 539 | //Model |
540 | 540 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
@@ -542,11 +542,11 @@ discard block |
||
542 | 542 | //Database Session handler Model |
543 | 543 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
544 | 544 | |
545 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
545 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
546 | 546 | session_set_save_handler($DBS, true); |
547 | 547 | $logger->info('session save path: ' . get_config('session_save_path')); |
548 | 548 | } |
549 | - else{ |
|
549 | + else { |
|
550 | 550 | show_error('Invalid session handler configuration'); |
551 | 551 | } |
552 | 552 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | $logger->info('Session lifetime: ' . $lifetime); |
570 | 570 | $logger->info('Session cookie path: ' . $path); |
571 | 571 | $logger->info('Session domain: ' . $domain); |
572 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
572 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
573 | 573 | |
574 | - if((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
574 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
575 | 575 | $logger->info('Session not yet start, start it now'); |
576 | 576 | session_start(); |
577 | 577 | } |
@@ -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,17 +147,17 @@ 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 | 153 | $secret = $this->getSessionSecret(); |
154 | - if(empty($secret)){ |
|
154 | + if (empty($secret)) { |
|
155 | 155 | $secret = get_config('session_secret', false); |
156 | 156 | $this->setSessionSecret($secret); |
157 | 157 | } |
158 | 158 | $this->logger->info('Session secret: ' . $secret); |
159 | 159 | |
160 | - if(! $this->getModelInstance()){ |
|
160 | + if (!$this->getModelInstance()) { |
|
161 | 161 | $this->setModelInstanceFromConfig(); |
162 | 162 | } |
163 | 163 | $this->setInitializerVector($secret); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | //set session tables columns |
166 | 166 | $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns(); |
167 | 167 | |
168 | - if(empty($this->sessionTableColumns)){ |
|
168 | + if (empty($this->sessionTableColumns)) { |
|
169 | 169 | show_error('The session handler is "database" but the table columns not set'); |
170 | 170 | } |
171 | 171 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Close the session |
182 | 182 | * @return boolean |
183 | 183 | */ |
184 | - public function close(){ |
|
184 | + public function close() { |
|
185 | 185 | $this->logger->debug('Closing database session handler'); |
186 | 186 | return true; |
187 | 187 | } |
@@ -191,28 +191,28 @@ discard block |
||
191 | 191 | * @param string $sid the session id to use |
192 | 192 | * @return string the session data in serialiaze format |
193 | 193 | */ |
194 | - public function read($sid){ |
|
194 | + public function read($sid) { |
|
195 | 195 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
196 | 196 | $instance = $this->getModelInstance(); |
197 | 197 | $columns = $this->sessionTableColumns; |
198 | - if($this->getLoader()){ |
|
198 | + if ($this->getLoader()) { |
|
199 | 199 | $this->getLoader()->functions('user_agent'); |
200 | 200 | $this->getLoader()->library('Browser'); |
201 | 201 | } |
202 | - else{ |
|
202 | + else { |
|
203 | 203 | Loader::functions('user_agent'); |
204 | 204 | Loader::library('Browser'); |
205 | 205 | } |
206 | 206 | |
207 | 207 | $ip = get_ip(); |
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 null; |
@@ -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 integer $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 object 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 object 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 object 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 |
@@ -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,7 +182,7 @@ 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); |
@@ -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,17 +878,17 @@ 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); |
@@ -943,7 +943,7 @@ discard block |
||
943 | 943 | { |
944 | 944 | $this->_database->where($params[0]); |
945 | 945 | } |
946 | - else if(count($params) == 2) |
|
946 | + else if (count($params) == 2) |
|
947 | 947 | { |
948 | 948 | if (is_array($params[1])) |
949 | 949 | { |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | $this->_database->where($params[0], $params[1]); |
955 | 955 | } |
956 | 956 | } |
957 | - else if(count($params) == 3) |
|
957 | + else if (count($params) == 3) |
|
958 | 958 | { |
959 | 959 | $this->_database->where($params[0], $params[1], $params[2]); |
960 | 960 | } |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | /** |
975 | 975 | Shortcut to controller |
976 | 976 | */ |
977 | - public function __get($key){ |
|
977 | + public function __get($key) { |
|
978 | 978 | return get_instance()->{$key}; |
979 | 979 | } |
980 | 980 |
@@ -92,36 +92,36 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * Construct the new Router instance |
94 | 94 | */ |
95 | - public function __construct(){ |
|
96 | - $this->logger =& class_loader('Log', 'classes'); |
|
95 | + public function __construct() { |
|
96 | + $this->logger = & class_loader('Log', 'classes'); |
|
97 | 97 | $this->logger->setLogger('Library::Router'); |
98 | 98 | $routesPath = CONFIG_PATH . 'routes.php'; |
99 | 99 | $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...'); |
100 | - if(file_exists($routesPath)){ |
|
101 | - $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it'); |
|
100 | + if (file_exists($routesPath)) { |
|
101 | + $this->logger->info('Found routes configuration file --> ' . $routesPath . ' now load it'); |
|
102 | 102 | require_once $routesPath; |
103 | - if(! empty($route) && is_array($route)){ |
|
103 | + if (!empty($route) && is_array($route)) { |
|
104 | 104 | $this->routes = $route; |
105 | 105 | unset($route); |
106 | 106 | } |
107 | 107 | } |
108 | - else{ |
|
108 | + else { |
|
109 | 109 | show_error('Unable to find the routes configuration file [' . $routesPath . ']'); |
110 | 110 | } |
111 | 111 | |
112 | 112 | //loading routes for module |
113 | 113 | $this->logger->debug('Loading of modules routes ... '); |
114 | 114 | $modulesRoutes = Module::getModulesRoutes(); |
115 | - if($modulesRoutes && is_array($modulesRoutes)){ |
|
115 | + if ($modulesRoutes && is_array($modulesRoutes)) { |
|
116 | 116 | $this->routes = array_merge($this->routes, $modulesRoutes); |
117 | 117 | $this->logger->info('Routes for all modules loaded successfully'); |
118 | 118 | } |
119 | - else{ |
|
119 | + else { |
|
120 | 120 | $this->logger->info('No routes found for all modules skipping.'); |
121 | 121 | } |
122 | 122 | $this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes)); |
123 | 123 | |
124 | - foreach($this->routes as $pattern => $callback){ |
|
124 | + foreach ($this->routes as $pattern => $callback) { |
|
125 | 125 | $this->add($pattern, $callback); |
126 | 126 | } |
127 | 127 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; |
130 | 130 | $this->logger->debug('Check if URL suffix is enabled in the configuration'); |
131 | 131 | //remove url suffix from the request URI |
132 | - if($suffix = get_config('url_suffix')){ |
|
133 | - $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' ); |
|
132 | + if ($suffix = get_config('url_suffix')) { |
|
133 | + $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']'); |
|
134 | 134 | $uri = str_ireplace($suffix, '', $uri); |
135 | 135 | } |
136 | - else{ |
|
136 | + else { |
|
137 | 137 | $this->logger->info('URL suffix is not enabled in the configuration'); |
138 | 138 | } |
139 | - if(strpos($uri, '?') !== false){ |
|
139 | + if (strpos($uri, '?') !== false) { |
|
140 | 140 | $uri = substr($uri, 0, strpos($uri, '?')); |
141 | 141 | } |
142 | 142 | $uri = trim($uri, $this->uriTrim); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function add($uri, $callback) { |
153 | 153 | $uri = trim($uri, $this->uriTrim); |
154 | - if(in_array($uri, $this->pattern)){ |
|
154 | + if (in_array($uri, $this->pattern)) { |
|
155 | 155 | $this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict'); |
156 | 156 | } |
157 | 157 | $this->pattern[] = $uri; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * Get the module name |
163 | 163 | * @return string |
164 | 164 | */ |
165 | - public function getModule(){ |
|
165 | + public function getModule() { |
|
166 | 166 | return $this->module; |
167 | 167 | } |
168 | 168 | |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * Get the controller name |
171 | 171 | * @return string |
172 | 172 | */ |
173 | - public function getController(){ |
|
173 | + public function getController() { |
|
174 | 174 | return $this->controller; |
175 | 175 | } |
176 | 176 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * Get the controller file path |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - public function getControllerPath(){ |
|
181 | + public function getControllerPath() { |
|
182 | 182 | return $this->controllerPath; |
183 | 183 | } |
184 | 184 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * Get the controller method |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - public function getMethod(){ |
|
189 | + public function getMethod() { |
|
190 | 190 | return $this->method; |
191 | 191 | } |
192 | 192 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * Get the request arguments |
195 | 195 | * @return array |
196 | 196 | */ |
197 | - public function getArgs(){ |
|
197 | + public function getArgs() { |
|
198 | 198 | return $this->args; |
199 | 199 | } |
200 | 200 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * Get the URL segments array |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - public function getSegments(){ |
|
205 | + public function getSegments() { |
|
206 | 206 | return $this->segments; |
207 | 207 | } |
208 | 208 | |
@@ -211,27 +211,27 @@ discard block |
||
211 | 211 | * otherwise send 404 error. |
212 | 212 | */ |
213 | 213 | public function run() { |
214 | - $benchmark =& class_loader('Benchmark'); |
|
214 | + $benchmark = & class_loader('Benchmark'); |
|
215 | 215 | $benchmark->mark('ROUTING_PROCESS_START'); |
216 | 216 | $this->logger->debug('Routing process start ...'); |
217 | 217 | $segment = $this->segments; |
218 | 218 | $baseUrl = get_config('base_url'); |
219 | 219 | //check if the app is not in DOCUMENT_ROOT |
220 | - if(isset($segment[0]) && stripos($baseUrl, $segment[0]) != false){ |
|
220 | + if (isset($segment[0]) && stripos($baseUrl, $segment[0]) != false) { |
|
221 | 221 | array_shift($segment); |
222 | 222 | $this->segments = $segment; |
223 | 223 | } |
224 | 224 | $this->logger->debug('Check if the request URI contains the front controller'); |
225 | - if(isset($segment[0]) && $segment[0] == SELF){ |
|
225 | + if (isset($segment[0]) && $segment[0] == SELF) { |
|
226 | 226 | $this->logger->info('The request URI contains the front controller'); |
227 | 227 | array_shift($segment); |
228 | 228 | $this->segments = $segment; |
229 | 229 | } |
230 | - else{ |
|
230 | + else { |
|
231 | 231 | $this->logger->info('The request URI does not contain the front controller'); |
232 | 232 | } |
233 | 233 | $uri = implode('/', $segment); |
234 | - $this->logger->info('The final Request URI is [' . $uri . ']' ); |
|
234 | + $this->logger->info('The final Request URI is [' . $uri . ']'); |
|
235 | 235 | //generic routes |
236 | 236 | $pattern = array(':num', ':alpha', ':alnum', ':any'); |
237 | 237 | $replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*'); |
@@ -245,20 +245,20 @@ discard block |
||
245 | 245 | array_shift($args); |
246 | 246 | //check if this contains an module |
247 | 247 | $moduleControllerMethod = explode('#', $this->callback[$index]); |
248 | - if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){ |
|
249 | - $this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']'); |
|
248 | + if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) { |
|
249 | + $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']'); |
|
250 | 250 | $this->module = $moduleControllerMethod[0]; |
251 | 251 | $moduleControllerMethod = explode('@', $moduleControllerMethod[1]); |
252 | 252 | } |
253 | - else{ |
|
253 | + else { |
|
254 | 254 | $this->logger->info('The current request does not use the module'); |
255 | 255 | $moduleControllerMethod = explode('@', $this->callback[$index]); |
256 | 256 | } |
257 | - if(is_array($moduleControllerMethod)){ |
|
258 | - if(isset($moduleControllerMethod[0])){ |
|
257 | + if (is_array($moduleControllerMethod)) { |
|
258 | + if (isset($moduleControllerMethod[0])) { |
|
259 | 259 | $this->controller = $moduleControllerMethod[0]; |
260 | 260 | } |
261 | - if(isset($moduleControllerMethod[1])){ |
|
261 | + if (isset($moduleControllerMethod[1])) { |
|
262 | 262 | $this->method = $moduleControllerMethod[1]; |
263 | 263 | } |
264 | 264 | $this->args = $args; |
@@ -268,73 +268,73 @@ discard block |
||
268 | 268 | } |
269 | 269 | } |
270 | 270 | //first if the controller is not set and the module is set use the module name as the controller |
271 | - if(! $this->getController() && $this->getModule()){ |
|
271 | + if (!$this->getController() && $this->getModule()) { |
|
272 | 272 | $this->logger->info('After loop in predefined routes configuration, the module name is set but the controller is not set, so we will use module as the controller'); |
273 | 273 | $this->controller = $this->getModule(); |
274 | 274 | } |
275 | 275 | //if can not determine the module/controller/method via the defined routes configuration we will use |
276 | 276 | //the URL like http://domain.com/module/controller/method/arg1/arg2 |
277 | - if(! $this->getController()){ |
|
277 | + if (!$this->getController()) { |
|
278 | 278 | $this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters'); |
279 | 279 | $nbSegment = count($segment); |
280 | 280 | //if segment is null so means no need to perform |
281 | - if($nbSegment > 0){ |
|
281 | + if ($nbSegment > 0) { |
|
282 | 282 | //get the module list |
283 | 283 | $modules = Module::getModuleList(); |
284 | 284 | //first check if no module |
285 | - if(! $modules){ |
|
285 | + if (!$modules) { |
|
286 | 286 | $this->logger->info('No module was loaded will skip the module checking'); |
287 | 287 | //the application don't use module |
288 | 288 | //controller |
289 | - if(isset($segment[0])){ |
|
289 | + if (isset($segment[0])) { |
|
290 | 290 | $this->controller = $segment[0]; |
291 | 291 | array_shift($segment); |
292 | 292 | } |
293 | 293 | //method |
294 | - if(isset($segment[0])){ |
|
294 | + if (isset($segment[0])) { |
|
295 | 295 | $this->method = $segment[0]; |
296 | 296 | array_shift($segment); |
297 | 297 | } |
298 | 298 | //args |
299 | 299 | $this->args = $segment; |
300 | 300 | } |
301 | - else{ |
|
301 | + else { |
|
302 | 302 | $this->logger->info('The application contains a loaded module will check if the current request is found in the module list'); |
303 | - if(in_array($segment[0], $modules)){ |
|
303 | + if (in_array($segment[0], $modules)) { |
|
304 | 304 | $this->logger->info('Found, the current request use the module [' . $segment[0] . ']'); |
305 | 305 | $this->module = $segment[0]; |
306 | 306 | array_shift($segment); |
307 | 307 | //check if the second arg is the controller from module |
308 | - if(isset($segment[0])){ |
|
308 | + if (isset($segment[0])) { |
|
309 | 309 | $this->controller = $segment[0]; |
310 | 310 | //check if the request use the same module name and controller |
311 | 311 | $path = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
312 | - if(! $path){ |
|
312 | + if (!$path) { |
|
313 | 313 | $this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller'); |
314 | 314 | $this->controller = $this->getModule(); |
315 | 315 | } |
316 | - else{ |
|
316 | + else { |
|
317 | 317 | $this->controllerPath = $path; |
318 | 318 | array_shift($segment); |
319 | 319 | } |
320 | 320 | } |
321 | 321 | //check for method |
322 | - if(isset($segment[0])){ |
|
322 | + if (isset($segment[0])) { |
|
323 | 323 | $this->method = $segment[0]; |
324 | 324 | array_shift($segment); |
325 | 325 | } |
326 | 326 | //the remaining is for args |
327 | 327 | $this->args = $segment; |
328 | 328 | } |
329 | - else{ |
|
329 | + else { |
|
330 | 330 | $this->logger->info('The current request information is not found in the module list'); |
331 | 331 | //controller |
332 | - if(isset($segment[0])){ |
|
332 | + if (isset($segment[0])) { |
|
333 | 333 | $this->controller = $segment[0]; |
334 | 334 | array_shift($segment); |
335 | 335 | } |
336 | 336 | //method |
337 | - if(isset($segment[0])){ |
|
337 | + if (isset($segment[0])) { |
|
338 | 338 | $this->method = $segment[0]; |
339 | 339 | array_shift($segment); |
340 | 340 | } |
@@ -344,18 +344,18 @@ discard block |
||
344 | 344 | } |
345 | 345 | } |
346 | 346 | } |
347 | - if(! $this->getController() && $this->getModule()){ |
|
347 | + if (!$this->getController() && $this->getModule()) { |
|
348 | 348 | $this->logger->info('After using the request URI the module name is set but the controller is not set so we will use module as the controller'); |
349 | 349 | $this->controller = $this->getModule(); |
350 | 350 | } |
351 | 351 | //did we set the controller, so set the controller path |
352 | - if($this->getController() && ! $this->getControllerPath()){ |
|
352 | + if ($this->getController() && !$this->getControllerPath()) { |
|
353 | 353 | $this->logger->debug('Setting the file path for the controller [' . $this->getController() . ']'); |
354 | 354 | //if it is the module controller |
355 | - if($this->getModule()){ |
|
355 | + if ($this->getModule()) { |
|
356 | 356 | $this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
357 | 357 | } |
358 | - else{ |
|
358 | + else { |
|
359 | 359 | $this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php'; |
360 | 360 | } |
361 | 361 | } |
@@ -365,20 +365,20 @@ discard block |
||
365 | 365 | $this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...'); |
366 | 366 | $benchmark->mark('ROUTING_PROCESS_END'); |
367 | 367 | $e404 = false; |
368 | - if(file_exists($classFilePath)){ |
|
368 | + if (file_exists($classFilePath)) { |
|
369 | 369 | require_once $classFilePath; |
370 | - if(! class_exists($controller, false)){ |
|
370 | + if (!class_exists($controller, false)) { |
|
371 | 371 | $e404 = true; |
372 | - $this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']'); |
|
372 | + $this->logger->info('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']'); |
|
373 | 373 | } |
374 | - else{ |
|
374 | + else { |
|
375 | 375 | $controllerInstance = new $controller(); |
376 | 376 | $controllerMethod = $this->getMethod(); |
377 | - if(! method_exists($controllerInstance, $controllerMethod)){ |
|
377 | + if (!method_exists($controllerInstance, $controllerMethod)) { |
|
378 | 378 | $e404 = true; |
379 | 379 | $this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']'); |
380 | 380 | } |
381 | - else{ |
|
381 | + else { |
|
382 | 382 | $this->logger->info('Routing data is set correctly now GO!'); |
383 | 383 | call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs()); |
384 | 384 | $obj = & get_instance(); |
@@ -388,12 +388,12 @@ discard block |
||
388 | 388 | } |
389 | 389 | } |
390 | 390 | } |
391 | - else{ |
|
391 | + else { |
|
392 | 392 | $this->logger->info('The controller file path [' . $classFilePath . '] does not exist'); |
393 | 393 | $e404 = true; |
394 | 394 | } |
395 | - if($e404){ |
|
396 | - $response =& class_loader('Response', 'classes'); |
|
395 | + if ($e404) { |
|
396 | + $response = & class_loader('Response', 'classes'); |
|
397 | 397 | $response->send404(); |
398 | 398 | } |
399 | 399 | } |
@@ -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 Log{ |
|
27 | + class Log { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The defined constante for Log level |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Create new Log instance |
54 | 54 | */ |
55 | - public function __construct(){ |
|
55 | + public function __construct() { |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Set the logger to identify each message in the log |
60 | 60 | * @param string $logger the logger name |
61 | 61 | */ |
62 | - public function setLogger($logger){ |
|
62 | + public function setLogger($logger) { |
|
63 | 63 | $this->logger = $logger; |
64 | 64 | } |
65 | 65 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @see Log::writeLog for more detail |
69 | 69 | * @param string $message the log message to save |
70 | 70 | */ |
71 | - public function fatal($message){ |
|
71 | + public function fatal($message) { |
|
72 | 72 | $this->writeLog($message, self::FATAL); |
73 | 73 | } |
74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @see Log::writeLog for more detail |
78 | 78 | * @param string $message the log message to save |
79 | 79 | */ |
80 | - public function error($message){ |
|
80 | + public function error($message) { |
|
81 | 81 | $this->writeLog($message, self::ERROR); |
82 | 82 | } |
83 | 83 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @see Log::writeLog for more detail |
87 | 87 | * @param string $message the log message to save |
88 | 88 | */ |
89 | - public function warning($message){ |
|
89 | + public function warning($message) { |
|
90 | 90 | $this->writeLog($message, self::WARNING); |
91 | 91 | } |
92 | 92 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @see Log::writeLog for more detail |
96 | 96 | * @param string $message the log message to save |
97 | 97 | */ |
98 | - public function info($message){ |
|
98 | + public function info($message) { |
|
99 | 99 | $this->writeLog($message, self::INFO); |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @see Log::writeLog for more detail |
105 | 105 | * @param string $message the log message to save |
106 | 106 | */ |
107 | - public function debug($message){ |
|
107 | + public function debug($message) { |
|
108 | 108 | $this->writeLog($message, self::DEBUG); |
109 | 109 | } |
110 | 110 | |
@@ -115,59 +115,59 @@ discard block |
||
115 | 115 | * @param integer|string $level the log level in integer or string format, if is string will convert into integer |
116 | 116 | * to allow check the log level threshold. |
117 | 117 | */ |
118 | - public function writeLog($message, $level = self::INFO){ |
|
118 | + public function writeLog($message, $level = self::INFO) { |
|
119 | 119 | $configLogLevel = get_config('log_level'); |
120 | - if(! $configLogLevel){ |
|
120 | + if (!$configLogLevel) { |
|
121 | 121 | //so means no need log just stop here |
122 | 122 | return; |
123 | 123 | } |
124 | 124 | //check config log level |
125 | - if(! self::isValidConfigLevel($configLogLevel)){ |
|
125 | + if (!self::isValidConfigLevel($configLogLevel)) { |
|
126 | 126 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
127 | 127 | show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false); |
128 | 128 | } |
129 | 129 | |
130 | 130 | //check if config log_logger_name is set |
131 | - if($this->logger){ |
|
131 | + if ($this->logger) { |
|
132 | 132 | $configLoggerName = get_config('log_logger_name', ''); |
133 | - if($configLoggerName){ |
|
134 | - if (is_array($configLoggerName)){ |
|
133 | + if ($configLoggerName) { |
|
134 | + if (is_array($configLoggerName)) { |
|
135 | 135 | //for best comparaison put all string to lowercase |
136 | 136 | $configLoggerName = array_map('strtolower', $configLoggerName); |
137 | - if(! in_array(strtolower($this->logger), $configLoggerName)){ |
|
137 | + if (!in_array(strtolower($this->logger), $configLoggerName)) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | } |
141 | - else if(strtolower($this->logger) !== strtolower($configLoggerName)){ |
|
141 | + else if (strtolower($this->logger) !== strtolower($configLoggerName)) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | 147 | //if $level is not an integer |
148 | - if(! is_numeric($level)){ |
|
148 | + if (!is_numeric($level)) { |
|
149 | 149 | $level = self::getLevelValue($level); |
150 | 150 | } |
151 | 151 | |
152 | 152 | //check if can logging regarding the log level config |
153 | 153 | $configLevel = self::getLevelValue($configLogLevel); |
154 | - if($configLevel > $level){ |
|
154 | + if ($configLevel > $level) { |
|
155 | 155 | //can't log |
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $logSavePath = get_config('log_save_path'); |
160 | - if(! $logSavePath){ |
|
160 | + if (!$logSavePath) { |
|
161 | 161 | $logSavePath = LOGS_PATH; |
162 | 162 | } |
163 | 163 | |
164 | - if(! is_dir($logSavePath) || !is_writable($logSavePath)){ |
|
164 | + if (!is_dir($logSavePath) || !is_writable($logSavePath)) { |
|
165 | 165 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
166 | 166 | show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false); |
167 | 167 | } |
168 | 168 | |
169 | 169 | $path = $logSavePath . 'logs-' . date('Y-m-d') . '.log'; |
170 | - if(! file_exists($path)){ |
|
170 | + if (!file_exists($path)) { |
|
171 | 171 | touch($path); |
172 | 172 | } |
173 | 173 | //may be at this time helper user_agent not yet included |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | $str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n"; |
191 | 191 | $fp = fopen($path, 'a+'); |
192 | - if(is_resource($fp)){ |
|
192 | + if (is_resource($fp)) { |
|
193 | 193 | flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed |
194 | 194 | fwrite($fp, $str); |
195 | 195 | fclose($fp); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return boolean true if the given log level is valid, false if not |
205 | 205 | */ |
206 | - private static function isValidConfigLevel($level){ |
|
206 | + private static function isValidConfigLevel($level) { |
|
207 | 207 | $level = strtolower($level); |
208 | 208 | return in_array($level, self::$validConfigLevel); |
209 | 209 | } |
@@ -213,27 +213,27 @@ discard block |
||
213 | 213 | * @param string $level the log level in string format |
214 | 214 | * @return int the log level in integer format using the predefinied constants |
215 | 215 | */ |
216 | - private static function getLevelValue($level){ |
|
216 | + private static function getLevelValue($level) { |
|
217 | 217 | $level = strtolower($level); |
218 | 218 | $value = self::NONE; |
219 | 219 | |
220 | 220 | //the default value is NONE, so means no need test for NONE |
221 | - if($level == 'fatal'){ |
|
221 | + if ($level == 'fatal') { |
|
222 | 222 | $value = self::FATAL; |
223 | 223 | } |
224 | - else if($level == 'error'){ |
|
224 | + else if ($level == 'error') { |
|
225 | 225 | $value = self::ERROR; |
226 | 226 | } |
227 | - else if($level == 'warning' || $level == 'warn'){ |
|
227 | + else if ($level == 'warning' || $level == 'warn') { |
|
228 | 228 | $value = self::WARNING; |
229 | 229 | } |
230 | - else if($level == 'info'){ |
|
230 | + else if ($level == 'info') { |
|
231 | 231 | $value = self::INFO; |
232 | 232 | } |
233 | - else if($level == 'debug'){ |
|
233 | + else if ($level == 'debug') { |
|
234 | 234 | $value = self::DEBUG; |
235 | 235 | } |
236 | - else if($level == 'all'){ |
|
236 | + else if ($level == 'all') { |
|
237 | 237 | $value = self::ALL; |
238 | 238 | } |
239 | 239 | return $value; |
@@ -244,23 +244,23 @@ discard block |
||
244 | 244 | * @param integer $level the log level in integer format |
245 | 245 | * @return string the log level in string format |
246 | 246 | */ |
247 | - private static function getLevelName($level){ |
|
247 | + private static function getLevelName($level) { |
|
248 | 248 | $value = ''; |
249 | 249 | |
250 | 250 | //the default value is NONE, so means no need test for NONE |
251 | - if($level == self::FATAL){ |
|
251 | + if ($level == self::FATAL) { |
|
252 | 252 | $value = 'FATAL'; |
253 | 253 | } |
254 | - else if($level == self::ERROR){ |
|
254 | + else if ($level == self::ERROR) { |
|
255 | 255 | $value = 'ERROR'; |
256 | 256 | } |
257 | - else if($level == self::WARNING){ |
|
257 | + else if ($level == self::WARNING) { |
|
258 | 258 | $value = 'WARNING'; |
259 | 259 | } |
260 | - else if($level == self::INFO){ |
|
260 | + else if ($level == self::INFO) { |
|
261 | 261 | $value = 'INFO'; |
262 | 262 | } |
263 | - else if($level == self::DEBUG){ |
|
263 | + else if ($level == self::DEBUG) { |
|
264 | 264 | $value = 'DEBUG'; |
265 | 265 | } |
266 | 266 | //no need for ALL |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * For application languages management |
29 | 29 | */ |
30 | - class Lang{ |
|
30 | + class Lang { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The supported available language for this application. |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * Construct new Lang instance |
69 | 69 | */ |
70 | - public function __construct(){ |
|
71 | - $this->logger =& class_loader('Log', 'classes'); |
|
70 | + public function __construct() { |
|
71 | + $this->logger = & class_loader('Log', 'classes'); |
|
72 | 72 | $this->logger->setLogger('Library::Lang'); |
73 | 73 | |
74 | 74 | $this->default = get_config('default_language', 'en'); |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | |
77 | 77 | //add the supported languages ('key', 'display name') |
78 | 78 | $languages = get_config('languages', null); |
79 | - if(! empty($languages)){ |
|
80 | - foreach($languages as $key => $displayName){ |
|
79 | + if (!empty($languages)) { |
|
80 | + foreach ($languages as $key => $displayName) { |
|
81 | 81 | $this->addLang($key, $displayName); |
82 | 82 | } |
83 | 83 | } |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | |
86 | 86 | //if the language exists in cookie use it |
87 | 87 | $cfgKey = get_config('language_cookie_name'); |
88 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
88 | + $this->logger->debug('Getting current language from cookie [' . $cfgKey . ']'); |
|
89 | 89 | $objCookie = & class_loader('Cookie'); |
90 | 90 | $cookieLang = $objCookie->get($cfgKey); |
91 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
91 | + if ($cookieLang && $this->isValid($cookieLang)) { |
|
92 | 92 | $this->current = $cookieLang; |
93 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
93 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is valid so we will set the language using the cookie value [' . $cookieLang . ']'); |
|
94 | 94 | } |
95 | - else{ |
|
96 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
95 | + else { |
|
96 | + $this->logger->info('Language from cookie [' . $cfgKey . '] is not set, use the default value [' . $this->getDefault() . ']'); |
|
97 | 97 | $this->current = $this->getDefault(); |
98 | 98 | } |
99 | 99 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array the language message list |
105 | 105 | */ |
106 | - public function getAll(){ |
|
106 | + public function getAll() { |
|
107 | 107 | return $this->languages; |
108 | 108 | } |
109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param string $key the language key to identify |
114 | 114 | * @param string $value the language message value |
115 | 115 | */ |
116 | - public function set($key, $value){ |
|
116 | + public function set($key, $value) { |
|
117 | 117 | $this->languages[$key] = $value; |
118 | 118 | } |
119 | 119 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return string the language message value |
127 | 127 | */ |
128 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
129 | - if(isset($this->languages[$key])){ |
|
128 | + public function get($key, $default = 'LANGUAGE_ERROR') { |
|
129 | + if (isset($this->languages[$key])) { |
|
130 | 130 | return $this->languages[$key]; |
131 | 131 | } |
132 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
132 | + $this->logger->warning('Language key [' . $key . '] does not exist use the default value [' . $default . ']'); |
|
133 | 133 | return $default; |
134 | 134 | } |
135 | 135 | |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return boolean true if the language directory exists, false or not |
142 | 142 | */ |
143 | - public function isValid($language){ |
|
143 | + public function isValid($language) { |
|
144 | 144 | $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
145 | - foreach($searchDir as $dir){ |
|
146 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
145 | + foreach ($searchDir as $dir) { |
|
146 | + if (file_exists($dir . $language) && is_dir($dir . $language)) { |
|
147 | 147 | return true; |
148 | 148 | } |
149 | 149 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return string the default language |
157 | 157 | */ |
158 | - public function getDefault(){ |
|
158 | + public function getDefault() { |
|
159 | 159 | return $this->default; |
160 | 160 | } |
161 | 161 | |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return string the current language |
166 | 166 | */ |
167 | - public function getCurrent(){ |
|
167 | + public function getCurrent() { |
|
168 | 168 | return $this->current; |
169 | 169 | } |
170 | 170 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | * @param string $name the short language name like "en", "fr". |
175 | 175 | * @param string $description the human readable description of this language |
176 | 176 | */ |
177 | - public function addLang($name, $description){ |
|
178 | - if(isset($this->availables[$name])){ |
|
177 | + public function addLang($name, $description) { |
|
178 | + if (isset($this->availables[$name])) { |
|
179 | 179 | return; //already added cost in performance |
180 | 180 | } |
181 | - if($this->isValid($name)){ |
|
181 | + if ($this->isValid($name)) { |
|
182 | 182 | $this->availables[$name] = $description; |
183 | 183 | } |
184 | - else{ |
|
184 | + else { |
|
185 | 185 | show_error('The language [' . $name . '] is not valid or does not exists.'); |
186 | 186 | } |
187 | 187 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return array the list of the application language |
193 | 193 | */ |
194 | - public function getSupported(){ |
|
194 | + public function getSupported() { |
|
195 | 195 | return $this->availables; |
196 | 196 | } |
197 | 197 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @param array $langs the languages array of the messages to be added |
202 | 202 | */ |
203 | - public function addLangMessages(array $langs){ |
|
203 | + public function addLangMessages(array $langs) { |
|
204 | 204 | foreach ($langs as $key => $value) { |
205 | 205 | $this->set($key, $value); |
206 | 206 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * along with this program; if not, write to the Free Software |
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | - class Session{ |
|
26 | + class Session { |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * The session flash key to use |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | * Get the logger singleton instance |
42 | 42 | * @return Log the logger instance |
43 | 43 | */ |
44 | - private static function getLogger(){ |
|
45 | - if(self::$logger == null){ |
|
46 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
44 | + private static function getLogger() { |
|
45 | + if (self::$logger == null) { |
|
46 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
47 | 47 | self::$logger[0]->setLogger('Library::Session'); |
48 | 48 | } |
49 | 49 | return self::$logger[0]; |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | * @param mixed $default the default value to use if can not find the session item in the list |
56 | 56 | * @return mixed the session value if exist or the default value |
57 | 57 | */ |
58 | - public static function get($item, $default = null){ |
|
58 | + public static function get($item, $default = null) { |
|
59 | 59 | $logger = self::getLogger(); |
60 | - $logger->debug('Getting session data for item [' .$item. '] ...'); |
|
61 | - if(array_key_exists($item, $_SESSION)){ |
|
60 | + $logger->debug('Getting session data for item [' . $item . '] ...'); |
|
61 | + if (array_key_exists($item, $_SESSION)) { |
|
62 | 62 | $logger->info('Found session data for item [' . $item . '] the vaue is : [' . stringfy_vars($_SESSION[$item]) . ']'); |
63 | 63 | return $_SESSION[$item]; |
64 | 64 | } |
65 | - $logger->warning('Cannot find session item [' . $item . '] using the default value ['. $default . ']'); |
|
65 | + $logger->warning('Cannot find session item [' . $item . '] using the default value [' . $default . ']'); |
|
66 | 66 | return $default; |
67 | 67 | } |
68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param string $item the session item name to set |
72 | 72 | * @param mixed $value the session item value |
73 | 73 | */ |
74 | - public static function set($item, $value){ |
|
74 | + public static function set($item, $value) { |
|
75 | 75 | $logger = self::getLogger(); |
76 | 76 | $logger->debug('Setting session data for item [' . $item . '], value [' . stringfy_vars($value) . ']'); |
77 | 77 | $_SESSION[$item] = $value; |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * @param mixed $default the default value to use if can not find the session flash item in the list |
84 | 84 | * @return mixed the session flash value if exist or the default value |
85 | 85 | */ |
86 | - public static function getFlash($item, $default = null){ |
|
86 | + public static function getFlash($item, $default = null) { |
|
87 | 87 | $logger = self::getLogger(); |
88 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
88 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
89 | 89 | $return = array_key_exists($key, $_SESSION) ? |
90 | 90 | ($_SESSION[$key]) : $default; |
91 | - if(array_key_exists($key, $_SESSION)){ |
|
91 | + if (array_key_exists($key, $_SESSION)) { |
|
92 | 92 | unset($_SESSION[$key]); |
93 | 93 | } |
94 | - else{ |
|
95 | - $logger->warning('Cannot find session flash item ['. $key .'] using the default value ['. $default .']'); |
|
94 | + else { |
|
95 | + $logger->warning('Cannot find session flash item [' . $key . '] using the default value [' . $default . ']'); |
|
96 | 96 | } |
97 | 97 | return $return; |
98 | 98 | } |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | * @param string $item the session flash item name |
103 | 103 | * @return boolean |
104 | 104 | */ |
105 | - public static function hasFlash($item){ |
|
106 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
105 | + public static function hasFlash($item) { |
|
106 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
107 | 107 | return array_key_exists($key, $_SESSION); |
108 | 108 | } |
109 | 109 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param string $item the session flash item name to set |
113 | 113 | * @param mixed $value the session flash item value |
114 | 114 | */ |
115 | - public static function setFlash($item, $value){ |
|
116 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
115 | + public static function setFlash($item, $value) { |
|
116 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
117 | 117 | $_SESSION[$key] = $value; |
118 | 118 | } |
119 | 119 | |
@@ -121,14 +121,14 @@ discard block |
||
121 | 121 | * Clear the session item in the list |
122 | 122 | * @param string $item the session item name to be deleted |
123 | 123 | */ |
124 | - public static function clear($item){ |
|
124 | + public static function clear($item) { |
|
125 | 125 | $logger = self::getLogger(); |
126 | - if(array_key_exists($item, $_SESSION)){ |
|
127 | - $logger->info('Deleting of session for item ['.$item.' ]'); |
|
126 | + if (array_key_exists($item, $_SESSION)) { |
|
127 | + $logger->info('Deleting of session for item [' . $item . ' ]'); |
|
128 | 128 | unset($_SESSION[$item]); |
129 | 129 | } |
130 | - else{ |
|
131 | - $logger->warning('Session item ['.$item.'] to be deleted does not exists'); |
|
130 | + else { |
|
131 | + $logger->warning('Session item [' . $item . '] to be deleted does not exists'); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | * Clear the session flash item in the list |
137 | 137 | * @param string $item the session flash item name to be deleted |
138 | 138 | */ |
139 | - public static function clearFlash($item){ |
|
139 | + public static function clearFlash($item) { |
|
140 | 140 | $logger = self::getLogger(); |
141 | - $key = self::SESSION_FLASH_KEY.'_'.$item; |
|
142 | - if(array_key_exists($key, $_SESSION)){ |
|
143 | - $logger->info('Delete session flash for item ['.$item.']'); |
|
141 | + $key = self::SESSION_FLASH_KEY . '_' . $item; |
|
142 | + if (array_key_exists($key, $_SESSION)) { |
|
143 | + $logger->info('Delete session flash for item [' . $item . ']'); |
|
144 | 144 | unset($_SESSION[$item]); |
145 | 145 | } |
146 | - else{ |
|
147 | - $logger->warning('Dession flash item ['.$item.'] to be deleted does not exists'); |
|
146 | + else { |
|
147 | + $logger->warning('Dession flash item [' . $item . '] to be deleted does not exists'); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | * @param string $item the session item name |
154 | 154 | * @return boolean |
155 | 155 | */ |
156 | - public static function exists($item){ |
|
156 | + public static function exists($item) { |
|
157 | 157 | return array_key_exists($item, $_SESSION); |
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | 161 | * Destroy all session data values |
162 | 162 | */ |
163 | - public static function clearAll(){ |
|
163 | + public static function clearAll() { |
|
164 | 164 | session_unset(); |
165 | 165 | session_destroy(); |
166 | 166 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Module{ |
|
27 | + class Module { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * list of loaded module |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * The signleton of the logger |
43 | 43 | * @return Object the Log instance |
44 | 44 | */ |
45 | - private static function getLogger(){ |
|
46 | - if(self::$logger == null){ |
|
47 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
45 | + private static function getLogger() { |
|
46 | + if (self::$logger == null) { |
|
47 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
48 | 48 | self::$logger[0]->setLogger('Library::Module'); |
49 | 49 | } |
50 | 50 | return self::$logger[0]; |
@@ -53,25 +53,25 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * Initialise the module list by scanning the directory MODULE_PATH |
55 | 55 | */ |
56 | - public function init(){ |
|
56 | + public function init() { |
|
57 | 57 | $logger = self::getLogger(); |
58 | 58 | $logger->debug('Check if the application contains the modules ...'); |
59 | 59 | $moduleDir = opendir(MODULE_PATH); |
60 | - while(($module = readdir($moduleDir)) !== false){ |
|
61 | - if($module != '.' && $module != '..' && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)){ |
|
60 | + while (($module = readdir($moduleDir)) !== false) { |
|
61 | + if ($module != '.' && $module != '..' && preg_match('/^([a-z0-9-_]+)$/i', $module) && is_dir(MODULE_PATH . $module)) { |
|
62 | 62 | self::$list[] = $module; |
63 | 63 | } |
64 | - else{ |
|
65 | - $logger->info('Skipping [' .$module. '], may be this is not a directory or does not exists or is invalid name'); |
|
64 | + else { |
|
65 | + $logger->info('Skipping [' . $module . '], may be this is not a directory or does not exists or is invalid name'); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | closedir($moduleDir); |
69 | 69 | ksort(self::$list); |
70 | 70 | |
71 | - if(self::hasModule()){ |
|
71 | + if (self::hasModule()) { |
|
72 | 72 | $logger->info('The application contains the module below [' . implode(', ', self::getModuleList()) . ']'); |
73 | 73 | } |
74 | - else{ |
|
74 | + else { |
|
75 | 75 | $logger->info('The application contains no module skipping'); |
76 | 76 | } |
77 | 77 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * Get the list of the custom autoload configuration from module if exists |
81 | 81 | * @return array|boolean the autoload configurations list or false if no module contains the autoload configuration values |
82 | 82 | */ |
83 | - public static function getModulesAutoloadConfig(){ |
|
83 | + public static function getModulesAutoloadConfig() { |
|
84 | 84 | $logger = self::getLogger(); |
85 | - if(! self::hasModule()){ |
|
85 | + if (!self::hasModule()) { |
|
86 | 86 | $logger->info('No module was loaded skipping.'); |
87 | 87 | return false; |
88 | 88 | } |
@@ -95,27 +95,27 @@ discard block |
||
95 | 95 | |
96 | 96 | foreach (self::$list as $module) { |
97 | 97 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'autoload.php'; |
98 | - if(file_exists($file)){ |
|
98 | + if (file_exists($file)) { |
|
99 | 99 | require_once $file; |
100 | - if(! empty($autoload) && is_array($autoload)){ |
|
100 | + if (!empty($autoload) && is_array($autoload)) { |
|
101 | 101 | //libraries autoload |
102 | - if(! empty($autoload['libraries']) && is_array($autoload['libraries'])){ |
|
102 | + if (!empty($autoload['libraries']) && is_array($autoload['libraries'])) { |
|
103 | 103 | $autoloads['libraries'] = array_merge($autoloads['libraries'], $autoload['libraries']); |
104 | 104 | } |
105 | 105 | //config autoload |
106 | - if(! empty($autoload['config']) && is_array($autoload['config'])){ |
|
106 | + if (!empty($autoload['config']) && is_array($autoload['config'])) { |
|
107 | 107 | $autoloads['config'] = array_merge($autoloads['config'], $autoload['config']); |
108 | 108 | } |
109 | 109 | //models autoload |
110 | - if(! empty($autoload['models']) && is_array($autoload['models'])){ |
|
110 | + if (!empty($autoload['models']) && is_array($autoload['models'])) { |
|
111 | 111 | $autoloads['models'] = array_merge($autoloads['models'], $autoload['models']); |
112 | 112 | } |
113 | 113 | //functions autoload |
114 | - if(! empty($autoload['functions']) && is_array($autoload['functions'])){ |
|
114 | + if (!empty($autoload['functions']) && is_array($autoload['functions'])) { |
|
115 | 115 | $autoloads['functions'] = array_merge($autoloads['functions'], $autoload['functions']); |
116 | 116 | } |
117 | 117 | //languages autoload |
118 | - if(! empty($autoload['languages']) && is_array($autoload['languages'])){ |
|
118 | + if (!empty($autoload['languages']) && is_array($autoload['languages'])) { |
|
119 | 119 | $autoloads['languages'] = array_merge($autoloads['languages'], $autoload['languages']); |
120 | 120 | } |
121 | 121 | unset($autoload); |
@@ -129,23 +129,23 @@ discard block |
||
129 | 129 | * Get the list of the custom routes configuration from module if exists |
130 | 130 | * @return array|boolean the routes list or false if no module contains the routes configuration |
131 | 131 | */ |
132 | - public static function getModulesRoutes(){ |
|
132 | + public static function getModulesRoutes() { |
|
133 | 133 | $logger = self::getLogger(); |
134 | - if(! self::hasModule()){ |
|
134 | + if (!self::hasModule()) { |
|
135 | 135 | $logger->info('No module was loaded skipping.'); |
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | $routes = array(); |
139 | 139 | foreach (self::$list as $module) { |
140 | 140 | $file = MODULE_PATH . $module . DS . 'config' . DS . 'routes.php'; |
141 | - if(file_exists($file)){ |
|
141 | + if (file_exists($file)) { |
|
142 | 142 | require_once $file; |
143 | - if(! empty($route) && is_array($route)){ |
|
143 | + if (!empty($route) && is_array($route)) { |
|
144 | 144 | $routes = array_merge($routes, $route); |
145 | 145 | unset($route); |
146 | 146 | } |
147 | - else{ |
|
148 | - show_error('No routing configuration found in [' .$file. '] for module [' . $module . ']'); |
|
147 | + else { |
|
148 | + show_error('No routing configuration found in [' . $file . '] for module [' . $module . ']'); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | } |
@@ -159,23 +159,23 @@ discard block |
||
159 | 159 | * @param string $module the module name |
160 | 160 | * @return boolean|string false or null if no module have this controller, path the full path of the controller |
161 | 161 | */ |
162 | - public static function findControllerFullPath($class, $module = null){ |
|
162 | + public static function findControllerFullPath($class, $module = null) { |
|
163 | 163 | $logger = self::getLogger(); |
164 | - if(! self::hasModule()){ |
|
164 | + if (!self::hasModule()) { |
|
165 | 165 | $logger->info('No module was loaded skiping.'); |
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | $class = str_ireplace('.php', '', $class); |
169 | 169 | $class = ucfirst($class); |
170 | - $classFile = $class.'.php'; |
|
171 | - $logger->debug('Checking the controller [' . $class . '] in module [' .$module. '] ...'); |
|
170 | + $classFile = $class . '.php'; |
|
171 | + $logger->debug('Checking the controller [' . $class . '] in module [' . $module . '] ...'); |
|
172 | 172 | $filePath = MODULE_PATH . $module . DS . 'controllers' . DS . $classFile; |
173 | - if(file_exists($filePath)){ |
|
174 | - $logger->info('Found controller [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
173 | + if (file_exists($filePath)) { |
|
174 | + $logger->info('Found controller [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
175 | 175 | return $filePath; |
176 | 176 | } |
177 | - else{ |
|
178 | - $logger->info('Controller [' . $class . '] does not exist in the module [' .$module. ']'); |
|
177 | + else { |
|
178 | + $logger->info('Controller [' . $class . '] does not exist in the module [' . $module . ']'); |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | } |
@@ -186,23 +186,23 @@ discard block |
||
186 | 186 | * @param string $module the module name |
187 | 187 | * @return boolean|string false or null if no module have this model, return the full path of this model |
188 | 188 | */ |
189 | - public static function findModelFullPath($class, $module = null){ |
|
189 | + public static function findModelFullPath($class, $module = null) { |
|
190 | 190 | $logger = self::getLogger(); |
191 | - if(! self::hasModule()){ |
|
191 | + if (!self::hasModule()) { |
|
192 | 192 | $logger->info('No module was loaded skiping.'); |
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | $class = str_ireplace('.php', '', $class); |
196 | 196 | $class = ucfirst($class); |
197 | - $classFile = $class.'.php'; |
|
198 | - $logger->debug('Checking model [' . $class . '] in module [' .$module. '] ...'); |
|
197 | + $classFile = $class . '.php'; |
|
198 | + $logger->debug('Checking model [' . $class . '] in module [' . $module . '] ...'); |
|
199 | 199 | $filePath = MODULE_PATH . $module . DS . 'models' . DS . $classFile; |
200 | - if(file_exists($filePath)){ |
|
201 | - $logger->info('Found model [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
200 | + if (file_exists($filePath)) { |
|
201 | + $logger->info('Found model [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
202 | 202 | return $filePath; |
203 | 203 | } |
204 | - else{ |
|
205 | - $logger->info('Model [' . $class . '] does not exist in the module [' .$module. ']'); |
|
204 | + else { |
|
205 | + $logger->info('Model [' . $class . '] does not exist in the module [' . $module . ']'); |
|
206 | 206 | return false; |
207 | 207 | } |
208 | 208 | } |
@@ -213,22 +213,22 @@ discard block |
||
213 | 213 | * @param string $module the module name |
214 | 214 | * @return boolean|string false or null if no module have this configuration, return the full path of this configuration |
215 | 215 | */ |
216 | - public static function findConfigFullPath($configuration, $module = null){ |
|
216 | + public static function findConfigFullPath($configuration, $module = null) { |
|
217 | 217 | $logger = self::getLogger(); |
218 | - if(! self::hasModule()){ |
|
218 | + if (!self::hasModule()) { |
|
219 | 219 | $logger->info('No module was loaded skiping.'); |
220 | 220 | return false; |
221 | 221 | } |
222 | 222 | $configuration = str_ireplace('.php', '', $configuration); |
223 | - $file = $configuration.'.php'; |
|
224 | - $logger->debug('Checking configuration [' . $configuration . '] in module [' .$module. '] ...'); |
|
223 | + $file = $configuration . '.php'; |
|
224 | + $logger->debug('Checking configuration [' . $configuration . '] in module [' . $module . '] ...'); |
|
225 | 225 | $filePath = MODULE_PATH . $module . DS . 'config' . DS . $file; |
226 | - if(file_exists($filePath)){ |
|
227 | - $logger->info('Found configuration [' . $configuration . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
226 | + if (file_exists($filePath)) { |
|
227 | + $logger->info('Found configuration [' . $configuration . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
228 | 228 | return $filePath; |
229 | 229 | } |
230 | - else{ |
|
231 | - $logger->info('Configuration [' . $configuration . '] does not exist in the module [' .$module. ']'); |
|
230 | + else { |
|
231 | + $logger->info('Configuration [' . $configuration . '] does not exist in the module [' . $module . ']'); |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | } |
@@ -239,23 +239,23 @@ discard block |
||
239 | 239 | * @param string $module the module name |
240 | 240 | * @return boolean|string false or null if no module have this helper, return the full path of this helper |
241 | 241 | */ |
242 | - public static function findFunctionFullPath($helper, $module = null){ |
|
242 | + public static function findFunctionFullPath($helper, $module = null) { |
|
243 | 243 | $logger = self::getLogger(); |
244 | - if(! self::hasModule()){ |
|
244 | + if (!self::hasModule()) { |
|
245 | 245 | $logger->info('No module was loaded skiping.'); |
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | $helper = str_ireplace('.php', '', $helper); |
249 | 249 | $helper = str_ireplace('function_', '', $helper); |
250 | - $file = 'function_'.$helper.'.php'; |
|
251 | - $logger->debug('Checking helper [' . $helper . '] in module [' .$module. '] ...'); |
|
250 | + $file = 'function_' . $helper . '.php'; |
|
251 | + $logger->debug('Checking helper [' . $helper . '] in module [' . $module . '] ...'); |
|
252 | 252 | $filePath = MODULE_PATH . $module . DS . 'functions' . DS . $file; |
253 | - if(file_exists($filePath)){ |
|
254 | - $logger->info('Found helper [' . $helper . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
253 | + if (file_exists($filePath)) { |
|
254 | + $logger->info('Found helper [' . $helper . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
255 | 255 | return $filePath; |
256 | 256 | } |
257 | - else{ |
|
258 | - $logger->info('Helper [' . $helper . '] does not exist in the module [' .$module. ']'); |
|
257 | + else { |
|
258 | + $logger->info('Helper [' . $helper . '] does not exist in the module [' . $module . ']'); |
|
259 | 259 | return false; |
260 | 260 | } |
261 | 261 | } |
@@ -267,22 +267,22 @@ discard block |
||
267 | 267 | * @param string $module the module name |
268 | 268 | * @return boolean|string false or null if no module have this library, return the full path of this library |
269 | 269 | */ |
270 | - public static function findLibraryFullPath($class, $module = null){ |
|
270 | + public static function findLibraryFullPath($class, $module = null) { |
|
271 | 271 | $logger = self::getLogger(); |
272 | - if(! self::hasModule()){ |
|
272 | + if (!self::hasModule()) { |
|
273 | 273 | $logger->info('No module was loaded skiping.'); |
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | $class = str_ireplace('.php', '', $class); |
277 | - $file = $class.'.php'; |
|
278 | - $logger->debug('Checking library [' . $class . '] in module [' .$module. '] ...'); |
|
277 | + $file = $class . '.php'; |
|
278 | + $logger->debug('Checking library [' . $class . '] in module [' . $module . '] ...'); |
|
279 | 279 | $filePath = MODULE_PATH . $module . DS . 'libraries' . DS . $file; |
280 | - if(file_exists($filePath)){ |
|
281 | - $logger->info('Found library [' . $class . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
280 | + if (file_exists($filePath)) { |
|
281 | + $logger->info('Found library [' . $class . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
282 | 282 | return $filePath; |
283 | 283 | } |
284 | - else{ |
|
285 | - $logger->info('Library [' . $class . '] does not exist in the module [' .$module. ']'); |
|
284 | + else { |
|
285 | + $logger->info('Library [' . $class . '] does not exist in the module [' . $module . ']'); |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | } |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | * @param string $module the module name to check |
295 | 295 | * @return boolean|string false or null if no module have this view, path the full path of the view |
296 | 296 | */ |
297 | - public static function findViewFullPath($view, $module = null){ |
|
297 | + public static function findViewFullPath($view, $module = null) { |
|
298 | 298 | $logger = self::getLogger(); |
299 | - if(! self::hasModule()){ |
|
299 | + if (!self::hasModule()) { |
|
300 | 300 | $logger->info('No module was loaded skiping.'); |
301 | 301 | return false; |
302 | 302 | } |
@@ -304,14 +304,14 @@ discard block |
||
304 | 304 | $view = trim($view, '/\\'); |
305 | 305 | $view = str_ireplace('/', DS, $view); |
306 | 306 | $viewFile = $view . '.php'; |
307 | - $logger->debug('Checking view [' . $view . '] in module [' .$module. '] ...'); |
|
307 | + $logger->debug('Checking view [' . $view . '] in module [' . $module . '] ...'); |
|
308 | 308 | $filePath = MODULE_PATH . $module . DS . 'views' . DS . $viewFile; |
309 | - if(file_exists($filePath)){ |
|
310 | - $logger->info('Found view [' . $view . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
309 | + if (file_exists($filePath)) { |
|
310 | + $logger->info('Found view [' . $view . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
311 | 311 | return $filePath; |
312 | 312 | } |
313 | - else{ |
|
314 | - $logger->info('View [' . $view . '] does not exist in the module [' .$module. ']'); |
|
313 | + else { |
|
314 | + $logger->info('View [' . $view . '] does not exist in the module [' . $module . ']'); |
|
315 | 315 | return false; |
316 | 316 | } |
317 | 317 | } |
@@ -323,23 +323,23 @@ discard block |
||
323 | 323 | * @param string $appLang the application language like 'en', 'fr' |
324 | 324 | * @return boolean|string false or null if no module have this language, return the full path of this language |
325 | 325 | */ |
326 | - public static function findLanguageFullPath($language, $module = null, $appLang){ |
|
326 | + public static function findLanguageFullPath($language, $module = null, $appLang) { |
|
327 | 327 | $logger = self::getLogger(); |
328 | - if(! self::hasModule()){ |
|
328 | + if (!self::hasModule()) { |
|
329 | 329 | $logger->info('No module was loaded skiping.'); |
330 | 330 | return false; |
331 | 331 | } |
332 | 332 | $language = str_ireplace('.php', '', $language); |
333 | 333 | $language = str_ireplace('lang_', '', $language); |
334 | - $file = 'lang_'.$language.'.php'; |
|
335 | - $logger->debug('Checking language [' . $language . '] in module [' .$module. '] ...'); |
|
334 | + $file = 'lang_' . $language . '.php'; |
|
335 | + $logger->debug('Checking language [' . $language . '] in module [' . $module . '] ...'); |
|
336 | 336 | $filePath = MODULE_PATH . $module . DS . 'lang' . DS . $appLang . DS . $file; |
337 | - if(file_exists($filePath)){ |
|
338 | - $logger->info('Found language [' . $language . '] in module [' .$module. '], the file path is [' .$filePath. ']'); |
|
337 | + if (file_exists($filePath)) { |
|
338 | + $logger->info('Found language [' . $language . '] in module [' . $module . '], the file path is [' . $filePath . ']'); |
|
339 | 339 | return $filePath; |
340 | 340 | } |
341 | - else{ |
|
342 | - $logger->info('Language [' . $language . '] does not exist in the module [' .$module. ']'); |
|
341 | + else { |
|
342 | + $logger->info('Language [' . $language . '] does not exist in the module [' . $module . ']'); |
|
343 | 343 | return false; |
344 | 344 | } |
345 | 345 | } |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * Get the list of module loaded |
349 | 349 | * @return array the module list |
350 | 350 | */ |
351 | - public static function getModuleList(){ |
|
351 | + public static function getModuleList() { |
|
352 | 352 | return self::$list; |
353 | 353 | } |
354 | 354 | |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * Check if the application has an module |
357 | 357 | * @return boolean |
358 | 358 | */ |
359 | - public static function hasModule(){ |
|
359 | + public static function hasModule() { |
|
360 | 360 | return !empty(self::$list); |
361 | 361 | } |
362 | 362 |
@@ -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 Request{ |
|
27 | + class Request { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The value for the super global $_GET |
@@ -90,21 +90,21 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * Construct new request instance |
92 | 92 | */ |
93 | - public function __construct(){ |
|
93 | + public function __construct() { |
|
94 | 94 | $this->get = $_GET; |
95 | 95 | $this->post = $_POST; |
96 | 96 | $this->server = $_SERVER; |
97 | 97 | $this->query = $_REQUEST; |
98 | 98 | $this->cookie = $_COOKIE; |
99 | 99 | $this->file = $_FILES; |
100 | - $this->session =& class_loader('Session', 'classes'); |
|
100 | + $this->session = & class_loader('Session', 'classes'); |
|
101 | 101 | $this->method = $this->server('REQUEST_METHOD'); |
102 | 102 | $this->requestUri = $this->server('REQUEST_URI'); |
103 | 103 | $this->header = array(); |
104 | - if(function_exists('apache_request_headers')){ |
|
104 | + if (function_exists('apache_request_headers')) { |
|
105 | 105 | $this->header = apache_request_headers(); |
106 | 106 | } |
107 | - else if(function_exists('getallheaders')){ |
|
107 | + else if (function_exists('getallheaders')) { |
|
108 | 108 | $this->header = getallheaders(); |
109 | 109 | } |
110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * Get the request method |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - public function method(){ |
|
116 | + public function method() { |
|
117 | 117 | return $this->method; |
118 | 118 | } |
119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * Get the request URI |
122 | 122 | * @return string |
123 | 123 | */ |
124 | - public function requestUri(){ |
|
124 | + public function requestUri() { |
|
125 | 125 | return $this->requestUri; |
126 | 126 | } |
127 | 127 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | * @param boolean $xss if need apply some XSS attack rule on the value |
132 | 132 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
133 | 133 | */ |
134 | - public function query($key = null, $xss = true){ |
|
135 | - if(empty($key)){ |
|
134 | + public function query($key = null, $xss = true) { |
|
135 | + if (empty($key)) { |
|
136 | 136 | //return all |
137 | 137 | return $xss ? clean_input($this->query) : $this->query; |
138 | 138 | } |
139 | 139 | $query = array_key_exists($key, $this->query) ? $this->query[$key] : null; |
140 | - if($xss){ |
|
140 | + if ($xss) { |
|
141 | 141 | $query = clean_input($query); |
142 | 142 | } |
143 | 143 | return $query; |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | * @param boolean $xss if need apply some XSS attack rule on the value |
150 | 150 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
151 | 151 | */ |
152 | - public function get($key = null, $xss = true){ |
|
153 | - if(empty($key)){ |
|
152 | + public function get($key = null, $xss = true) { |
|
153 | + if (empty($key)) { |
|
154 | 154 | //return all |
155 | 155 | return $xss ? clean_input($this->get) : $this->get; |
156 | 156 | } |
157 | 157 | $get = array_key_exists($key, $this->get) ? $this->get[$key] : null; |
158 | - if($xss){ |
|
158 | + if ($xss) { |
|
159 | 159 | $get = clean_input($get); |
160 | 160 | } |
161 | 161 | return $get; |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @param boolean $xss if need apply some XSS attack rule on the value |
168 | 168 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
169 | 169 | */ |
170 | - public function post($key = null, $xss = true){ |
|
171 | - if(empty($key)){ |
|
170 | + public function post($key = null, $xss = true) { |
|
171 | + if (empty($key)) { |
|
172 | 172 | //return all |
173 | 173 | return $xss ? clean_input($this->post) : $this->post; |
174 | 174 | } |
175 | 175 | $post = array_key_exists($key, $this->post) ? $this->post[$key] : null; |
176 | - if($xss){ |
|
176 | + if ($xss) { |
|
177 | 177 | $post = clean_input($post); |
178 | 178 | } |
179 | 179 | return $post; |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | * @param boolean $xss if need apply some XSS attack rule on the value |
186 | 186 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
187 | 187 | */ |
188 | - public function server($key = null, $xss = true){ |
|
189 | - if(empty($key)){ |
|
188 | + public function server($key = null, $xss = true) { |
|
189 | + if (empty($key)) { |
|
190 | 190 | //return all |
191 | 191 | return $xss ? clean_input($this->server) : $this->server; |
192 | 192 | } |
193 | 193 | $server = array_key_exists($key, $this->server) ? $this->server[$key] : null; |
194 | - if($xss){ |
|
194 | + if ($xss) { |
|
195 | 195 | $server = clean_input($server); |
196 | 196 | } |
197 | 197 | return $server; |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | * @param boolean $xss if need apply some XSS attack rule on the value |
204 | 204 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
205 | 205 | */ |
206 | - public function cookie($key = null, $xss = true){ |
|
207 | - if(empty($key)){ |
|
206 | + public function cookie($key = null, $xss = true) { |
|
207 | + if (empty($key)) { |
|
208 | 208 | //return all |
209 | 209 | return $xss ? clean_input($this->cookie) : $this->cookie; |
210 | 210 | } |
211 | 211 | $cookie = array_key_exists($key, $this->cookie) ? $this->cookie[$key] : null; |
212 | - if($xss){ |
|
212 | + if ($xss) { |
|
213 | 213 | $cookie = clean_input($cookie); |
214 | 214 | } |
215 | 215 | return $cookie; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param string $key the item key to be fetched |
221 | 221 | * @return array|mixed the item value if the key exists or all array if the key does not exists or is empty |
222 | 222 | */ |
223 | - public function file($key){ |
|
223 | + public function file($key) { |
|
224 | 224 | $file = array_key_exists($key, $this->file) ? $this->file[$key] : null; |
225 | 225 | return $file; |
226 | 226 | } |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @param boolean $xss if need apply some XSS attack rule on the value |
232 | 232 | * @return array|mixed the item value if the key exists or null if the key does not exists |
233 | 233 | */ |
234 | - public function session($key, $xss = true){ |
|
234 | + public function session($key, $xss = true) { |
|
235 | 235 | $session = $this->session->get($key); |
236 | - if($xss){ |
|
236 | + if ($xss) { |
|
237 | 237 | $session = clean_input($session); |
238 | 238 | } |
239 | 239 | return $session; |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | * @param boolean $xss if need apply some XSS attack rule on the value |
246 | 246 | * @return mixed the item value if the key exists or null if the key does not exists |
247 | 247 | */ |
248 | - public function header($key, $xss = true){ |
|
248 | + public function header($key, $xss = true) { |
|
249 | 249 | $header = array_key_exists($key, $this->header) ? $this->header[$key] : null; |
250 | - if($xss){ |
|
250 | + if ($xss) { |
|
251 | 251 | $header = clean_input($header); |
252 | 252 | } |
253 | 253 | return $header; |