@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * @file common.php |
@@ -438,13 +438,13 @@ discard block |
||
438 | 438 | |
439 | 439 | |
440 | 440 | /** |
441 | - * Function to stringfy PHP variable, useful in debug situation |
|
442 | - * |
|
443 | - * @param mixed $var the variable to stringfy |
|
444 | - * @codeCoverageIgnore |
|
445 | - * |
|
446 | - * @return string the stringfy value |
|
447 | - */ |
|
441 | + * Function to stringfy PHP variable, useful in debug situation |
|
442 | + * |
|
443 | + * @param mixed $var the variable to stringfy |
|
444 | + * @codeCoverageIgnore |
|
445 | + * |
|
446 | + * @return string the stringfy value |
|
447 | + */ |
|
448 | 448 | function stringfy_vars($var){ |
449 | 449 | return print_r($var, true); |
450 | 450 | } |
@@ -586,15 +586,15 @@ discard block |
||
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
589 | - * This function is very useful, it allows to recover the instance of the global controller. |
|
590 | - * Note this function always returns the address of the super instance. |
|
591 | - * For example : |
|
592 | - * $obj = & get_instance(); |
|
593 | - * |
|
594 | - * @codeCoverageIgnore |
|
595 | - * |
|
596 | - * @return object the instance of the "Controller" class |
|
597 | - */ |
|
589 | + * This function is very useful, it allows to recover the instance of the global controller. |
|
590 | + * Note this function always returns the address of the super instance. |
|
591 | + * For example : |
|
592 | + * $obj = & get_instance(); |
|
593 | + * |
|
594 | + * @codeCoverageIgnore |
|
595 | + * |
|
596 | + * @return object the instance of the "Controller" class |
|
597 | + */ |
|
598 | 598 | function & get_instance(){ |
599 | 599 | return Controller::get_instance(); |
600 | 600 | } |
@@ -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,8 +175,8 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @codeCoverageIgnore |
177 | 177 | */ |
178 | - function set_http_status_header($code = 200, $text = null){ |
|
179 | - if (empty($text)){ |
|
178 | + function set_http_status_header($code = 200, $text = null) { |
|
179 | + if (empty($text)) { |
|
180 | 180 | $http_status = array( |
181 | 181 | 100 => 'Continue', |
182 | 182 | 101 => 'Switching Protocols', |
@@ -224,18 +224,18 @@ discard block |
||
224 | 224 | 504 => 'Gateway Timeout', |
225 | 225 | 505 => 'HTTP Version Not Supported', |
226 | 226 | ); |
227 | - if (isset($http_status[$code])){ |
|
227 | + if (isset($http_status[$code])) { |
|
228 | 228 | $text = $http_status[$code]; |
229 | 229 | } |
230 | - else{ |
|
230 | + else { |
|
231 | 231 | show_error('No HTTP status text found for your code please check it.'); |
232 | 232 | } |
233 | 233 | } |
234 | 234 | |
235 | - if (strpos(php_sapi_name(), 'cgi') === 0){ |
|
235 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
236 | 236 | header('Status: ' . $code . ' ' . $text, TRUE); |
237 | 237 | } |
238 | - else{ |
|
238 | + else { |
|
239 | 239 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
240 | 240 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
241 | 241 | } |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @codeCoverageIgnore |
252 | 252 | */ |
253 | - function show_error($msg, $title = 'error', $logging = true){ |
|
253 | + function show_error($msg, $title = 'error', $logging = true) { |
|
254 | 254 | $title = strtoupper($title); |
255 | 255 | $data = array(); |
256 | 256 | $data['error'] = $msg; |
257 | 257 | $data['title'] = $title; |
258 | - if ($logging){ |
|
259 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
258 | + if ($logging) { |
|
259 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
260 | 260 | } |
261 | 261 | $response = & class_loader('Response', 'classes'); |
262 | 262 | $response->sendError($data); |
@@ -270,18 +270,18 @@ discard block |
||
270 | 270 | * |
271 | 271 | * @return boolean true if the web server uses the https protocol, false if not. |
272 | 272 | */ |
273 | - function is_https(){ |
|
273 | + function is_https() { |
|
274 | 274 | /* |
275 | 275 | * some servers pass the "HTTPS" parameter in the server variable, |
276 | 276 | * if is the case, check if the value is "on", "true", "1". |
277 | 277 | */ |
278 | - if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
278 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
279 | 279 | return true; |
280 | 280 | } |
281 | - else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
281 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
282 | 282 | return true; |
283 | 283 | } |
284 | - else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
284 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
285 | 285 | return true; |
286 | 286 | } |
287 | 287 | return false; |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return boolean true if is a valid URL address or false. |
298 | 298 | */ |
299 | - function is_url($url){ |
|
299 | + function is_url($url) { |
|
300 | 300 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
301 | 301 | } |
302 | 302 | |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @param string $controllerClass the controller class name to be loaded |
307 | 307 | * @codeCoverageIgnore |
308 | 308 | */ |
309 | - function autoload_controller($controllerClass){ |
|
310 | - if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
309 | + function autoload_controller($controllerClass) { |
|
310 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
311 | 311 | require_once $path; |
312 | 312 | } |
313 | 313 | } |
@@ -321,11 +321,11 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @return boolean |
323 | 323 | */ |
324 | - function php_exception_handler($ex){ |
|
325 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
326 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
324 | + function php_exception_handler($ex) { |
|
325 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
326 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
327 | 327 | } |
328 | - else{ |
|
328 | + else { |
|
329 | 329 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
330 | 330 | } |
331 | 331 | return true; |
@@ -342,16 +342,16 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @return boolean |
344 | 344 | */ |
345 | - function php_error_handler($errno , $errstr, $errfile , $errline){ |
|
345 | + function php_error_handler($errno, $errstr, $errfile, $errline) { |
|
346 | 346 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
347 | - if ($isError){ |
|
347 | + if ($isError) { |
|
348 | 348 | set_http_status_header(500); |
349 | 349 | } |
350 | - if (! (error_reporting() & $errno)) { |
|
350 | + if (!(error_reporting() & $errno)) { |
|
351 | 351 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
352 | 352 | return; |
353 | 353 | } |
354 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
354 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
355 | 355 | $errorType = 'error'; |
356 | 356 | switch ($errno) { |
357 | 357 | case E_USER_ERROR: |
@@ -367,9 +367,9 @@ discard block |
||
367 | 367 | $errorType = 'error'; |
368 | 368 | break; |
369 | 369 | } |
370 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
370 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
371 | 371 | } |
372 | - if ($isError){ |
|
372 | + if ($isError) { |
|
373 | 373 | die(); |
374 | 374 | } |
375 | 375 | return true; |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | * This function is used to run in shutdown situation of the script |
380 | 380 | * @codeCoverageIgnore |
381 | 381 | */ |
382 | - function php_shudown_handler(){ |
|
382 | + function php_shudown_handler() { |
|
383 | 383 | $lastError = error_get_last(); |
384 | 384 | if (isset($lastError) && |
385 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
385 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
386 | 386 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
387 | 387 | } |
388 | 388 | } |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | * |
401 | 401 | * @return string string of the HTML attribute. |
402 | 402 | */ |
403 | - function attributes_to_string(array $attributes){ |
|
403 | + function attributes_to_string(array $attributes) { |
|
404 | 404 | $str = ' '; |
405 | 405 | //we check that the array passed as an argument is not empty. |
406 | - if (! empty($attributes)){ |
|
407 | - foreach($attributes as $key => $value){ |
|
406 | + if (!empty($attributes)) { |
|
407 | + foreach ($attributes as $key => $value) { |
|
408 | 408 | $key = trim(htmlspecialchars($key)); |
409 | 409 | $value = trim(htmlspecialchars($value)); |
410 | 410 | /* |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | * $attr = array('placeholder' => 'I am a "puple"') |
415 | 415 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
416 | 416 | */ |
417 | - if ($value && strpos('"', $value) !== false){ |
|
417 | + if ($value && strpos('"', $value) !== false) { |
|
418 | 418 | $value = addslashes($value); |
419 | 419 | } |
420 | - $str .= $key.' = "'.$value.'" '; |
|
420 | + $str .= $key . ' = "' . $value . '" '; |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | //remove the space after using rtrim() |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | * |
434 | 434 | * @return string the stringfy value |
435 | 435 | */ |
436 | - function stringfy_vars($var){ |
|
436 | + function stringfy_vars($var) { |
|
437 | 437 | return print_r($var, true); |
438 | 438 | } |
439 | 439 | |
@@ -444,18 +444,18 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @return mixed the sanitize value |
446 | 446 | */ |
447 | - function clean_input($str){ |
|
448 | - if (is_array($str)){ |
|
447 | + function clean_input($str) { |
|
448 | + if (is_array($str)) { |
|
449 | 449 | $str = array_map('clean_input', $str); |
450 | 450 | } |
451 | - else if (is_object($str)){ |
|
451 | + else if (is_object($str)) { |
|
452 | 452 | $obj = $str; |
453 | 453 | foreach ($str as $var => $value) { |
454 | 454 | $obj->$var = clean_input($value); |
455 | 455 | } |
456 | 456 | $str = $obj; |
457 | 457 | } |
458 | - else{ |
|
458 | + else { |
|
459 | 459 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
460 | 460 | } |
461 | 461 | return $str; |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | * |
474 | 474 | * @return string the string with the hidden part. |
475 | 475 | */ |
476 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
476 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
477 | 477 | //get the string length |
478 | 478 | $len = strlen($str); |
479 | 479 | //if str is empty |
480 | - if ($len <= 0){ |
|
480 | + if ($len <= 0) { |
|
481 | 481 | return str_repeat($hiddenChar, 6); |
482 | 482 | } |
483 | 483 | //if the length is less than startCount and endCount |
@@ -485,14 +485,14 @@ discard block |
||
485 | 485 | //or startCount is negative or endCount is negative |
486 | 486 | //return the full string hidden |
487 | 487 | |
488 | - if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
488 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
489 | 489 | return str_repeat($hiddenChar, $len); |
490 | 490 | } |
491 | 491 | //the start non hidden string |
492 | 492 | $startNonHiddenStr = substr($str, 0, $startCount); |
493 | 493 | //the end non hidden string |
494 | 494 | $endNonHiddenStr = null; |
495 | - if ($endCount > 0){ |
|
495 | + if ($endCount > 0) { |
|
496 | 496 | $endNonHiddenStr = substr($str, - $endCount); |
497 | 497 | } |
498 | 498 | //the hidden string |
@@ -505,40 +505,40 @@ discard block |
||
505 | 505 | * This function is used to set the initial session config regarding the configuration |
506 | 506 | * @codeCoverageIgnore |
507 | 507 | */ |
508 | - function set_session_config(){ |
|
508 | + function set_session_config() { |
|
509 | 509 | //$_SESSION is not available on cli mode |
510 | - if (! IS_CLI){ |
|
511 | - $logger =& class_loader('Log', 'classes'); |
|
510 | + if (!IS_CLI) { |
|
511 | + $logger = & class_loader('Log', 'classes'); |
|
512 | 512 | $logger->setLogger('PHPSession'); |
513 | 513 | //set session params |
514 | 514 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
515 | 515 | $sessionName = get_config('session_name'); |
516 | - if ($sessionName){ |
|
516 | + if ($sessionName) { |
|
517 | 517 | session_name($sessionName); |
518 | 518 | } |
519 | 519 | $logger->info('Session handler: ' . $sessionHandler); |
520 | 520 | $logger->info('Session name: ' . $sessionName); |
521 | 521 | |
522 | - if ($sessionHandler == 'files'){ |
|
522 | + if ($sessionHandler == 'files') { |
|
523 | 523 | $sessionSavePath = get_config('session_save_path'); |
524 | - if ($sessionSavePath){ |
|
525 | - if (! is_dir($sessionSavePath)){ |
|
524 | + if ($sessionSavePath) { |
|
525 | + if (!is_dir($sessionSavePath)) { |
|
526 | 526 | mkdir($sessionSavePath, 1773); |
527 | 527 | } |
528 | 528 | session_save_path($sessionSavePath); |
529 | 529 | $logger->info('Session save path: ' . $sessionSavePath); |
530 | 530 | } |
531 | 531 | } |
532 | - else if ($sessionHandler == 'database'){ |
|
532 | + else if ($sessionHandler == 'database') { |
|
533 | 533 | //load database session handle library |
534 | 534 | //Database Session handler Model |
535 | 535 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
536 | 536 | |
537 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
537 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
538 | 538 | session_set_save_handler($DBS, true); |
539 | 539 | $logger->info('session save path: ' . get_config('session_save_path')); |
540 | 540 | } |
541 | - else{ |
|
541 | + else { |
|
542 | 542 | show_error('Invalid session handler configuration'); |
543 | 543 | } |
544 | 544 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -561,9 +561,9 @@ discard block |
||
561 | 561 | $logger->info('Session lifetime: ' . $lifetime); |
562 | 562 | $logger->info('Session cookie path: ' . $path); |
563 | 563 | $logger->info('Session domain: ' . $domain); |
564 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
564 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
565 | 565 | |
566 | - if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
566 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
567 | 567 | $logger->info('Session not yet start, start it now'); |
568 | 568 | session_start(); |
569 | 569 | } |
@@ -226,16 +226,14 @@ discard block |
||
226 | 226 | ); |
227 | 227 | if (isset($http_status[$code])){ |
228 | 228 | $text = $http_status[$code]; |
229 | - } |
|
230 | - else{ |
|
229 | + } else{ |
|
231 | 230 | show_error('No HTTP status text found for your code please check it.'); |
232 | 231 | } |
233 | 232 | } |
234 | 233 | |
235 | 234 | if (strpos(php_sapi_name(), 'cgi') === 0){ |
236 | 235 | header('Status: ' . $code . ' ' . $text, TRUE); |
237 | - } |
|
238 | - else{ |
|
236 | + } else{ |
|
239 | 237 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
240 | 238 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
241 | 239 | } |
@@ -277,11 +275,9 @@ discard block |
||
277 | 275 | */ |
278 | 276 | if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
279 | 277 | return true; |
280 | - } |
|
281 | - else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
278 | + } else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
282 | 279 | return true; |
283 | - } |
|
284 | - else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
280 | + } else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
285 | 281 | return true; |
286 | 282 | } |
287 | 283 | return false; |
@@ -324,8 +320,7 @@ discard block |
||
324 | 320 | function php_exception_handler($ex){ |
325 | 321 | if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
326 | 322 | show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
327 | - } |
|
328 | - else{ |
|
323 | + } else{ |
|
329 | 324 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
330 | 325 | } |
331 | 326 | return true; |
@@ -447,15 +442,13 @@ discard block |
||
447 | 442 | function clean_input($str){ |
448 | 443 | if (is_array($str)){ |
449 | 444 | $str = array_map('clean_input', $str); |
450 | - } |
|
451 | - else if (is_object($str)){ |
|
445 | + } else if (is_object($str)){ |
|
452 | 446 | $obj = $str; |
453 | 447 | foreach ($str as $var => $value) { |
454 | 448 | $obj->$var = clean_input($value); |
455 | 449 | } |
456 | 450 | $str = $obj; |
457 | - } |
|
458 | - else{ |
|
451 | + } else{ |
|
459 | 452 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
460 | 453 | } |
461 | 454 | return $str; |
@@ -528,8 +521,7 @@ discard block |
||
528 | 521 | session_save_path($sessionSavePath); |
529 | 522 | $logger->info('Session save path: ' . $sessionSavePath); |
530 | 523 | } |
531 | - } |
|
532 | - else if ($sessionHandler == 'database'){ |
|
524 | + } else if ($sessionHandler == 'database'){ |
|
533 | 525 | //load database session handle library |
534 | 526 | //Database Session handler Model |
535 | 527 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
@@ -537,8 +529,7 @@ discard block |
||
537 | 529 | $DBS =& class_loader('DBSessionHandler', 'classes'); |
538 | 530 | session_set_save_handler($DBS, true); |
539 | 531 | $logger->info('session save path: ' . get_config('session_save_path')); |
540 | - } |
|
541 | - else{ |
|
532 | + } else{ |
|
542 | 533 | show_error('Invalid session handler configuration'); |
543 | 534 | } |
544 | 535 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | if(is_object($logger)){ |
89 | 89 | $this->setLogger($logger); |
90 | - } |
|
91 | - else{ |
|
90 | + } else{ |
|
92 | 91 | $this->logger =& class_loader('Log', 'classes'); |
93 | 92 | $this->logger->setLogger('Library::DBSessionHandler'); |
94 | 93 | } |
@@ -197,8 +196,7 @@ discard block |
||
197 | 196 | if($this->getLoader()){ |
198 | 197 | $this->getLoader()->functions('user_agent'); |
199 | 198 | $this->getLoader()->library('Browser'); |
200 | - } |
|
201 | - else{ |
|
199 | + } else{ |
|
202 | 200 | Loader::functions('user_agent'); |
203 | 201 | Loader::library('Browser'); |
204 | 202 | } |
@@ -237,8 +235,7 @@ discard block |
||
237 | 235 | if($this->getLoader()){ |
238 | 236 | $this->getLoader()->functions('user_agent'); |
239 | 237 | $this->getLoader()->library('Browser'); |
240 | - } |
|
241 | - else{ |
|
238 | + } else{ |
|
242 | 239 | Loader::functions('user_agent'); |
243 | 240 | Loader::library('Browser'); |
244 | 241 | } |
@@ -264,8 +261,7 @@ discard block |
||
264 | 261 | //update |
265 | 262 | unset($params[$columns['sid']]); |
266 | 263 | $instance->update($sid, $params); |
267 | - } |
|
268 | - else{ |
|
264 | + } else{ |
|
269 | 265 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
270 | 266 | $instance->insert($params); |
271 | 267 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * check if the interface "SessionHandlerInterface" exists (normally in PHP 5.4 this already exists) |
@@ -76,27 +76,27 @@ discard block |
||
76 | 76 | private $logger; |
77 | 77 | |
78 | 78 | /** |
79 | - * Instance of the Loader class |
|
80 | - * @var Loader |
|
81 | - */ |
|
82 | - protected $loader = null; |
|
79 | + * Instance of the Loader class |
|
80 | + * @var Loader |
|
81 | + */ |
|
82 | + protected $loader = null; |
|
83 | 83 | |
84 | 84 | public function __construct(DBSessionHandlerModel $modelInstance = null, Log $logger = null, Loader $loader = null){ |
85 | 85 | /** |
86 | - * instance of the Log class |
|
87 | - */ |
|
88 | - if(is_object($logger)){ |
|
89 | - $this->setLogger($logger); |
|
90 | - } |
|
91 | - else{ |
|
92 | - $this->logger =& class_loader('Log', 'classes'); |
|
93 | - $this->logger->setLogger('Library::DBSessionHandler'); |
|
94 | - } |
|
95 | - |
|
96 | - if(is_object($loader)){ |
|
97 | - $this->setLoader($loader); |
|
98 | - } |
|
99 | - $this->OBJ = & get_instance(); |
|
86 | + * instance of the Log class |
|
87 | + */ |
|
88 | + if(is_object($logger)){ |
|
89 | + $this->setLogger($logger); |
|
90 | + } |
|
91 | + else{ |
|
92 | + $this->logger =& class_loader('Log', 'classes'); |
|
93 | + $this->logger->setLogger('Library::DBSessionHandler'); |
|
94 | + } |
|
95 | + |
|
96 | + if(is_object($loader)){ |
|
97 | + $this->setLoader($loader); |
|
98 | + } |
|
99 | + $this->OBJ = & get_instance(); |
|
100 | 100 | |
101 | 101 | |
102 | 102 | if(is_object($modelInstance)){ |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | $this->getLoader()->library('Browser'); |
200 | 200 | } |
201 | 201 | else{ |
202 | - Loader::functions('user_agent'); |
|
203 | - Loader::library('Browser'); |
|
204 | - } |
|
202 | + Loader::functions('user_agent'); |
|
203 | + Loader::library('Browser'); |
|
204 | + } |
|
205 | 205 | |
206 | 206 | $ip = get_ip(); |
207 | 207 | $host = @gethostbyaddr($ip) or null; |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | $this->getLoader()->library('Browser'); |
239 | 239 | } |
240 | 240 | else{ |
241 | - Loader::functions('user_agent'); |
|
242 | - Loader::library('Browser'); |
|
243 | - } |
|
241 | + Loader::functions('user_agent'); |
|
242 | + Loader::library('Browser'); |
|
243 | + } |
|
244 | 244 | |
245 | 245 | $ip = get_ip(); |
246 | 246 | $keyValue = $instance->getKeyValue(); |
@@ -324,75 +324,75 @@ discard block |
||
324 | 324 | |
325 | 325 | |
326 | 326 | /** |
327 | - * Return the loader instance |
|
328 | - * @return object Loader the loader instance |
|
329 | - */ |
|
330 | - public function getLoader(){ |
|
331 | - return $this->loader; |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * set the loader instance for future use |
|
336 | - * @param object Loader $loader the loader object |
|
337 | - */ |
|
338 | - public function setLoader($loader){ |
|
339 | - $this->loader = $loader; |
|
340 | - return $this; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Return the model instance |
|
345 | - * @return object DBSessionHandlerModel the model instance |
|
346 | - */ |
|
347 | - public function getModelInstance(){ |
|
348 | - return $this->modelInstanceName; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * set the model instance for future use |
|
353 | - * @param DBSessionHandlerModel $modelInstance the model object |
|
354 | - */ |
|
355 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
356 | - $this->modelInstanceName = $modelInstance; |
|
357 | - return $this; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Return the Log instance |
|
362 | - * @return Log |
|
363 | - */ |
|
364 | - public function getLogger(){ |
|
365 | - return $this->logger; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Set the log instance |
|
370 | - * @param Log $logger the log object |
|
371 | - */ |
|
372 | - public function setLogger(Log $logger){ |
|
373 | - $this->logger = $logger; |
|
374 | - return $this; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Set the model instance using the configuration for session |
|
379 | - */ |
|
380 | - private function setModelInstanceFromConfig(){ |
|
381 | - $modelName = get_config('session_save_path'); |
|
327 | + * Return the loader instance |
|
328 | + * @return object Loader the loader instance |
|
329 | + */ |
|
330 | + public function getLoader(){ |
|
331 | + return $this->loader; |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * set the loader instance for future use |
|
336 | + * @param object Loader $loader the loader object |
|
337 | + */ |
|
338 | + public function setLoader($loader){ |
|
339 | + $this->loader = $loader; |
|
340 | + return $this; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Return the model instance |
|
345 | + * @return object DBSessionHandlerModel the model instance |
|
346 | + */ |
|
347 | + public function getModelInstance(){ |
|
348 | + return $this->modelInstanceName; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * set the model instance for future use |
|
353 | + * @param DBSessionHandlerModel $modelInstance the model object |
|
354 | + */ |
|
355 | + public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
356 | + $this->modelInstanceName = $modelInstance; |
|
357 | + return $this; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Return the Log instance |
|
362 | + * @return Log |
|
363 | + */ |
|
364 | + public function getLogger(){ |
|
365 | + return $this->logger; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Set the log instance |
|
370 | + * @param Log $logger the log object |
|
371 | + */ |
|
372 | + public function setLogger(Log $logger){ |
|
373 | + $this->logger = $logger; |
|
374 | + return $this; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Set the model instance using the configuration for session |
|
379 | + */ |
|
380 | + private function setModelInstanceFromConfig(){ |
|
381 | + $modelName = get_config('session_save_path'); |
|
382 | 382 | $this->logger->info('The database session model: ' . $modelName); |
383 | 383 | if($this->getLoader()){ |
384 | 384 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
385 | 385 | } |
386 | 386 | //@codeCoverageIgnoreStart |
387 | 387 | else{ |
388 | - Loader::model($modelName, 'dbsessionhandlerinstance'); |
|
389 | - } |
|
390 | - if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
388 | + Loader::model($modelName, 'dbsessionhandlerinstance'); |
|
389 | + } |
|
390 | + if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
391 | 391 | show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"'); |
392 | 392 | } |
393 | 393 | //@codeCoverageIgnoreEnd |
394 | 394 | |
395 | 395 | //set model instance |
396 | 396 | $this->setModelInstance($this->OBJ->dbsessionhandlerinstance); |
397 | - } |
|
397 | + } |
|
398 | 398 | } |
@@ -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', null); |
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 |
@@ -24,20 +24,20 @@ |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | |
27 | - public function testFunctionGetConfigKeyNotExist(){ |
|
27 | + public function testFunctionGetConfigKeyNotExist() { |
|
28 | 28 | $key = 'foo'; |
29 | 29 | $cfg = get_config($key); |
30 | 30 | $this->assertNull($cfg); |
31 | 31 | } |
32 | 32 | |
33 | - public function testFunctionGetConfigKeyNotExistUsingDefaultValue(){ |
|
33 | + public function testFunctionGetConfigKeyNotExistUsingDefaultValue() { |
|
34 | 34 | $key = 'foo'; |
35 | 35 | $expected = 'bar'; |
36 | 36 | $cfg = get_config($key, $expected); |
37 | 37 | $this->assertEquals($cfg, $expected); |
38 | 38 | } |
39 | 39 | |
40 | - public function testFunctionGetConfigAfterSet(){ |
|
40 | + public function testFunctionGetConfigAfterSet() { |
|
41 | 41 | $key = 'foo'; |
42 | 42 | $expected = 'bar'; |
43 | 43 | $c = new Config(); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class ApcCache implements CacheInterface{ |
28 | 28 | |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * instance of the Log class |
|
43 | - */ |
|
44 | - if(is_object($logger)){ |
|
45 | - $this->logger = $logger; |
|
46 | - } |
|
47 | - else{ |
|
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
49 | - $this->logger->setLogger('Library::ApcCache'); |
|
50 | - } |
|
42 | + * instance of the Log class |
|
43 | + */ |
|
44 | + if(is_object($logger)){ |
|
45 | + $this->logger = $logger; |
|
46 | + } |
|
47 | + else{ |
|
48 | + $this->logger =& class_loader('Log', 'classes'); |
|
49 | + $this->logger->setLogger('Library::ApcCache'); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
88 | 88 | $result = apc_store($key, $data, $ttl); |
89 | 89 | if($result === false){ |
90 | - $this->logger->error('Can not write cache data for the key ['. $key .'], return false'); |
|
91 | - return false; |
|
92 | - } |
|
93 | - else{ |
|
94 | - $this->logger->info('Cache data saved for the key ['. $key .']'); |
|
95 | - return true; |
|
96 | - } |
|
90 | + $this->logger->error('Can not write cache data for the key ['. $key .'], return false'); |
|
91 | + return false; |
|
92 | + } |
|
93 | + else{ |
|
94 | + $this->logger->info('Cache data saved for the key ['. $key .']'); |
|
95 | + return true; |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | else{ |
114 | 114 | $this->logger->info('Found cache data for the key [' .$key. '] remove it'); |
115 | - return apc_delete($key) === true; |
|
115 | + return apc_delete($key) === true; |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -177,28 +177,28 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | - * Return the Log instance |
|
181 | - * @return Log |
|
182 | - */ |
|
183 | - public function getLogger(){ |
|
184 | - return $this->logger; |
|
185 | - } |
|
180 | + * Return the Log instance |
|
181 | + * @return Log |
|
182 | + */ |
|
183 | + public function getLogger(){ |
|
184 | + return $this->logger; |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Set the log instance |
|
189 | - * @param Log $logger the log object |
|
190 | - */ |
|
191 | - public function setLogger(Log $logger){ |
|
192 | - $this->logger = $logger; |
|
193 | - return $this; |
|
194 | - } |
|
187 | + /** |
|
188 | + * Set the log instance |
|
189 | + * @param Log $logger the log object |
|
190 | + */ |
|
191 | + public function setLogger(Log $logger){ |
|
192 | + $this->logger = $logger; |
|
193 | + return $this; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | /** |
197 | - * Return the array of cache information |
|
198 | - * |
|
199 | - * @param string $key the cache key to get the cache information |
|
200 | - * @return boolean|array |
|
201 | - */ |
|
197 | + * Return the array of cache information |
|
198 | + * |
|
199 | + * @param string $key the cache key to get the cache information |
|
200 | + * @return boolean|array |
|
201 | + */ |
|
202 | 202 | private function _getCacheInfo($key){ |
203 | 203 | $caches = apc_cache_info('user'); |
204 | 204 | if(! empty($caches['cache_list'])){ |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class ApcCache implements CacheInterface{ |
|
27 | + class ApcCache implements CacheInterface { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The logger instance |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | private $logger; |
34 | 34 | |
35 | 35 | |
36 | - public function __construct(Log $logger = null){ |
|
37 | - if(! $this->isSupported()){ |
|
36 | + public function __construct(Log $logger = null) { |
|
37 | + if (!$this->isSupported()) { |
|
38 | 38 | show_error('The cache for APC[u] driver is not available. Check if APC[u] extension is loaded and enabled.'); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * instance of the Log class |
43 | 43 | */ |
44 | - if(is_object($logger)){ |
|
44 | + if (is_object($logger)) { |
|
45 | 45 | $this->logger = $logger; |
46 | 46 | } |
47 | - else{ |
|
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
47 | + else { |
|
48 | + $this->logger = & class_loader('Log', 'classes'); |
|
49 | 49 | $this->logger->setLogger('Library::ApcCache'); |
50 | 50 | } |
51 | 51 | } |
@@ -55,21 +55,21 @@ discard block |
||
55 | 55 | * @param string $key the key to identify the cache data |
56 | 56 | * @return mixed the cache data if exists else return false |
57 | 57 | */ |
58 | - public function get($key){ |
|
59 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
58 | + public function get($key) { |
|
59 | + $this->logger->debug('Getting cache data for key [' . $key . ']'); |
|
60 | 60 | $success = false; |
61 | 61 | $data = apc_fetch($key, $success); |
62 | - if($success === false){ |
|
63 | - $this->logger->info('No cache found for the key ['. $key .'], return false'); |
|
62 | + if ($success === false) { |
|
63 | + $this->logger->info('No cache found for the key [' . $key . '], return false'); |
|
64 | 64 | return false; |
65 | 65 | } |
66 | - else{ |
|
66 | + else { |
|
67 | 67 | $cacheInfo = $this->_getCacheInfo($key); |
68 | 68 | $expire = time(); |
69 | - if($cacheInfo){ |
|
69 | + if ($cacheInfo) { |
|
70 | 70 | $expire = $cacheInfo['creation_time'] + $cacheInfo['ttl']; |
71 | 71 | } |
72 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
72 | + $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
73 | 73 | return $data; |
74 | 74 | } |
75 | 75 | } |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | * @param integer $ttl the cache life time |
83 | 83 | * @return boolean true if success otherwise will return false |
84 | 84 | */ |
85 | - public function set($key, $data, $ttl = 0){ |
|
85 | + public function set($key, $data, $ttl = 0) { |
|
86 | 86 | $expire = time() + $ttl; |
87 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
87 | + $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
88 | 88 | $result = apc_store($key, $data, $ttl); |
89 | - if($result === false){ |
|
90 | - $this->logger->error('Can not write cache data for the key ['. $key .'], return false'); |
|
89 | + if ($result === false) { |
|
90 | + $this->logger->error('Can not write cache data for the key [' . $key . '], return false'); |
|
91 | 91 | return false; |
92 | 92 | } |
93 | - else{ |
|
94 | - $this->logger->info('Cache data saved for the key ['. $key .']'); |
|
93 | + else { |
|
94 | + $this->logger->info('Cache data saved for the key [' . $key . ']'); |
|
95 | 95 | return true; |
96 | 96 | } |
97 | 97 | } |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @return boolean true if the cache is deleted, false if can't delete |
104 | 104 | * the cache or the cache with the given key not exist |
105 | 105 | */ |
106 | - public function delete($key){ |
|
107 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
106 | + public function delete($key) { |
|
107 | + $this->logger->debug('Deleting of cache data for key [' . $key . ']'); |
|
108 | 108 | $cacheInfo = $this->_getCacheInfo($key); |
109 | - if($cacheInfo === false){ |
|
109 | + if ($cacheInfo === false) { |
|
110 | 110 | $this->logger->info('This cache data does not exists skipping'); |
111 | 111 | return false; |
112 | 112 | } |
113 | - else{ |
|
114 | - $this->logger->info('Found cache data for the key [' .$key. '] remove it'); |
|
113 | + else { |
|
114 | + $this->logger->info('Found cache data for the key [' . $key . '] remove it'); |
|
115 | 115 | return apc_delete($key) === true; |
116 | 116 | } |
117 | 117 | } |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | * 'expire' => expiration time of the cache (Unix timestamp), |
125 | 125 | * 'ttl' => the time to live of the cache in second |
126 | 126 | */ |
127 | - public function getInfo($key){ |
|
128 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
127 | + public function getInfo($key) { |
|
128 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
129 | 129 | $cacheInfos = $this->_getCacheInfo($key); |
130 | - if($cacheInfos){ |
|
130 | + if ($cacheInfos) { |
|
131 | 131 | $data = array( |
132 | 132 | 'mtime' => $cacheInfos['creation_time'], |
133 | 133 | 'expire' => $cacheInfos['creation_time'] + $cacheInfos['ttl'], |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ); |
136 | 136 | return $data; |
137 | 137 | } |
138 | - else{ |
|
138 | + else { |
|
139 | 139 | $this->logger->info('This cache does not exists skipping'); |
140 | 140 | return false; |
141 | 141 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * Used to delete expired cache data |
147 | 147 | */ |
148 | - public function deleteExpiredCache(){ |
|
148 | + public function deleteExpiredCache() { |
|
149 | 149 | //for APC[u] is done automatically |
150 | 150 | return true; |
151 | 151 | } |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * Remove all cache data |
155 | 155 | */ |
156 | - public function clean(){ |
|
156 | + public function clean() { |
|
157 | 157 | $this->logger->debug('Deleting of all cache data'); |
158 | 158 | $cacheInfos = apc_cache_info('user'); |
159 | - if(empty($cacheInfos['cache_list'])){ |
|
159 | + if (empty($cacheInfos['cache_list'])) { |
|
160 | 160 | $this->logger->info('No cache data were found skipping'); |
161 | 161 | return false; |
162 | 162 | } |
163 | - else{ |
|
163 | + else { |
|
164 | 164 | $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove'); |
165 | 165 | return apc_clear_cache('user'); |
166 | 166 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return bool |
174 | 174 | */ |
175 | - public function isSupported(){ |
|
175 | + public function isSupported() { |
|
176 | 176 | return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled'); |
177 | 177 | } |
178 | 178 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * Return the Log instance |
181 | 181 | * @return Log |
182 | 182 | */ |
183 | - public function getLogger(){ |
|
183 | + public function getLogger() { |
|
184 | 184 | return $this->logger; |
185 | 185 | } |
186 | 186 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * Set the log instance |
189 | 189 | * @param Log $logger the log object |
190 | 190 | */ |
191 | - public function setLogger(Log $logger){ |
|
191 | + public function setLogger(Log $logger) { |
|
192 | 192 | $this->logger = $logger; |
193 | 193 | return $this; |
194 | 194 | } |
@@ -199,12 +199,12 @@ discard block |
||
199 | 199 | * @param string $key the cache key to get the cache information |
200 | 200 | * @return boolean|array |
201 | 201 | */ |
202 | - private function _getCacheInfo($key){ |
|
202 | + private function _getCacheInfo($key) { |
|
203 | 203 | $caches = apc_cache_info('user'); |
204 | - if(! empty($caches['cache_list'])){ |
|
204 | + if (!empty($caches['cache_list'])) { |
|
205 | 205 | $cacheLists = $caches['cache_list']; |
206 | - foreach ($cacheLists as $c){ |
|
207 | - if(isset($c['info']) && $c['info'] === $key){ |
|
206 | + foreach ($cacheLists as $c) { |
|
207 | + if (isset($c['info']) && $c['info'] === $key) { |
|
208 | 208 | return $c; |
209 | 209 | } |
210 | 210 | } |
@@ -43,8 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | if(is_object($logger)){ |
45 | 45 | $this->logger = $logger; |
46 | - } |
|
47 | - else{ |
|
46 | + } else{ |
|
48 | 47 | $this->logger =& class_loader('Log', 'classes'); |
49 | 48 | $this->logger->setLogger('Library::ApcCache'); |
50 | 49 | } |
@@ -62,8 +61,7 @@ discard block |
||
62 | 61 | if($success === false){ |
63 | 62 | $this->logger->info('No cache found for the key ['. $key .'], return false'); |
64 | 63 | return false; |
65 | - } |
|
66 | - else{ |
|
64 | + } else{ |
|
67 | 65 | $cacheInfo = $this->_getCacheInfo($key); |
68 | 66 | $expire = time(); |
69 | 67 | if($cacheInfo){ |
@@ -89,8 +87,7 @@ discard block |
||
89 | 87 | if($result === false){ |
90 | 88 | $this->logger->error('Can not write cache data for the key ['. $key .'], return false'); |
91 | 89 | return false; |
92 | - } |
|
93 | - else{ |
|
90 | + } else{ |
|
94 | 91 | $this->logger->info('Cache data saved for the key ['. $key .']'); |
95 | 92 | return true; |
96 | 93 | } |
@@ -109,8 +106,7 @@ discard block |
||
109 | 106 | if($cacheInfo === false){ |
110 | 107 | $this->logger->info('This cache data does not exists skipping'); |
111 | 108 | return false; |
112 | - } |
|
113 | - else{ |
|
109 | + } else{ |
|
114 | 110 | $this->logger->info('Found cache data for the key [' .$key. '] remove it'); |
115 | 111 | return apc_delete($key) === true; |
116 | 112 | } |
@@ -134,8 +130,7 @@ discard block |
||
134 | 130 | 'ttl' => $cacheInfos['ttl'] |
135 | 131 | ); |
136 | 132 | return $data; |
137 | - } |
|
138 | - else{ |
|
133 | + } else{ |
|
139 | 134 | $this->logger->info('This cache does not exists skipping'); |
140 | 135 | return false; |
141 | 136 | } |
@@ -159,8 +154,7 @@ discard block |
||
159 | 154 | if(empty($cacheInfos['cache_list'])){ |
160 | 155 | $this->logger->info('No cache data were found skipping'); |
161 | 156 | return false; |
162 | - } |
|
163 | - else{ |
|
157 | + } else{ |
|
164 | 158 | $this->logger->info('Found [' . count($cacheInfos) . '] cache data to remove'); |
165 | 159 | return apc_clear_cache('user'); |
166 | 160 | } |
@@ -48,8 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | if(is_object($logger)){ |
50 | 50 | $this->logger = $logger; |
51 | - } |
|
52 | - else{ |
|
51 | + } else{ |
|
53 | 52 | $this->logger =& class_loader('Log', 'classes'); |
54 | 53 | $this->logger->setLogger('Library::FileCache'); |
55 | 54 | } |
@@ -95,8 +94,7 @@ discard block |
||
95 | 94 | // Unlinking when the file was expired |
96 | 95 | unlink($filePath); |
97 | 96 | return false; |
98 | - } |
|
99 | - else{ |
|
97 | + } else{ |
|
100 | 98 | $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
101 | 99 | return $data['data']; |
102 | 100 | } |
@@ -133,8 +131,7 @@ discard block |
||
133 | 131 | $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
134 | 132 | fclose($handle); |
135 | 133 | return false; |
136 | - } |
|
137 | - else{ |
|
134 | + } else{ |
|
138 | 135 | $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
139 | 136 | fclose($handle); |
140 | 137 | chmod($filePath, 0640); |
@@ -156,8 +153,7 @@ discard block |
||
156 | 153 | if(! file_exists($filePath)){ |
157 | 154 | $this->logger->info('This cache file does not exists skipping'); |
158 | 155 | return false; |
159 | - } |
|
160 | - else{ |
|
156 | + } else{ |
|
161 | 157 | $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
162 | 158 | unlink($filePath); |
163 | 159 | return true; |
@@ -179,16 +175,14 @@ discard block |
||
179 | 175 | if(! file_exists($filePath)){ |
180 | 176 | $this->logger->info('This cache file does not exists skipping'); |
181 | 177 | return false; |
182 | - } |
|
183 | - else{ |
|
178 | + } else{ |
|
184 | 179 | $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
185 | 180 | $data = file_get_contents($filePath); |
186 | 181 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
187 | 182 | if(! $data){ |
188 | 183 | $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
189 | 184 | return false; |
190 | - } |
|
191 | - else{ |
|
185 | + } else{ |
|
192 | 186 | $this->logger->info('This cache data is OK check for expire'); |
193 | 187 | if(isset($data['expire']) && $data['expire'] > time()){ |
194 | 188 | $this->logger->info('This cache not yet expired return cache informations'); |
@@ -198,8 +192,7 @@ discard block |
||
198 | 192 | 'ttl' => $data['ttl'] |
199 | 193 | ); |
200 | 194 | return $info; |
201 | - } |
|
202 | - else{ |
|
195 | + } else{ |
|
203 | 196 | $this->logger->info('This cache already expired return false'); |
204 | 197 | return false; |
205 | 198 | } |
@@ -216,8 +209,7 @@ discard block |
||
216 | 209 | $list = glob(CACHE_PATH . '*.cache'); |
217 | 210 | if(! $list){ |
218 | 211 | $this->logger->info('No cache files were found skipping'); |
219 | - } |
|
220 | - else{ |
|
212 | + } else{ |
|
221 | 213 | $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
222 | 214 | foreach ($list as $file) { |
223 | 215 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -225,12 +217,10 @@ discard block |
||
225 | 217 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
226 | 218 | if(! $data){ |
227 | 219 | $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
228 | - } |
|
229 | - else if(time() > $data['expire']){ |
|
220 | + } else if(time() > $data['expire']){ |
|
230 | 221 | $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
231 | 222 | unlink($file); |
232 | - } |
|
233 | - else{ |
|
223 | + } else{ |
|
234 | 224 | $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
235 | 225 | } |
236 | 226 | } |
@@ -245,8 +235,7 @@ discard block |
||
245 | 235 | $list = glob(CACHE_PATH . '*.cache'); |
246 | 236 | if(! $list){ |
247 | 237 | $this->logger->info('No cache files were found skipping'); |
248 | - } |
|
249 | - else{ |
|
238 | + } else{ |
|
250 | 239 | $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
251 | 240 | foreach ($list as $file) { |
252 | 241 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -273,8 +262,7 @@ discard block |
||
273 | 262 | |
274 | 263 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
275 | 264 | $this->compressCacheData = false; |
276 | - } |
|
277 | - else{ |
|
265 | + } else{ |
|
278 | 266 | $this->compressCacheData = $status; |
279 | 267 | } |
280 | 268 | return $this; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class FileCache implements CacheInterface{ |
28 | 28 | |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.'); |
45 | 45 | } |
46 | 46 | /** |
47 | - * instance of the Log class |
|
48 | - */ |
|
49 | - if(is_object($logger)){ |
|
50 | - $this->logger = $logger; |
|
51 | - } |
|
52 | - else{ |
|
53 | - $this->logger =& class_loader('Log', 'classes'); |
|
54 | - $this->logger->setLogger('Library::FileCache'); |
|
55 | - } |
|
47 | + * instance of the Log class |
|
48 | + */ |
|
49 | + if(is_object($logger)){ |
|
50 | + $this->logger = $logger; |
|
51 | + } |
|
52 | + else{ |
|
53 | + $this->logger =& class_loader('Log', 'classes'); |
|
54 | + $this->logger->setLogger('Library::FileCache'); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | //if Zlib extension is not loaded set compressCacheData to false |
58 | 58 | if(! extension_loaded('zlib')){ |
@@ -80,26 +80,26 @@ discard block |
||
80 | 80 | return false; |
81 | 81 | } |
82 | 82 | // Getting a shared lock |
83 | - flock($handle, LOCK_SH); |
|
84 | - $data = file_get_contents($filePath); |
|
85 | - fclose($handle); |
|
86 | - $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
87 | - if (! $data) { |
|
88 | - $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
89 | - // If unserializing somehow didn't work out, we'll delete the file |
|
90 | - unlink($filePath); |
|
91 | - return false; |
|
92 | - } |
|
93 | - if (time() > $data['expire']) { |
|
94 | - $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
95 | - // Unlinking when the file was expired |
|
96 | - unlink($filePath); |
|
97 | - return false; |
|
98 | - } |
|
99 | - else{ |
|
100 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
101 | - return $data['data']; |
|
102 | - } |
|
83 | + flock($handle, LOCK_SH); |
|
84 | + $data = file_get_contents($filePath); |
|
85 | + fclose($handle); |
|
86 | + $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
87 | + if (! $data) { |
|
88 | + $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
89 | + // If unserializing somehow didn't work out, we'll delete the file |
|
90 | + unlink($filePath); |
|
91 | + return false; |
|
92 | + } |
|
93 | + if (time() > $data['expire']) { |
|
94 | + $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
95 | + // Unlinking when the file was expired |
|
96 | + unlink($filePath); |
|
97 | + return false; |
|
98 | + } |
|
99 | + else{ |
|
100 | + $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
101 | + return $data['data']; |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -121,25 +121,25 @@ discard block |
||
121 | 121 | } |
122 | 122 | flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed |
123 | 123 | //Serializing along with the TTL |
124 | - $cacheData = serialize(array( |
|
124 | + $cacheData = serialize(array( |
|
125 | 125 | 'mtime' => time(), |
126 | 126 | 'expire' => $expire, |
127 | 127 | 'data' => $data, |
128 | 128 | 'ttl' => $ttl |
129 | 129 | ) |
130 | 130 | ); |
131 | - $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
|
132 | - if(! $result){ |
|
133 | - $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
134 | - fclose($handle); |
|
135 | - return false; |
|
136 | - } |
|
137 | - else{ |
|
138 | - $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
139 | - fclose($handle); |
|
131 | + $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
|
132 | + if(! $result){ |
|
133 | + $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
134 | + fclose($handle); |
|
135 | + return false; |
|
136 | + } |
|
137 | + else{ |
|
138 | + $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
139 | + fclose($handle); |
|
140 | 140 | chmod($filePath, 0640); |
141 | 141 | return true; |
142 | - } |
|
142 | + } |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | } |
160 | 160 | else{ |
161 | 161 | $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
162 | - unlink($filePath); |
|
162 | + unlink($filePath); |
|
163 | 163 | return true; |
164 | 164 | } |
165 | 165 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | else{ |
184 | 184 | $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
185 | - $data = file_get_contents($filePath); |
|
185 | + $data = file_get_contents($filePath); |
|
186 | 186 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
187 | 187 | if(! $data){ |
188 | 188 | $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
@@ -222,17 +222,17 @@ discard block |
||
222 | 222 | foreach ($list as $file) { |
223 | 223 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
224 | 224 | $data = file_get_contents($file); |
225 | - $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
226 | - if(! $data){ |
|
227 | - $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
|
228 | - } |
|
229 | - else if(time() > $data['expire']){ |
|
230 | - $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
|
231 | - unlink($file); |
|
232 | - } |
|
233 | - else{ |
|
234 | - $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
|
235 | - } |
|
225 | + $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
|
226 | + if(! $data){ |
|
227 | + $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
|
228 | + } |
|
229 | + else if(time() > $data['expire']){ |
|
230 | + $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
|
231 | + unlink($file); |
|
232 | + } |
|
233 | + else{ |
|
234 | + $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
|
235 | + } |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | } |
@@ -255,19 +255,19 @@ discard block |
||
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - /** |
|
259 | - * @return boolean |
|
260 | - */ |
|
261 | - public function isCompressCacheData(){ |
|
262 | - return $this->compressCacheData; |
|
263 | - } |
|
258 | + /** |
|
259 | + * @return boolean |
|
260 | + */ |
|
261 | + public function isCompressCacheData(){ |
|
262 | + return $this->compressCacheData; |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * @param boolean $compressCacheData |
|
267 | - * |
|
268 | - * @return object |
|
269 | - */ |
|
270 | - public function setCompressCacheData($status = true){ |
|
265 | + /** |
|
266 | + * @param boolean $compressCacheData |
|
267 | + * |
|
268 | + * @return object |
|
269 | + */ |
|
270 | + public function setCompressCacheData($status = true){ |
|
271 | 271 | //if Zlib extension is not loaded set compressCacheData to false |
272 | 272 | if($status === true && ! extension_loaded('zlib')){ |
273 | 273 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $this->compressCacheData = $status; |
279 | 279 | } |
280 | 280 | return $this; |
281 | - } |
|
281 | + } |
|
282 | 282 | |
283 | 283 | /** |
284 | 284 | * Check whether the cache feature for the handle is supported |
@@ -290,28 +290,28 @@ discard block |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | - * Return the Log instance |
|
294 | - * @return object |
|
295 | - */ |
|
296 | - public function getLogger(){ |
|
297 | - return $this->logger; |
|
298 | - } |
|
293 | + * Return the Log instance |
|
294 | + * @return object |
|
295 | + */ |
|
296 | + public function getLogger(){ |
|
297 | + return $this->logger; |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Set the log instance |
|
302 | - * @param Log $logger the log object |
|
303 | - */ |
|
304 | - public function setLogger(Log $logger){ |
|
305 | - $this->logger = $logger; |
|
306 | - return $this; |
|
307 | - } |
|
300 | + /** |
|
301 | + * Set the log instance |
|
302 | + * @param Log $logger the log object |
|
303 | + */ |
|
304 | + public function setLogger(Log $logger){ |
|
305 | + $this->logger = $logger; |
|
306 | + return $this; |
|
307 | + } |
|
308 | 308 | |
309 | 309 | /** |
310 | - * Get the cache file full path for the given key |
|
311 | - * |
|
312 | - * @param $key the cache item key |
|
313 | - * @return string |
|
314 | - */ |
|
310 | + * Get the cache file full path for the given key |
|
311 | + * |
|
312 | + * @param $key the cache item key |
|
313 | + * @return string |
|
314 | + */ |
|
315 | 315 | private function getFilePath($key){ |
316 | 316 | return CACHE_PATH . md5($key) . '.cache'; |
317 | 317 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class FileCache implements CacheInterface{ |
|
27 | + class FileCache implements CacheInterface { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Whether to enable compression of the cache data file. |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | private $logger; |
40 | 40 | |
41 | 41 | |
42 | - public function __construct(Log $logger = null){ |
|
43 | - if(! $this->isSupported()){ |
|
42 | + public function __construct(Log $logger = null) { |
|
43 | + if (!$this->isSupported()) { |
|
44 | 44 | show_error('The cache for file system is not available. Check the cache directory if is exists or is writable.'); |
45 | 45 | } |
46 | 46 | /** |
47 | 47 | * instance of the Log class |
48 | 48 | */ |
49 | - if(is_object($logger)){ |
|
49 | + if (is_object($logger)) { |
|
50 | 50 | $this->logger = $logger; |
51 | 51 | } |
52 | - else{ |
|
53 | - $this->logger =& class_loader('Log', 'classes'); |
|
52 | + else { |
|
53 | + $this->logger = & class_loader('Log', 'classes'); |
|
54 | 54 | $this->logger->setLogger('Library::FileCache'); |
55 | 55 | } |
56 | 56 | |
57 | 57 | //if Zlib extension is not loaded set compressCacheData to false |
58 | - if(! extension_loaded('zlib')){ |
|
58 | + if (!extension_loaded('zlib')) { |
|
59 | 59 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
60 | 60 | $this->compressCacheData = false; |
61 | 61 | } |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | * @param string $key the key to identify the cache data |
67 | 67 | * @return mixed the cache data if exists else return false |
68 | 68 | */ |
69 | - public function get($key){ |
|
70 | - $this->logger->debug('Getting cache data for key ['. $key .']'); |
|
69 | + public function get($key) { |
|
70 | + $this->logger->debug('Getting cache data for key [' . $key . ']'); |
|
71 | 71 | $filePath = $this->getFilePath($key); |
72 | - if(! file_exists($filePath)){ |
|
73 | - $this->logger->info('No cache file found for the key ['. $key .'], return false'); |
|
72 | + if (!file_exists($filePath)) { |
|
73 | + $this->logger->info('No cache file found for the key [' . $key . '], return false'); |
|
74 | 74 | return false; |
75 | 75 | } |
76 | - $this->logger->info('The cache file [' .$filePath. '] for the key ['. $key .'] exists, check if the cache data is valid'); |
|
77 | - $handle = fopen($filePath,'r'); |
|
78 | - if(! is_resource($handle)){ |
|
79 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
76 | + $this->logger->info('The cache file [' . $filePath . '] for the key [' . $key . '] exists, check if the cache data is valid'); |
|
77 | + $handle = fopen($filePath, 'r'); |
|
78 | + if (!is_resource($handle)) { |
|
79 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
80 | 80 | return false; |
81 | 81 | } |
82 | 82 | // Getting a shared lock |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | $data = file_get_contents($filePath); |
85 | 85 | fclose($handle); |
86 | 86 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
87 | - if (! $data) { |
|
88 | - $this->logger->error('Can not unserialize the cache data for the key ['. $key .'], return false'); |
|
87 | + if (!$data) { |
|
88 | + $this->logger->error('Can not unserialize the cache data for the key [' . $key . '], return false'); |
|
89 | 89 | // If unserializing somehow didn't work out, we'll delete the file |
90 | 90 | unlink($filePath); |
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | if (time() > $data['expire']) { |
94 | - $this->logger->info('The cache data for the key ['. $key .'] already expired delete the cache file [' .$filePath. ']'); |
|
94 | + $this->logger->info('The cache data for the key [' . $key . '] already expired delete the cache file [' . $filePath . ']'); |
|
95 | 95 | // Unlinking when the file was expired |
96 | 96 | unlink($filePath); |
97 | 97 | return false; |
98 | 98 | } |
99 | - else{ |
|
100 | - $this->logger->info('The cache not yet expire, now return the cache data for key ['. $key .'], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
99 | + else { |
|
100 | + $this->logger->info('The cache not yet expire, now return the cache data for key [' . $key . '], the cache will expire at [' . date('Y-m-d H:i:s', $data['expire']) . ']'); |
|
101 | 101 | return $data['data']; |
102 | 102 | } |
103 | 103 | } |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | * @param integer $ttl the cache life time |
111 | 111 | * @return boolean true if success otherwise will return false |
112 | 112 | */ |
113 | - public function set($key, $data, $ttl = 0){ |
|
113 | + public function set($key, $data, $ttl = 0) { |
|
114 | 114 | $expire = time() + $ttl; |
115 | - $this->logger->debug('Setting cache data for key ['. $key .'], time to live [' .$ttl. '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
115 | + $this->logger->debug('Setting cache data for key [' . $key . '], time to live [' . $ttl . '], expire at [' . date('Y-m-d H:i:s', $expire) . ']'); |
|
116 | 116 | $filePath = $this->getFilePath($key); |
117 | - $handle = fopen($filePath,'w'); |
|
118 | - if(! is_resource($handle)){ |
|
119 | - $this->logger->error('Can not open the file cache [' .$filePath. '] for the key ['. $key .'], return false'); |
|
117 | + $handle = fopen($filePath, 'w'); |
|
118 | + if (!is_resource($handle)) { |
|
119 | + $this->logger->error('Can not open the file cache [' . $filePath . '] for the key [' . $key . '], return false'); |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | flock($handle, LOCK_EX); // exclusive lock, will get released when the file is closed |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | ) |
130 | 130 | ); |
131 | 131 | $result = fwrite($handle, $this->compressCacheData ? gzdeflate($cacheData, 9) : $cacheData); |
132 | - if(! $result){ |
|
133 | - $this->logger->error('Can not write cache data into file [' .$filePath. '] for the key ['. $key .'], return false'); |
|
132 | + if (!$result) { |
|
133 | + $this->logger->error('Can not write cache data into file [' . $filePath . '] for the key [' . $key . '], return false'); |
|
134 | 134 | fclose($handle); |
135 | 135 | return false; |
136 | 136 | } |
137 | - else{ |
|
138 | - $this->logger->info('Cache data saved into file [' .$filePath. '] for the key ['. $key .']'); |
|
137 | + else { |
|
138 | + $this->logger->info('Cache data saved into file [' . $filePath . '] for the key [' . $key . ']'); |
|
139 | 139 | fclose($handle); |
140 | 140 | chmod($filePath, 0640); |
141 | 141 | return true; |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | * @return boolean true if the cache is delete, false if can't delete |
150 | 150 | * the cache or the cache with the given key not exist |
151 | 151 | */ |
152 | - public function delete($key){ |
|
153 | - $this->logger->debug('Deleting of cache data for key [' .$key. ']'); |
|
152 | + public function delete($key) { |
|
153 | + $this->logger->debug('Deleting of cache data for key [' . $key . ']'); |
|
154 | 154 | $filePath = $this->getFilePath($key); |
155 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
156 | - if(! file_exists($filePath)){ |
|
155 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
156 | + if (!file_exists($filePath)) { |
|
157 | 157 | $this->logger->info('This cache file does not exists skipping'); |
158 | 158 | return false; |
159 | 159 | } |
160 | - else{ |
|
161 | - $this->logger->info('Found cache file [' .$filePath. '] remove it'); |
|
160 | + else { |
|
161 | + $this->logger->info('Found cache file [' . $filePath . '] remove it'); |
|
162 | 162 | unlink($filePath); |
163 | 163 | return true; |
164 | 164 | } |
@@ -172,25 +172,25 @@ discard block |
||
172 | 172 | * 'expire' => expiration time of the cache (Unix timestamp), |
173 | 173 | * 'ttl' => the time to live of the cache in second |
174 | 174 | */ |
175 | - public function getInfo($key){ |
|
176 | - $this->logger->debug('Getting of cache info for key [' .$key. ']'); |
|
175 | + public function getInfo($key) { |
|
176 | + $this->logger->debug('Getting of cache info for key [' . $key . ']'); |
|
177 | 177 | $filePath = $this->getFilePath($key); |
178 | - $this->logger->info('The file path for the key [' .$key. '] is [' .$filePath. ']'); |
|
179 | - if(! file_exists($filePath)){ |
|
178 | + $this->logger->info('The file path for the key [' . $key . '] is [' . $filePath . ']'); |
|
179 | + if (!file_exists($filePath)) { |
|
180 | 180 | $this->logger->info('This cache file does not exists skipping'); |
181 | 181 | return false; |
182 | 182 | } |
183 | - else{ |
|
184 | - $this->logger->info('Found cache file [' .$filePath. '] check the validity'); |
|
183 | + else { |
|
184 | + $this->logger->info('Found cache file [' . $filePath . '] check the validity'); |
|
185 | 185 | $data = file_get_contents($filePath); |
186 | 186 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
187 | - if(! $data){ |
|
187 | + if (!$data) { |
|
188 | 188 | $this->logger->warning('Can not unserialize the cache data for file [' . $filePath . ']'); |
189 | 189 | return false; |
190 | 190 | } |
191 | - else{ |
|
191 | + else { |
|
192 | 192 | $this->logger->info('This cache data is OK check for expire'); |
193 | - if(isset($data['expire']) && $data['expire'] > time()){ |
|
193 | + if (isset($data['expire']) && $data['expire'] > time()) { |
|
194 | 194 | $this->logger->info('This cache not yet expired return cache informations'); |
195 | 195 | $info = array( |
196 | 196 | 'mtime' => $data['mtime'], |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | ); |
200 | 200 | return $info; |
201 | 201 | } |
202 | - else{ |
|
202 | + else { |
|
203 | 203 | $this->logger->info('This cache already expired return false'); |
204 | 204 | return false; |
205 | 205 | } |
@@ -211,26 +211,26 @@ discard block |
||
211 | 211 | /** |
212 | 212 | * Used to delete expired cache data |
213 | 213 | */ |
214 | - public function deleteExpiredCache(){ |
|
214 | + public function deleteExpiredCache() { |
|
215 | 215 | $this->logger->debug('Deleting of expired cache files'); |
216 | 216 | $list = glob(CACHE_PATH . '*.cache'); |
217 | - if(! $list){ |
|
217 | + if (!$list) { |
|
218 | 218 | $this->logger->info('No cache files were found skipping'); |
219 | 219 | } |
220 | - else{ |
|
220 | + else { |
|
221 | 221 | $this->logger->info('Found [' . count($list) . '] cache files to remove if expired'); |
222 | 222 | foreach ($list as $file) { |
223 | 223 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
224 | 224 | $data = file_get_contents($file); |
225 | 225 | $data = @unserialize($this->compressCacheData ? gzinflate($data) : $data); |
226 | - if(! $data){ |
|
226 | + if (!$data) { |
|
227 | 227 | $this->logger->warning('Can not unserialize the cache data for file [' . $file . ']'); |
228 | 228 | } |
229 | - else if(time() > $data['expire']){ |
|
229 | + else if (time() > $data['expire']) { |
|
230 | 230 | $this->logger->info('The cache data for file [' . $file . '] already expired remove it'); |
231 | 231 | unlink($file); |
232 | 232 | } |
233 | - else{ |
|
233 | + else { |
|
234 | 234 | $this->logger->info('The cache data for file [' . $file . '] not yet expired skip it'); |
235 | 235 | } |
236 | 236 | } |
@@ -240,13 +240,13 @@ discard block |
||
240 | 240 | /** |
241 | 241 | * Remove all file from cache folder |
242 | 242 | */ |
243 | - public function clean(){ |
|
243 | + public function clean() { |
|
244 | 244 | $this->logger->debug('Deleting of all cache files'); |
245 | 245 | $list = glob(CACHE_PATH . '*.cache'); |
246 | - if(! $list){ |
|
246 | + if (!$list) { |
|
247 | 247 | $this->logger->info('No cache files were found skipping'); |
248 | 248 | } |
249 | - else{ |
|
249 | + else { |
|
250 | 250 | $this->logger->info('Found [' . count($list) . '] cache files to remove'); |
251 | 251 | foreach ($list as $file) { |
252 | 252 | $this->logger->debug('Processing the cache file [' . $file . ']'); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | /** |
259 | 259 | * @return boolean |
260 | 260 | */ |
261 | - public function isCompressCacheData(){ |
|
261 | + public function isCompressCacheData() { |
|
262 | 262 | return $this->compressCacheData; |
263 | 263 | } |
264 | 264 | |
@@ -267,14 +267,14 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @return object |
269 | 269 | */ |
270 | - public function setCompressCacheData($status = true){ |
|
270 | + public function setCompressCacheData($status = true) { |
|
271 | 271 | //if Zlib extension is not loaded set compressCacheData to false |
272 | - if($status === true && ! extension_loaded('zlib')){ |
|
272 | + if ($status === true && !extension_loaded('zlib')) { |
|
273 | 273 | |
274 | 274 | $this->logger->warning('The zlib extension is not loaded set cache compress data to FALSE'); |
275 | 275 | $this->compressCacheData = false; |
276 | 276 | } |
277 | - else{ |
|
277 | + else { |
|
278 | 278 | $this->compressCacheData = $status; |
279 | 279 | } |
280 | 280 | return $this; |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return bool |
287 | 287 | */ |
288 | - public function isSupported(){ |
|
288 | + public function isSupported() { |
|
289 | 289 | return CACHE_PATH && is_dir(CACHE_PATH) && is_writable(CACHE_PATH); |
290 | 290 | } |
291 | 291 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * Return the Log instance |
294 | 294 | * @return object |
295 | 295 | */ |
296 | - public function getLogger(){ |
|
296 | + public function getLogger() { |
|
297 | 297 | return $this->logger; |
298 | 298 | } |
299 | 299 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * Set the log instance |
302 | 302 | * @param Log $logger the log object |
303 | 303 | */ |
304 | - public function setLogger(Log $logger){ |
|
304 | + public function setLogger(Log $logger) { |
|
305 | 305 | $this->logger = $logger; |
306 | 306 | return $this; |
307 | 307 | } |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @param $key the cache item key |
313 | 313 | * @return string |
314 | 314 | */ |
315 | - private function getFilePath($key){ |
|
315 | + private function getFilePath($key) { |
|
316 | 316 | return CACHE_PATH . md5($key) . '.cache'; |
317 | 317 | } |
318 | 318 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class Response{ |
28 | 28 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | private $_currentUrlCacheKey = null; |
58 | 58 | |
59 | 59 | /** |
60 | - * Whether we can compress the output using Gzip |
|
61 | - * @var boolean |
|
62 | - */ |
|
60 | + * Whether we can compress the output using Gzip |
|
61 | + * @var boolean |
|
62 | + */ |
|
63 | 63 | private static $_canCompressOutput = false; |
64 | 64 | |
65 | 65 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
239 | - * Send the final page output to user |
|
240 | - */ |
|
239 | + * Send the final page output to user |
|
240 | + */ |
|
241 | 241 | public function renderFinalPage(){ |
242 | 242 | $logger = self::getLogger(); |
243 | 243 | $obj = & get_instance(); |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
304 | - * Send the final page output to user if is cached |
|
305 | - */ |
|
304 | + * Send the final page output to user if is cached |
|
305 | + */ |
|
306 | 306 | public function renderFinalPageFromCache(&$cache){ |
307 | 307 | $logger = self::getLogger(); |
308 | 308 | $url = $this->_currentUrl; |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
365 | - * Get the final page to be rendered |
|
366 | - * @return string |
|
367 | - */ |
|
365 | + * Get the final page to be rendered |
|
366 | + * @return string |
|
367 | + */ |
|
368 | 368 | public function getFinalPageRendered(){ |
369 | 369 | return $this->_pageRender; |
370 | 370 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Response{ |
|
27 | + class Response { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of request header to send with response |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Construct new response instance |
67 | 67 | */ |
68 | - public function __construct(){ |
|
69 | - $this->_currentUrl = (! empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' ) |
|
70 | - . (! empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : '' ); |
|
68 | + public function __construct() { |
|
69 | + $this->_currentUrl = (!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') |
|
70 | + . (!empty($_SERVER['QUERY_STRING']) ? ('?' . $_SERVER['QUERY_STRING']) : ''); |
|
71 | 71 | |
72 | 72 | $this->_currentUrlCacheKey = md5($this->_currentUrl); |
73 | 73 | |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * Get the logger singleton instance |
83 | 83 | * @return Log the logger instance |
84 | 84 | */ |
85 | - private static function getLogger(){ |
|
86 | - if(self::$logger == null){ |
|
87 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
85 | + private static function getLogger() { |
|
86 | + if (self::$logger == null) { |
|
87 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
88 | 88 | self::$logger[0]->setLogger('Library::Response'); |
89 | 89 | } |
90 | 90 | return self::$logger[0]; |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | * @param integer $httpCode the HTTP status code |
96 | 96 | * @param array $headers the additional headers to add to the existing headers list |
97 | 97 | */ |
98 | - public static function sendHeaders($httpCode = 200, array $headers = array()){ |
|
98 | + public static function sendHeaders($httpCode = 200, array $headers = array()) { |
|
99 | 99 | set_http_status_header($httpCode); |
100 | 100 | self::setHeaders($headers); |
101 | - if(! headers_sent()){ |
|
102 | - foreach(self::getHeaders() as $key => $value){ |
|
103 | - header($key .': '.$value); |
|
101 | + if (!headers_sent()) { |
|
102 | + foreach (self::getHeaders() as $key => $value) { |
|
103 | + header($key . ': ' . $value); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * Get the list of the headers |
110 | 110 | * @return array the headers list |
111 | 111 | */ |
112 | - public static function getHeaders(){ |
|
112 | + public static function getHeaders() { |
|
113 | 113 | return self::$headers; |
114 | 114 | } |
115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param string $name the header name |
119 | 119 | * @return string the header value |
120 | 120 | */ |
121 | - public static function getHeader($name){ |
|
121 | + public static function getHeader($name) { |
|
122 | 122 | return array_key_exists($name, self::$headers) ? self::$headers[$name] : null; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param string $name the header name |
129 | 129 | * @param string $value the header value to be set |
130 | 130 | */ |
131 | - public static function setHeader($name, $value){ |
|
131 | + public static function setHeader($name, $value) { |
|
132 | 132 | self::$headers[$name] = $value; |
133 | 133 | } |
134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param array $headers the list of the headers to set. |
138 | 138 | * Note: this will merge with the existing headers |
139 | 139 | */ |
140 | - public static function setHeaders(array $headers){ |
|
140 | + public static function setHeaders(array $headers) { |
|
141 | 141 | self::$headers = array_merge(self::getHeaders(), $headers); |
142 | 142 | } |
143 | 143 | |
@@ -145,17 +145,17 @@ discard block |
||
145 | 145 | * Redirect user in the specified page |
146 | 146 | * @param string $path the URL or URI to be redirect to |
147 | 147 | */ |
148 | - public static function redirect($path = ''){ |
|
148 | + public static function redirect($path = '') { |
|
149 | 149 | $logger = self::getLogger(); |
150 | 150 | $url = Url::site_url($path); |
151 | - $logger->info('Redirect to URL [' .$url. ']'); |
|
152 | - if(! headers_sent()){ |
|
153 | - header('Location: '.$url); |
|
151 | + $logger->info('Redirect to URL [' . $url . ']'); |
|
152 | + if (!headers_sent()) { |
|
153 | + header('Location: ' . $url); |
|
154 | 154 | exit; |
155 | 155 | } |
156 | - else{ |
|
156 | + else { |
|
157 | 157 | echo '<script> |
158 | - location.href = "'.$url.'"; |
|
158 | + location.href = "'.$url . '"; |
|
159 | 159 | </script>'; |
160 | 160 | } |
161 | 161 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | * @return void|string if $return is true will return the view content otherwise |
169 | 169 | * will display the view content. |
170 | 170 | */ |
171 | - public function render($view, $data = null, $return = false){ |
|
171 | + public function render($view, $data = null, $return = false) { |
|
172 | 172 | $logger = self::getLogger(); |
173 | 173 | //convert data to an array |
174 | - $data = ! is_array($data) ? (array) $data : $data; |
|
174 | + $data = !is_array($data) ? (array) $data : $data; |
|
175 | 175 | $view = str_ireplace('.php', '', $view); |
176 | 176 | $view = trim($view, '/\\'); |
177 | 177 | $viewFile = $view . '.php'; |
@@ -180,42 +180,42 @@ discard block |
||
180 | 180 | //super instance |
181 | 181 | $obj = & get_instance(); |
182 | 182 | |
183 | - if(Module::hasModule()){ |
|
183 | + if (Module::hasModule()) { |
|
184 | 184 | //check in module first |
185 | 185 | $logger->debug('Checking the view [' . $view . '] from module list ...'); |
186 | 186 | $mod = null; |
187 | 187 | //check if the request class contains module name |
188 | - if(strpos($view, '/') !== false){ |
|
188 | + if (strpos($view, '/') !== false) { |
|
189 | 189 | $viewPath = explode('/', $view); |
190 | - if(isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())){ |
|
190 | + if (isset($viewPath[0]) && in_array($viewPath[0], Module::getModuleList())) { |
|
191 | 191 | $mod = $viewPath[0]; |
192 | 192 | array_shift($viewPath); |
193 | 193 | $view = implode('/', $viewPath); |
194 | 194 | $viewFile = $view . '.php'; |
195 | 195 | } |
196 | 196 | } |
197 | - if(! $mod && !empty($obj->moduleName)){ |
|
197 | + if (!$mod && !empty($obj->moduleName)) { |
|
198 | 198 | $mod = $obj->moduleName; |
199 | 199 | } |
200 | - if($mod){ |
|
200 | + if ($mod) { |
|
201 | 201 | $moduleViewPath = Module::findViewFullPath($view, $mod); |
202 | - if($moduleViewPath){ |
|
202 | + if ($moduleViewPath) { |
|
203 | 203 | $path = $moduleViewPath; |
204 | - $logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it'); |
|
204 | + $logger->info('Found view [' . $view . '] in module [' . $mod . '], the file path is [' . $moduleViewPath . '] we will used it'); |
|
205 | 205 | } |
206 | - else{ |
|
207 | - $logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location'); |
|
206 | + else { |
|
207 | + $logger->info('Cannot find view [' . $view . '] in module [' . $mod . '] using the default location'); |
|
208 | 208 | } |
209 | 209 | } |
210 | - else{ |
|
210 | + else { |
|
211 | 211 | $logger->info('The current request does not use module using the default location.'); |
212 | 212 | } |
213 | 213 | } |
214 | 214 | $logger->info('The view file path to be loaded is [' . $path . ']'); |
215 | 215 | $found = false; |
216 | - if(file_exists($path)){ |
|
217 | - foreach(get_object_vars($obj) as $key => $value){ |
|
218 | - if(! isset($this->{$key})){ |
|
216 | + if (file_exists($path)) { |
|
217 | + foreach (get_object_vars($obj) as $key => $value) { |
|
218 | + if (!isset($this->{$key})) { |
|
219 | 219 | $this->{$key} = & $obj->{$key}; |
220 | 220 | } |
221 | 221 | } |
@@ -224,44 +224,44 @@ discard block |
||
224 | 224 | //need use require() instead of require_once because can load this view many time |
225 | 225 | require $path; |
226 | 226 | $content = ob_get_clean(); |
227 | - if($return){ |
|
227 | + if ($return) { |
|
228 | 228 | return $content; |
229 | 229 | } |
230 | 230 | $this->_pageRender .= $content; |
231 | 231 | $found = true; |
232 | 232 | } |
233 | - if(! $found){ |
|
234 | - show_error('Unable to find view [' .$view . ']'); |
|
233 | + if (!$found) { |
|
234 | + show_error('Unable to find view [' . $view . ']'); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
239 | 239 | * Send the final page output to user |
240 | 240 | */ |
241 | - public function renderFinalPage(){ |
|
241 | + public function renderFinalPage() { |
|
242 | 242 | $logger = self::getLogger(); |
243 | 243 | $obj = & get_instance(); |
244 | 244 | $cachePageStatus = get_config('cache_enable', false) && !empty($obj->view_cache_enable); |
245 | 245 | $dispatcher = $obj->eventdispatcher; |
246 | 246 | $content = $this->_pageRender; |
247 | - if(! $content){ |
|
247 | + if (!$content) { |
|
248 | 248 | $logger->warning('The final view content is empty.'); |
249 | 249 | return; |
250 | 250 | } |
251 | 251 | //dispatch |
252 | 252 | $event = $dispatcher->dispatch(new EventInfo('FINAL_VIEW_READY', $content, true)); |
253 | - $content = ! empty($event->payload) ? $event->payload : null; |
|
254 | - if(empty($content)){ |
|
253 | + $content = !empty($event->payload) ? $event->payload : null; |
|
254 | + if (empty($content)) { |
|
255 | 255 | $logger->warning('The view content is empty after dispatch to event listeners.'); |
256 | 256 | } |
257 | 257 | |
258 | 258 | //check whether need save the page into cache. |
259 | - if($cachePageStatus){ |
|
259 | + if ($cachePageStatus) { |
|
260 | 260 | //current page URL |
261 | 261 | $url = $this->_currentUrl; |
262 | 262 | //Cache view Time to live in second |
263 | 263 | $viewCacheTtl = get_config('cache_ttl'); |
264 | - if (!empty($obj->view_cache_ttl)){ |
|
264 | + if (!empty($obj->view_cache_ttl)) { |
|
265 | 265 | $viewCacheTtl = $obj->view_cache_ttl; |
266 | 266 | } |
267 | 267 | //the cache handler instance |
@@ -274,14 +274,14 @@ discard block |
||
274 | 274 | |
275 | 275 | //get the cache information to prepare header to send to browser |
276 | 276 | $cacheInfo = $cacheInstance->getInfo($cacheKey); |
277 | - if($cacheInfo){ |
|
277 | + if ($cacheInfo) { |
|
278 | 278 | $lastModified = $cacheInfo['mtime']; |
279 | 279 | $expire = $cacheInfo['expire']; |
280 | 280 | $maxAge = $expire - time(); |
281 | 281 | self::setHeader('Pragma', 'public'); |
282 | 282 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
283 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
284 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
283 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
284 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | |
294 | 294 | //compress the output if is available |
295 | 295 | $type = null; |
296 | - if (self::$_canCompressOutput){ |
|
296 | + if (self::$_canCompressOutput) { |
|
297 | 297 | $type = 'ob_gzhandler'; |
298 | 298 | } |
299 | 299 | ob_start($type); |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | /** |
306 | 306 | * Send the final page output to user if is cached |
307 | 307 | */ |
308 | - public function renderFinalPageFromCache(&$cache){ |
|
308 | + public function renderFinalPageFromCache(&$cache) { |
|
309 | 309 | $logger = self::getLogger(); |
310 | 310 | $url = $this->_currentUrl; |
311 | 311 | //the current page cache key for identification |
@@ -314,25 +314,25 @@ discard block |
||
314 | 314 | $logger->debug('Checking if the page content for the URL [' . $url . '] is cached ...'); |
315 | 315 | //get the cache information to prepare header to send to browser |
316 | 316 | $cacheInfo = $cache->getInfo($pageCacheKey); |
317 | - if($cacheInfo){ |
|
317 | + if ($cacheInfo) { |
|
318 | 318 | $lastModified = $cacheInfo['mtime']; |
319 | 319 | $expire = $cacheInfo['expire']; |
320 | 320 | $maxAge = $expire - $_SERVER['REQUEST_TIME']; |
321 | 321 | self::setHeader('Pragma', 'public'); |
322 | 322 | self::setHeader('Cache-Control', 'max-age=' . $maxAge . ', public'); |
323 | - self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire).' GMT'); |
|
324 | - self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified).' GMT'); |
|
325 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ |
|
323 | + self::setHeader('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); |
|
324 | + self::setHeader('Last-modified', gmdate('D, d M Y H:i:s', $lastModified) . ' GMT'); |
|
325 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { |
|
326 | 326 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
327 | 327 | self::sendHeaders(304); |
328 | 328 | return; |
329 | 329 | } |
330 | - else{ |
|
330 | + else { |
|
331 | 331 | $logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser'); |
332 | 332 | self::sendHeaders(200); |
333 | 333 | //get the cache content |
334 | 334 | $content = $cache->get($pageCacheKey); |
335 | - if($content){ |
|
335 | + if ($content) { |
|
336 | 336 | $logger->info('The page content for the URL [' . $url . '] already cached just display it'); |
337 | 337 | //load benchmark class |
338 | 338 | $benchmark = & class_loader('Benchmark'); |
@@ -345,17 +345,17 @@ discard block |
||
345 | 345 | |
346 | 346 | ///display the final output |
347 | 347 | //compress the output if is available |
348 | - if (self::$_canCompressOutput){ |
|
348 | + if (self::$_canCompressOutput) { |
|
349 | 349 | ob_start('ob_gzhandler'); |
350 | 350 | } |
351 | - else{ |
|
351 | + else { |
|
352 | 352 | ob_start(); |
353 | 353 | } |
354 | 354 | echo $content; |
355 | 355 | ob_end_flush(); |
356 | 356 | return; |
357 | 357 | } |
358 | - else{ |
|
358 | + else { |
|
359 | 359 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
360 | 360 | $cache->delete($pageCacheKey); |
361 | 361 | } |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * Get the final page to be rendered |
368 | 368 | * @return string |
369 | 369 | */ |
370 | - public function getFinalPageRendered(){ |
|
370 | + public function getFinalPageRendered() { |
|
371 | 371 | return $this->_pageRender; |
372 | 372 | } |
373 | 373 | |
@@ -375,14 +375,14 @@ discard block |
||
375 | 375 | * Send the HTTP 404 error if can not found the |
376 | 376 | * routing information for the current request |
377 | 377 | */ |
378 | - public static function send404(){ |
|
378 | + public static function send404() { |
|
379 | 379 | /********* for logs **************/ |
380 | 380 | //can't use $obj = & get_instance() here because the global super object will be available until |
381 | 381 | //the main controller is loaded even for Loader::library('xxxx'); |
382 | 382 | $logger = self::getLogger(); |
383 | - $request =& class_loader('Request', 'classes'); |
|
384 | - $userAgent =& class_loader('Browser'); |
|
385 | - $browser = $userAgent->getPlatform().', '.$userAgent->getBrowser().' '.$userAgent->getVersion(); |
|
383 | + $request = & class_loader('Request', 'classes'); |
|
384 | + $userAgent = & class_loader('Browser'); |
|
385 | + $browser = $userAgent->getPlatform() . ', ' . $userAgent->getBrowser() . ' ' . $userAgent->getVersion(); |
|
386 | 386 | |
387 | 387 | //here can't use Loader::functions just include the helper manually |
388 | 388 | require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
@@ -392,12 +392,12 @@ discard block |
||
392 | 392 | $logger->error($str); |
393 | 393 | /***********************************/ |
394 | 394 | $path = CORE_VIEWS_PATH . '404.php'; |
395 | - if(file_exists($path)){ |
|
395 | + if (file_exists($path)) { |
|
396 | 396 | //compress the output if is available |
397 | - if (self::$_canCompressOutput){ |
|
397 | + if (self::$_canCompressOutput) { |
|
398 | 398 | ob_start('ob_gzhandler'); |
399 | 399 | } |
400 | - else{ |
|
400 | + else { |
|
401 | 401 | ob_start(); |
402 | 402 | } |
403 | 403 | require_once $path; |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | self::sendHeaders(404); |
406 | 406 | echo $output; |
407 | 407 | } |
408 | - else{ |
|
409 | - show_error('The 404 view [' .$path. '] does not exist'); |
|
408 | + else { |
|
409 | + show_error('The 404 view [' . $path . '] does not exist'); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
@@ -414,14 +414,14 @@ discard block |
||
414 | 414 | * Display the error to user |
415 | 415 | * @param array $data the error information |
416 | 416 | */ |
417 | - public static function sendError(array $data = array()){ |
|
417 | + public static function sendError(array $data = array()) { |
|
418 | 418 | $path = CORE_VIEWS_PATH . 'errors.php'; |
419 | - if(file_exists($path)){ |
|
419 | + if (file_exists($path)) { |
|
420 | 420 | //compress the output if exists |
421 | - if (self::$_canCompressOutput){ |
|
421 | + if (self::$_canCompressOutput) { |
|
422 | 422 | ob_start('ob_gzhandler'); |
423 | 423 | } |
424 | - else{ |
|
424 | + else { |
|
425 | 425 | ob_start(); |
426 | 426 | } |
427 | 427 | extract($data); |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | self::sendHeaders(503); |
431 | 431 | echo $output; |
432 | 432 | } |
433 | - else{ |
|
433 | + else { |
|
434 | 434 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
435 | 435 | set_http_status_header(503); |
436 | 436 | echo 'The error view [' . $path . '] does not exist'; |
@@ -152,8 +152,7 @@ discard block |
||
152 | 152 | if(! headers_sent()){ |
153 | 153 | header('Location: '.$url); |
154 | 154 | exit; |
155 | - } |
|
156 | - else{ |
|
155 | + } else{ |
|
157 | 156 | echo '<script> |
158 | 157 | location.href = "'.$url.'"; |
159 | 158 | </script>'; |
@@ -202,12 +201,10 @@ discard block |
||
202 | 201 | if($moduleViewPath){ |
203 | 202 | $path = $moduleViewPath; |
204 | 203 | $logger->info('Found view [' . $view . '] in module [' .$mod. '], the file path is [' .$moduleViewPath. '] we will used it'); |
205 | - } |
|
206 | - else{ |
|
204 | + } else{ |
|
207 | 205 | $logger->info('Cannot find view [' . $view . '] in module [' .$mod. '] using the default location'); |
208 | 206 | } |
209 | - } |
|
210 | - else{ |
|
207 | + } else{ |
|
211 | 208 | $logger->info('The current request does not use module using the default location.'); |
212 | 209 | } |
213 | 210 | } |
@@ -326,8 +323,7 @@ discard block |
||
326 | 323 | $logger->info('The cache page content is not yet expire for the URL [' . $url . '] send 304 header to browser'); |
327 | 324 | self::sendHeaders(304); |
328 | 325 | return; |
329 | - } |
|
330 | - else{ |
|
326 | + } else{ |
|
331 | 327 | $logger->info('The cache page content is expired or the browser don\'t send the HTTP_IF_MODIFIED_SINCE header for the URL [' . $url . '] send cache headers to tell the browser'); |
332 | 328 | self::sendHeaders(200); |
333 | 329 | //get the cache content |
@@ -347,15 +343,13 @@ discard block |
||
347 | 343 | //compress the output if is available |
348 | 344 | if (self::$_canCompressOutput){ |
349 | 345 | ob_start('ob_gzhandler'); |
350 | - } |
|
351 | - else{ |
|
346 | + } else{ |
|
352 | 347 | ob_start(); |
353 | 348 | } |
354 | 349 | echo $content; |
355 | 350 | ob_end_flush(); |
356 | 351 | return; |
357 | - } |
|
358 | - else{ |
|
352 | + } else{ |
|
359 | 353 | $logger->info('The page cache content for the URL [' . $url . '] is not valid may be already expired'); |
360 | 354 | $cache->delete($pageCacheKey); |
361 | 355 | } |
@@ -396,16 +390,14 @@ discard block |
||
396 | 390 | //compress the output if is available |
397 | 391 | if (self::$_canCompressOutput){ |
398 | 392 | ob_start('ob_gzhandler'); |
399 | - } |
|
400 | - else{ |
|
393 | + } else{ |
|
401 | 394 | ob_start(); |
402 | 395 | } |
403 | 396 | require_once $path; |
404 | 397 | $output = ob_get_clean(); |
405 | 398 | self::sendHeaders(404); |
406 | 399 | echo $output; |
407 | - } |
|
408 | - else{ |
|
400 | + } else{ |
|
409 | 401 | show_error('The 404 view [' .$path. '] does not exist'); |
410 | 402 | } |
411 | 403 | } |
@@ -420,8 +412,7 @@ discard block |
||
420 | 412 | //compress the output if exists |
421 | 413 | if (self::$_canCompressOutput){ |
422 | 414 | ob_start('ob_gzhandler'); |
423 | - } |
|
424 | - else{ |
|
415 | + } else{ |
|
425 | 416 | ob_start(); |
426 | 417 | } |
427 | 418 | extract($data); |
@@ -429,8 +420,7 @@ discard block |
||
429 | 420 | $output = ob_get_clean(); |
430 | 421 | self::sendHeaders(503); |
431 | 422 | echo $output; |
432 | - } |
|
433 | - else{ |
|
423 | + } else{ |
|
434 | 424 | //can't use show_error() at this time because some dependencies not yet loaded and to prevent loop |
435 | 425 | set_http_status_header(503); |
436 | 426 | echo 'The error view [' . $path . '] does not exist'; |
@@ -104,8 +104,7 @@ discard block |
||
104 | 104 | $this->routes = $route; |
105 | 105 | unset($route); |
106 | 106 | } |
107 | - } |
|
108 | - else{ |
|
107 | + } else{ |
|
109 | 108 | show_error('Unable to find the routes configuration file [' . $routesPath . ']'); |
110 | 109 | } |
111 | 110 | |
@@ -115,8 +114,7 @@ discard block |
||
115 | 114 | if($modulesRoutes && is_array($modulesRoutes)){ |
116 | 115 | $this->routes = array_merge($this->routes, $modulesRoutes); |
117 | 116 | $this->logger->info('Routes for all modules loaded successfully'); |
118 | - } |
|
119 | - else{ |
|
117 | + } else{ |
|
120 | 118 | $this->logger->info('No routes found for all modules skipping.'); |
121 | 119 | } |
122 | 120 | $this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes)); |
@@ -132,8 +130,7 @@ discard block |
||
132 | 130 | if($suffix = get_config('url_suffix')){ |
133 | 131 | $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' ); |
134 | 132 | $uri = str_ireplace($suffix, '', $uri); |
135 | - } |
|
136 | - else{ |
|
133 | + } else{ |
|
137 | 134 | $this->logger->info('URL suffix is not enabled in the configuration'); |
138 | 135 | } |
139 | 136 | if(strpos($uri, '?') !== false){ |
@@ -226,8 +223,7 @@ discard block |
||
226 | 223 | $this->logger->info('The request URI contains the front controller'); |
227 | 224 | array_shift($segment); |
228 | 225 | $this->segments = $segment; |
229 | - } |
|
230 | - else{ |
|
226 | + } else{ |
|
231 | 227 | $this->logger->info('The request URI does not contain the front controller'); |
232 | 228 | } |
233 | 229 | $uri = implode('/', $segment); |
@@ -249,8 +245,7 @@ discard block |
||
249 | 245 | $this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']'); |
250 | 246 | $this->module = $moduleControllerMethod[0]; |
251 | 247 | $moduleControllerMethod = explode('@', $moduleControllerMethod[1]); |
252 | - } |
|
253 | - else{ |
|
248 | + } else{ |
|
254 | 249 | $this->logger->info('The current request does not use the module'); |
255 | 250 | $moduleControllerMethod = explode('@', $this->callback[$index]); |
256 | 251 | } |
@@ -297,8 +292,7 @@ discard block |
||
297 | 292 | } |
298 | 293 | //args |
299 | 294 | $this->args = $segment; |
300 | - } |
|
301 | - else{ |
|
295 | + } else{ |
|
302 | 296 | $this->logger->info('The application contains a loaded module will check if the current request is found in the module list'); |
303 | 297 | if(in_array($segment[0], $modules)){ |
304 | 298 | $this->logger->info('Found, the current request use the module [' . $segment[0] . ']'); |
@@ -312,8 +306,7 @@ discard block |
||
312 | 306 | if(! $path){ |
313 | 307 | $this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller'); |
314 | 308 | $this->controller = $this->getModule(); |
315 | - } |
|
316 | - else{ |
|
309 | + } else{ |
|
317 | 310 | $this->controllerPath = $path; |
318 | 311 | array_shift($segment); |
319 | 312 | } |
@@ -325,8 +318,7 @@ discard block |
||
325 | 318 | } |
326 | 319 | //the remaining is for args |
327 | 320 | $this->args = $segment; |
328 | - } |
|
329 | - else{ |
|
321 | + } else{ |
|
330 | 322 | $this->logger->info('The current request information is not found in the module list'); |
331 | 323 | //controller |
332 | 324 | if(isset($segment[0])){ |
@@ -354,8 +346,7 @@ discard block |
||
354 | 346 | //if it is the module controller |
355 | 347 | if($this->getModule()){ |
356 | 348 | $this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
357 | - } |
|
358 | - else{ |
|
349 | + } else{ |
|
359 | 350 | $this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php'; |
360 | 351 | } |
361 | 352 | } |
@@ -370,15 +361,13 @@ discard block |
||
370 | 361 | if(! class_exists($controller, false)){ |
371 | 362 | $e404 = true; |
372 | 363 | $this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']'); |
373 | - } |
|
374 | - else{ |
|
364 | + } else{ |
|
375 | 365 | $controllerInstance = new $controller(); |
376 | 366 | $controllerMethod = $this->getMethod(); |
377 | 367 | if(! method_exists($controllerInstance, $controllerMethod)){ |
378 | 368 | $e404 = true; |
379 | 369 | $this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']'); |
380 | - } |
|
381 | - else{ |
|
370 | + } else{ |
|
382 | 371 | $this->logger->info('Routing data is set correctly now GO!'); |
383 | 372 | call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs()); |
384 | 373 | $obj = & get_instance(); |
@@ -387,8 +376,7 @@ discard block |
||
387 | 376 | $obj->response->renderFinalPage(); |
388 | 377 | } |
389 | 378 | } |
390 | - } |
|
391 | - else{ |
|
379 | + } else{ |
|
392 | 380 | $this->logger->info('The controller file path [' . $classFilePath . '] does not exist'); |
393 | 381 | $e404 = true; |
394 | 382 | } |
@@ -22,23 +22,23 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class Router { |
28 | 28 | |
29 | 29 | /** |
30 | - * @var array $pattern: The list of URIs to validate against |
|
31 | - */ |
|
30 | + * @var array $pattern: The list of URIs to validate against |
|
31 | + */ |
|
32 | 32 | private $pattern = array(); |
33 | 33 | |
34 | 34 | /** |
35 | - * @var array $callback: The list of callback to call |
|
36 | - */ |
|
35 | + * @var array $callback: The list of callback to call |
|
36 | + */ |
|
37 | 37 | private $callback = array(); |
38 | 38 | |
39 | 39 | /** |
40 | - * @var string $uriTrim: The char to remove from the URIs |
|
41 | - */ |
|
40 | + * @var string $uriTrim: The char to remove from the URIs |
|
41 | + */ |
|
42 | 42 | protected $uriTrim = '/\^$'; |
43 | 43 | |
44 | 44 | /** |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function __construct(){ |
96 | 96 | $this->logger =& class_loader('Log', 'classes'); |
97 | - $this->logger->setLogger('Library::Router'); |
|
98 | - $routesPath = CONFIG_PATH . 'routes.php'; |
|
99 | - $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...'); |
|
97 | + $this->logger->setLogger('Library::Router'); |
|
98 | + $routesPath = CONFIG_PATH . 'routes.php'; |
|
99 | + $this->logger->debug('Loading of routes configuration file --> ' . $routesPath . ' ...'); |
|
100 | 100 | if(file_exists($routesPath)){ |
101 | 101 | $this->logger->info('Found routes configuration file --> ' . $routesPath. ' now load it'); |
102 | 102 | $route = array(); |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | - * Add the URI and callback to the list of URIs to validate |
|
149 | - * |
|
150 | - * @param string $uri the request URI |
|
151 | - * @param object $callback the callback function |
|
152 | - */ |
|
148 | + * Add the URI and callback to the list of URIs to validate |
|
149 | + * |
|
150 | + * @param string $uri the request URI |
|
151 | + * @param object $callback the callback function |
|
152 | + */ |
|
153 | 153 | public function add($uri, $callback) { |
154 | 154 | $uri = trim($uri, $this->uriTrim); |
155 | 155 | if(in_array($uri, $this->pattern)){ |
@@ -92,37 +92,37 @@ 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 | $route = array(); |
103 | 103 | require_once $routesPath; |
104 | - if(! empty($route) && is_array($route)){ |
|
104 | + if (!empty($route) && is_array($route)) { |
|
105 | 105 | $this->routes = $route; |
106 | 106 | unset($route); |
107 | 107 | } |
108 | 108 | } |
109 | - else{ |
|
109 | + else { |
|
110 | 110 | show_error('Unable to find the routes configuration file [' . $routesPath . ']'); |
111 | 111 | } |
112 | 112 | |
113 | 113 | //loading routes for module |
114 | 114 | $this->logger->debug('Loading of modules routes ... '); |
115 | 115 | $modulesRoutes = Module::getModulesRoutes(); |
116 | - if($modulesRoutes && is_array($modulesRoutes)){ |
|
116 | + if ($modulesRoutes && is_array($modulesRoutes)) { |
|
117 | 117 | $this->routes = array_merge($this->routes, $modulesRoutes); |
118 | 118 | $this->logger->info('Routes for all modules loaded successfully'); |
119 | 119 | } |
120 | - else{ |
|
120 | + else { |
|
121 | 121 | $this->logger->info('No routes found for all modules skipping.'); |
122 | 122 | } |
123 | 123 | $this->logger->info('The routes configuration are listed below: ' . stringfy_vars($this->routes)); |
124 | 124 | |
125 | - foreach($this->routes as $pattern => $callback){ |
|
125 | + foreach ($this->routes as $pattern => $callback) { |
|
126 | 126 | $this->add($pattern, $callback); |
127 | 127 | } |
128 | 128 | |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; |
131 | 131 | $this->logger->debug('Check if URL suffix is enabled in the configuration'); |
132 | 132 | //remove url suffix from the request URI |
133 | - if($suffix = get_config('url_suffix')){ |
|
134 | - $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']' ); |
|
133 | + if ($suffix = get_config('url_suffix')) { |
|
134 | + $this->logger->info('URL suffix is enabled in the configuration, the value is [' . $suffix . ']'); |
|
135 | 135 | $uri = str_ireplace($suffix, '', $uri); |
136 | 136 | } |
137 | - else{ |
|
137 | + else { |
|
138 | 138 | $this->logger->info('URL suffix is not enabled in the configuration'); |
139 | 139 | } |
140 | - if(strpos($uri, '?') !== false){ |
|
140 | + if (strpos($uri, '?') !== false) { |
|
141 | 141 | $uri = substr($uri, 0, strpos($uri, '?')); |
142 | 142 | } |
143 | 143 | $uri = trim($uri, $this->uriTrim); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function add($uri, $callback) { |
154 | 154 | $uri = trim($uri, $this->uriTrim); |
155 | - if(in_array($uri, $this->pattern)){ |
|
155 | + if (in_array($uri, $this->pattern)) { |
|
156 | 156 | $this->logger->warning('The route [' . $uri . '] already added, may be adding again can have route conflict'); |
157 | 157 | } |
158 | 158 | $this->pattern[] = $uri; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * Get the module name |
164 | 164 | * @return string |
165 | 165 | */ |
166 | - public function getModule(){ |
|
166 | + public function getModule() { |
|
167 | 167 | return $this->module; |
168 | 168 | } |
169 | 169 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * Get the controller name |
172 | 172 | * @return string |
173 | 173 | */ |
174 | - public function getController(){ |
|
174 | + public function getController() { |
|
175 | 175 | return $this->controller; |
176 | 176 | } |
177 | 177 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * Get the controller file path |
180 | 180 | * @return string |
181 | 181 | */ |
182 | - public function getControllerPath(){ |
|
182 | + public function getControllerPath() { |
|
183 | 183 | return $this->controllerPath; |
184 | 184 | } |
185 | 185 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * Get the controller method |
188 | 188 | * @return string |
189 | 189 | */ |
190 | - public function getMethod(){ |
|
190 | + public function getMethod() { |
|
191 | 191 | return $this->method; |
192 | 192 | } |
193 | 193 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * Get the request arguments |
196 | 196 | * @return array |
197 | 197 | */ |
198 | - public function getArgs(){ |
|
198 | + public function getArgs() { |
|
199 | 199 | return $this->args; |
200 | 200 | } |
201 | 201 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * Get the URL segments array |
204 | 204 | * @return array |
205 | 205 | */ |
206 | - public function getSegments(){ |
|
206 | + public function getSegments() { |
|
207 | 207 | return $this->segments; |
208 | 208 | } |
209 | 209 | |
@@ -212,27 +212,27 @@ discard block |
||
212 | 212 | * otherwise send 404 error. |
213 | 213 | */ |
214 | 214 | public function run() { |
215 | - $benchmark =& class_loader('Benchmark'); |
|
215 | + $benchmark = & class_loader('Benchmark'); |
|
216 | 216 | $benchmark->mark('ROUTING_PROCESS_START'); |
217 | 217 | $this->logger->debug('Routing process start ...'); |
218 | 218 | $segment = $this->segments; |
219 | 219 | $baseUrl = get_config('base_url'); |
220 | 220 | //check if the app is not in DOCUMENT_ROOT |
221 | - if(isset($segment[0]) && stripos($baseUrl, $segment[0]) != false){ |
|
221 | + if (isset($segment[0]) && stripos($baseUrl, $segment[0]) != false) { |
|
222 | 222 | array_shift($segment); |
223 | 223 | $this->segments = $segment; |
224 | 224 | } |
225 | 225 | $this->logger->debug('Check if the request URI contains the front controller'); |
226 | - if(isset($segment[0]) && $segment[0] == SELF){ |
|
226 | + if (isset($segment[0]) && $segment[0] == SELF) { |
|
227 | 227 | $this->logger->info('The request URI contains the front controller'); |
228 | 228 | array_shift($segment); |
229 | 229 | $this->segments = $segment; |
230 | 230 | } |
231 | - else{ |
|
231 | + else { |
|
232 | 232 | $this->logger->info('The request URI does not contain the front controller'); |
233 | 233 | } |
234 | 234 | $uri = implode('/', $segment); |
235 | - $this->logger->info('The final Request URI is [' . $uri . ']' ); |
|
235 | + $this->logger->info('The final Request URI is [' . $uri . ']'); |
|
236 | 236 | //generic routes |
237 | 237 | $pattern = array(':num', ':alpha', ':alnum', ':any'); |
238 | 238 | $replace = array('[0-9]+', '[a-zA-Z]+', '[a-zA-Z0-9]+', '.*'); |
@@ -246,20 +246,20 @@ discard block |
||
246 | 246 | array_shift($args); |
247 | 247 | //check if this contains an module |
248 | 248 | $moduleControllerMethod = explode('#', $this->callback[$index]); |
249 | - if(is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2){ |
|
250 | - $this->logger->info('The current request use the module [' .$moduleControllerMethod[0]. ']'); |
|
249 | + if (is_array($moduleControllerMethod) && count($moduleControllerMethod) >= 2) { |
|
250 | + $this->logger->info('The current request use the module [' . $moduleControllerMethod[0] . ']'); |
|
251 | 251 | $this->module = $moduleControllerMethod[0]; |
252 | 252 | $moduleControllerMethod = explode('@', $moduleControllerMethod[1]); |
253 | 253 | } |
254 | - else{ |
|
254 | + else { |
|
255 | 255 | $this->logger->info('The current request does not use the module'); |
256 | 256 | $moduleControllerMethod = explode('@', $this->callback[$index]); |
257 | 257 | } |
258 | - if(is_array($moduleControllerMethod)){ |
|
259 | - if(isset($moduleControllerMethod[0])){ |
|
258 | + if (is_array($moduleControllerMethod)) { |
|
259 | + if (isset($moduleControllerMethod[0])) { |
|
260 | 260 | $this->controller = $moduleControllerMethod[0]; |
261 | 261 | } |
262 | - if(isset($moduleControllerMethod[1])){ |
|
262 | + if (isset($moduleControllerMethod[1])) { |
|
263 | 263 | $this->method = $moduleControllerMethod[1]; |
264 | 264 | } |
265 | 265 | $this->args = $args; |
@@ -269,73 +269,73 @@ discard block |
||
269 | 269 | } |
270 | 270 | } |
271 | 271 | //first if the controller is not set and the module is set use the module name as the controller |
272 | - if(! $this->getController() && $this->getModule()){ |
|
272 | + if (!$this->getController() && $this->getModule()) { |
|
273 | 273 | $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'); |
274 | 274 | $this->controller = $this->getModule(); |
275 | 275 | } |
276 | 276 | //if can not determine the module/controller/method via the defined routes configuration we will use |
277 | 277 | //the URL like http://domain.com/module/controller/method/arg1/arg2 |
278 | - if(! $this->getController()){ |
|
278 | + if (!$this->getController()) { |
|
279 | 279 | $this->logger->info('Cannot determine the routing information using the predefined routes configuration, will use the request URI parameters'); |
280 | 280 | $nbSegment = count($segment); |
281 | 281 | //if segment is null so means no need to perform |
282 | - if($nbSegment > 0){ |
|
282 | + if ($nbSegment > 0) { |
|
283 | 283 | //get the module list |
284 | 284 | $modules = Module::getModuleList(); |
285 | 285 | //first check if no module |
286 | - if(! $modules){ |
|
286 | + if (!$modules) { |
|
287 | 287 | $this->logger->info('No module was loaded will skip the module checking'); |
288 | 288 | //the application don't use module |
289 | 289 | //controller |
290 | - if(isset($segment[0])){ |
|
290 | + if (isset($segment[0])) { |
|
291 | 291 | $this->controller = $segment[0]; |
292 | 292 | array_shift($segment); |
293 | 293 | } |
294 | 294 | //method |
295 | - if(isset($segment[0])){ |
|
295 | + if (isset($segment[0])) { |
|
296 | 296 | $this->method = $segment[0]; |
297 | 297 | array_shift($segment); |
298 | 298 | } |
299 | 299 | //args |
300 | 300 | $this->args = $segment; |
301 | 301 | } |
302 | - else{ |
|
302 | + else { |
|
303 | 303 | $this->logger->info('The application contains a loaded module will check if the current request is found in the module list'); |
304 | - if(in_array($segment[0], $modules)){ |
|
304 | + if (in_array($segment[0], $modules)) { |
|
305 | 305 | $this->logger->info('Found, the current request use the module [' . $segment[0] . ']'); |
306 | 306 | $this->module = $segment[0]; |
307 | 307 | array_shift($segment); |
308 | 308 | //check if the second arg is the controller from module |
309 | - if(isset($segment[0])){ |
|
309 | + if (isset($segment[0])) { |
|
310 | 310 | $this->controller = $segment[0]; |
311 | 311 | //check if the request use the same module name and controller |
312 | 312 | $path = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
313 | - if(! $path){ |
|
313 | + if (!$path) { |
|
314 | 314 | $this->logger->info('The controller [' . $this->getController() . '] not found in the module, may be will use the module [' . $this->getModule() . '] as controller'); |
315 | 315 | $this->controller = $this->getModule(); |
316 | 316 | } |
317 | - else{ |
|
317 | + else { |
|
318 | 318 | $this->controllerPath = $path; |
319 | 319 | array_shift($segment); |
320 | 320 | } |
321 | 321 | } |
322 | 322 | //check for method |
323 | - if(isset($segment[0])){ |
|
323 | + if (isset($segment[0])) { |
|
324 | 324 | $this->method = $segment[0]; |
325 | 325 | array_shift($segment); |
326 | 326 | } |
327 | 327 | //the remaining is for args |
328 | 328 | $this->args = $segment; |
329 | 329 | } |
330 | - else{ |
|
330 | + else { |
|
331 | 331 | $this->logger->info('The current request information is not found in the module list'); |
332 | 332 | //controller |
333 | - if(isset($segment[0])){ |
|
333 | + if (isset($segment[0])) { |
|
334 | 334 | $this->controller = $segment[0]; |
335 | 335 | array_shift($segment); |
336 | 336 | } |
337 | 337 | //method |
338 | - if(isset($segment[0])){ |
|
338 | + if (isset($segment[0])) { |
|
339 | 339 | $this->method = $segment[0]; |
340 | 340 | array_shift($segment); |
341 | 341 | } |
@@ -345,18 +345,18 @@ discard block |
||
345 | 345 | } |
346 | 346 | } |
347 | 347 | } |
348 | - if(! $this->getController() && $this->getModule()){ |
|
348 | + if (!$this->getController() && $this->getModule()) { |
|
349 | 349 | $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'); |
350 | 350 | $this->controller = $this->getModule(); |
351 | 351 | } |
352 | 352 | //did we set the controller, so set the controller path |
353 | - if($this->getController() && ! $this->getControllerPath()){ |
|
353 | + if ($this->getController() && !$this->getControllerPath()) { |
|
354 | 354 | $this->logger->debug('Setting the file path for the controller [' . $this->getController() . ']'); |
355 | 355 | //if it is the module controller |
356 | - if($this->getModule()){ |
|
356 | + if ($this->getModule()) { |
|
357 | 357 | $this->controllerPath = Module::findControllerFullPath(ucfirst($this->getController()), $this->getModule()); |
358 | 358 | } |
359 | - else{ |
|
359 | + else { |
|
360 | 360 | $this->controllerPath = APPS_CONTROLLER_PATH . ucfirst($this->getController()) . '.php'; |
361 | 361 | } |
362 | 362 | } |
@@ -366,20 +366,20 @@ discard block |
||
366 | 366 | $this->logger->debug('Loading controller [' . $controller . '], the file path is [' . $classFilePath . ']...'); |
367 | 367 | $benchmark->mark('ROUTING_PROCESS_END'); |
368 | 368 | $e404 = false; |
369 | - if(file_exists($classFilePath)){ |
|
369 | + if (file_exists($classFilePath)) { |
|
370 | 370 | require_once $classFilePath; |
371 | - if(! class_exists($controller, false)){ |
|
371 | + if (!class_exists($controller, false)) { |
|
372 | 372 | $e404 = true; |
373 | - $this->logger->info('The controller file [' .$classFilePath. '] exists but does not contain the class [' . $controller . ']'); |
|
373 | + $this->logger->info('The controller file [' . $classFilePath . '] exists but does not contain the class [' . $controller . ']'); |
|
374 | 374 | } |
375 | - else{ |
|
375 | + else { |
|
376 | 376 | $controllerInstance = new $controller(); |
377 | 377 | $controllerMethod = $this->getMethod(); |
378 | - if(! method_exists($controllerInstance, $controllerMethod)){ |
|
378 | + if (!method_exists($controllerInstance, $controllerMethod)) { |
|
379 | 379 | $e404 = true; |
380 | 380 | $this->logger->info('The controller [' . $controller . '] exist but does not contain the method [' . $controllerMethod . ']'); |
381 | 381 | } |
382 | - else{ |
|
382 | + else { |
|
383 | 383 | $this->logger->info('Routing data is set correctly now GO!'); |
384 | 384 | call_user_func_array(array($controllerInstance, $controllerMethod), $this->getArgs()); |
385 | 385 | $obj = & get_instance(); |
@@ -389,12 +389,12 @@ discard block |
||
389 | 389 | } |
390 | 390 | } |
391 | 391 | } |
392 | - else{ |
|
392 | + else { |
|
393 | 393 | $this->logger->info('The controller file path [' . $classFilePath . '] does not exist'); |
394 | 394 | $e404 = true; |
395 | 395 | } |
396 | - if($e404){ |
|
397 | - $response =& class_loader('Response', 'classes'); |
|
396 | + if ($e404) { |
|
397 | + $response = & class_loader('Response', 'classes'); |
|
398 | 398 | $response->send404(); |
399 | 399 | } |
400 | 400 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | /** |
28 | 28 | * This class represent the event detail to dispatch to correspond listener |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * This class represent the event detail to dispatch to correspond listener |
29 | 29 | */ |
30 | - class EventInfo{ |
|
30 | + class EventInfo { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public $stop; |
56 | 56 | |
57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
58 | 58 | $this->name = $name; |
59 | 59 | $this->payload = $payload; |
60 | 60 | $this->returnBack = $returnBack; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * You should have received a copy of the GNU General Public License |
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 | 26 | |
27 | 27 | class Controller{ |
28 | 28 | |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
116 | 116 | if($logger !== null){ |
117 | - $this->logger = $logger; |
|
118 | - } |
|
119 | - else{ |
|
120 | - $this->logger =& class_loader('Log', 'classes'); |
|
117 | + $this->logger = $logger; |
|
118 | + } |
|
119 | + else{ |
|
120 | + $this->logger =& class_loader('Log', 'classes'); |
|
121 | 121 | $this->logger->setLogger('MainController'); |
122 | - } |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -115,8 +115,7 @@ |
||
115 | 115 | protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
116 | 116 | if($logger !== null){ |
117 | 117 | $this->logger = $logger; |
118 | - } |
|
119 | - else{ |
|
118 | + } else{ |
|
120 | 119 | $this->logger =& class_loader('Log', 'classes'); |
121 | 120 | $this->logger->setLogger('MainController'); |
122 | 121 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Controller{ |
|
27 | + class Controller { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The name of the module if this controller belong to an module |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * Class constructor |
49 | 49 | * @param object $logger the Log instance to use if is null will create one |
50 | 50 | */ |
51 | - public function __construct(Log $logger = null){ |
|
51 | + public function __construct(Log $logger = null) { |
|
52 | 52 | //setting the Log instance |
53 | 53 | $this->setLoggerFromParamOrCreateNewInstance($logger); |
54 | 54 | |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | /** |
85 | 85 | * This method is used to set the module name |
86 | 86 | */ |
87 | - protected function setModuleNameFromRouter(){ |
|
87 | + protected function setModuleNameFromRouter() { |
|
88 | 88 | //determine the current module |
89 | - if(isset($this->router) && $this->router->getModule()){ |
|
89 | + if (isset($this->router) && $this->router->getModule()) { |
|
90 | 90 | $this->moduleName = $this->router->getModule(); |
91 | 91 | } |
92 | 92 | } |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * Set the cache using the argument otherwise will use the configuration |
96 | 96 | * @param CacheInterface $cache the implementation of CacheInterface if null will use the configured |
97 | 97 | */ |
98 | - protected function setCacheFromParamOrConfig(CacheInterface $cache = null){ |
|
98 | + protected function setCacheFromParamOrConfig(CacheInterface $cache = null) { |
|
99 | 99 | $this->logger->debug('Setting the cache handler instance'); |
100 | 100 | //set cache handler instance |
101 | - if(get_config('cache_enable', false)){ |
|
102 | - if ($cache !== null){ |
|
101 | + if (get_config('cache_enable', false)) { |
|
102 | + if ($cache !== null) { |
|
103 | 103 | $this->cache = $cache; |
104 | - } else if (isset($this->{strtolower(get_config('cache_handler'))})){ |
|
104 | + } else if (isset($this->{strtolower(get_config('cache_handler'))})) { |
|
105 | 105 | $this->cache = $this->{strtolower(get_config('cache_handler'))}; |
106 | 106 | unset($this->{strtolower(get_config('cache_handler'))}); |
107 | 107 | } |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | * Set the Log instance using argument or create new instance |
113 | 113 | * @param object $logger the Log instance if not null |
114 | 114 | */ |
115 | - protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null){ |
|
116 | - if($logger !== null){ |
|
115 | + protected function setLoggerFromParamOrCreateNewInstance(Log $logger = null) { |
|
116 | + if ($logger !== null) { |
|
117 | 117 | $this->logger = $logger; |
118 | 118 | } |
119 | - else{ |
|
120 | - $this->logger =& class_loader('Log', 'classes'); |
|
119 | + else { |
|
120 | + $this->logger = & class_loader('Log', 'classes'); |
|
121 | 121 | $this->logger->setLogger('MainController'); |
122 | 122 | } |
123 | 123 | } |
@@ -126,20 +126,20 @@ discard block |
||
126 | 126 | * This method is used to load the required resources for framework to work |
127 | 127 | * @return void |
128 | 128 | */ |
129 | - private function loadRequiredResources(){ |
|
129 | + private function loadRequiredResources() { |
|
130 | 130 | $this->logger->debug('Adding the loaded classes to the super instance'); |
131 | - foreach (class_loaded() as $var => $class){ |
|
132 | - $this->$var =& class_loader($class); |
|
131 | + foreach (class_loaded() as $var => $class) { |
|
132 | + $this->$var = & class_loader($class); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | $this->logger->debug('Loading the required classes into super instance'); |
136 | - $this->eventdispatcher =& class_loader('EventDispatcher', 'classes'); |
|
137 | - $this->loader =& class_loader('Loader', 'classes'); |
|
138 | - $this->lang =& class_loader('Lang', 'classes'); |
|
139 | - $this->request =& class_loader('Request', 'classes'); |
|
136 | + $this->eventdispatcher = & class_loader('EventDispatcher', 'classes'); |
|
137 | + $this->loader = & class_loader('Loader', 'classes'); |
|
138 | + $this->lang = & class_loader('Lang', 'classes'); |
|
139 | + $this->request = & class_loader('Request', 'classes'); |
|
140 | 140 | //dispatch the request instance created event |
141 | 141 | $this->eventdispatcher->dispatch('REQUEST_CREATED'); |
142 | - $this->response =& class_loader('Response', 'classes', 'classes'); |
|
142 | + $this->response = & class_loader('Response', 'classes', 'classes'); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | } |