@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * Function to test private & protected method |
|
5 | - */ |
|
4 | + * Function to test private & protected method |
|
5 | + */ |
|
6 | 6 | function runPrivateOrProtectedMethod($object, $method, array $args = array()){ |
7 | 7 | $r = new ReflectionClass(get_class($object)); |
8 | 8 | $m = $r->getMethod($method); |
@@ -3,7 +3,7 @@ |
||
3 | 3 | /** |
4 | 4 | * Function to test private & protected method |
5 | 5 | */ |
6 | - function runPrivateOrProtectedMethod($object, $method, array $args = array()){ |
|
6 | + function runPrivateOrProtectedMethod($object, $method, array $args = array()) { |
|
7 | 7 | $r = new ReflectionClass(get_class($object)); |
8 | 8 | $m = $r->getMethod($method); |
9 | 9 | $m->setAccessible(true); |
@@ -3,66 +3,66 @@ discard block |
||
3 | 3 | class FormValidationTest extends TestCase |
4 | 4 | { |
5 | 5 | public static function setUpBeforeClass() |
6 | - { |
|
6 | + { |
|
7 | 7 | |
8 | - } |
|
8 | + } |
|
9 | 9 | |
10 | 10 | public static function tearDownAfterClass() |
11 | - { |
|
11 | + { |
|
12 | 12 | |
13 | - } |
|
13 | + } |
|
14 | 14 | |
15 | - protected function setUp() |
|
16 | - { |
|
15 | + protected function setUp() |
|
16 | + { |
|
17 | 17 | |
18 | - } |
|
18 | + } |
|
19 | 19 | |
20 | - protected function tearDown() |
|
21 | - { |
|
20 | + protected function tearDown() |
|
21 | + { |
|
22 | 22 | |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - // tests |
|
28 | - public function testValidationDataIsEmpty() |
|
29 | - { |
|
27 | + // tests |
|
28 | + public function testValidationDataIsEmpty() |
|
29 | + { |
|
30 | 30 | $fv = new FormValidation(); |
31 | 31 | $this->assertEmpty($fv->getData()); |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | 34 | public function testValidationDataIsNotEmpty() |
35 | - { |
|
35 | + { |
|
36 | 36 | $fv = new FormValidation(); |
37 | 37 | $fv->setData(array('name' => 'mike')); |
38 | 38 | $this->assertNotEmpty($fv->getData()); |
39 | 39 | $this->assertArrayHasKey('name', $fv->getData()); |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | public function testCannotDoValidation() |
43 | - { |
|
43 | + { |
|
44 | 44 | $fv = new FormValidation(); |
45 | 45 | $this->assertFalse($fv->canDoValidation()); |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | 48 | public function testSettingErrorDelimiter() |
49 | - { |
|
49 | + { |
|
50 | 50 | $fv = new FormValidation(); |
51 | 51 | $fv->setErrorDelimiter('<a>', '</b>'); |
52 | 52 | $this->assertContains('<a>', $fv->getErrorDelimiter()); |
53 | 53 | $this->assertContains('</b>', $fv->getErrorDelimiter()); |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | 56 | public function testSettingErrorsDelimiter() |
57 | - { |
|
57 | + { |
|
58 | 58 | $fv = new FormValidation(); |
59 | 59 | $fv->setErrorsDelimiter('<foo>', '</bar>'); |
60 | 60 | $this->assertContains('<foo>', $fv->getErrorsDelimiter()); |
61 | 61 | $this->assertContains('</bar>', $fv->getErrorsDelimiter()); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | public function testSettingErrorMessageOverride() |
65 | - { |
|
65 | + { |
|
66 | 66 | |
67 | 67 | //field specific message for the rule |
68 | 68 | $fv = new FormValidation(); |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | |
83 | 83 | $this->assertFalse($fv->run()); |
84 | 84 | $this->assertContains('global required message error', $fv->returnErrors()); |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | 87 | public function testSettingCustomErrorMessage() |
88 | - { |
|
88 | + { |
|
89 | 89 | |
90 | 90 | $fv = new FormValidation(); |
91 | 91 | $fv->setData(array('foo' => '')); |
@@ -103,20 +103,20 @@ discard block |
||
103 | 103 | |
104 | 104 | $this->assertFalse($fv->run()); |
105 | 105 | $this->assertContains('custom "bar" message error', $fv->returnErrors()); |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | 108 | public function testReturnErrorsArray() |
109 | - { |
|
109 | + { |
|
110 | 110 | $fv = new FormValidation(); |
111 | 111 | $fv->setRule('name', 'name', 'required'); |
112 | 112 | $fv->setData(array('name' => '')); |
113 | 113 | $this->assertFalse($fv->run()); |
114 | 114 | $this->assertNotEmpty($fv->returnErrors()); |
115 | - } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | public function testRequiredRule() |
119 | - { |
|
119 | + { |
|
120 | 120 | $fv = new FormValidation(); |
121 | 121 | $fv->setRule('name', 'name', 'required'); |
122 | 122 | $fv->setData(array('name' => '')); |
@@ -131,5 +131,5 @@ discard block |
||
131 | 131 | $fv->setRule('name', 'name', 'required'); |
132 | 132 | $fv->setData(array('name' => 'tony')); |
133 | 133 | $this->assertTrue($fv->run()); |
134 | - } |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | \ No newline at end of file |
@@ -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,11 +175,11 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @codeCoverageIgnore |
177 | 177 | */ |
178 | - function set_http_status_header($code = 200, $text = null){ |
|
179 | - if(!is_numeric($code) || $code < 0 ){ |
|
178 | + function set_http_status_header($code = 200, $text = null) { |
|
179 | + if (!is_numeric($code) || $code < 0) { |
|
180 | 180 | show_error('HTTP status code must be an integer'); |
181 | 181 | } |
182 | - if(empty($text)){ |
|
182 | + if (empty($text)) { |
|
183 | 183 | $code = abs($code); |
184 | 184 | $http_status = array( |
185 | 185 | 100 => 'Continue', |
@@ -228,18 +228,18 @@ discard block |
||
228 | 228 | 504 => 'Gateway Timeout', |
229 | 229 | 505 => 'HTTP Version Not Supported', |
230 | 230 | ); |
231 | - if(isset($http_status[$code])){ |
|
231 | + if (isset($http_status[$code])) { |
|
232 | 232 | $text = $http_status[$code]; |
233 | 233 | } |
234 | - else{ |
|
234 | + else { |
|
235 | 235 | show_error('No HTTP status text found for your code please check it.'); |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - if(strpos(php_sapi_name(), 'cgi') === 0){ |
|
239 | + if (strpos(php_sapi_name(), 'cgi') === 0) { |
|
240 | 240 | header('Status: ' . $code . ' ' . $text, TRUE); |
241 | 241 | } |
242 | - else{ |
|
242 | + else { |
|
243 | 243 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
244 | 244 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
245 | 245 | } |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @codeCoverageIgnore |
256 | 256 | */ |
257 | - function show_error($msg, $title = 'error', $logging = true){ |
|
257 | + function show_error($msg, $title = 'error', $logging = true) { |
|
258 | 258 | $title = strtoupper($title); |
259 | 259 | $data = array(); |
260 | 260 | $data['error'] = $msg; |
261 | 261 | $data['title'] = $title; |
262 | - if($logging){ |
|
263 | - save_to_log('error', '['.$title.'] '.strip_tags($msg), 'GLOBAL::ERROR'); |
|
262 | + if ($logging) { |
|
263 | + save_to_log('error', '[' . $title . '] ' . strip_tags($msg), 'GLOBAL::ERROR'); |
|
264 | 264 | } |
265 | 265 | $response = & class_loader('Response', 'classes'); |
266 | 266 | $response->sendError($data); |
@@ -274,18 +274,18 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @return boolean true if the web server uses the https protocol, false if not. |
276 | 276 | */ |
277 | - function is_https(){ |
|
277 | + function is_https() { |
|
278 | 278 | /* |
279 | 279 | * some servers pass the "HTTPS" parameter in the server variable, |
280 | 280 | * if is the case, check if the value is "on", "true", "1". |
281 | 281 | */ |
282 | - if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
|
282 | + if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
283 | 283 | return true; |
284 | 284 | } |
285 | - else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
285 | + else if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
286 | 286 | return true; |
287 | 287 | } |
288 | - else if(isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off'){ |
|
288 | + else if (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
289 | 289 | return true; |
290 | 290 | } |
291 | 291 | return false; |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return boolean true if is a valid URL address or false. |
302 | 302 | */ |
303 | - function is_url($url){ |
|
303 | + function is_url($url) { |
|
304 | 304 | return preg_match('/^(http|https|ftp):\/\/(.*)/', $url) == 1; |
305 | 305 | } |
306 | 306 | |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | * @param string $controllerClass the controller class name to be loaded |
311 | 311 | * @codeCoverageIgnore |
312 | 312 | */ |
313 | - function autoload_controller($controllerClass){ |
|
314 | - if(file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')){ |
|
313 | + function autoload_controller($controllerClass) { |
|
314 | + if (file_exists($path = APPS_CONTROLLER_PATH . $controllerClass . '.php')) { |
|
315 | 315 | require_once $path; |
316 | 316 | } |
317 | 317 | } |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @return boolean |
327 | 327 | */ |
328 | - function php_exception_handler($ex){ |
|
329 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
330 | - show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
328 | + function php_exception_handler($ex) { |
|
329 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
330 | + show_error('An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
|
331 | 331 | } |
332 | - else{ |
|
332 | + else { |
|
333 | 333 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
334 | 334 | } |
335 | 335 | return true; |
@@ -347,16 +347,16 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @return boolean |
349 | 349 | */ |
350 | - function php_error_handler($errno , $errstr, $errfile , $errline, array $errcontext = array()){ |
|
350 | + function php_error_handler($errno, $errstr, $errfile, $errline, array $errcontext = array()) { |
|
351 | 351 | $isError = (((E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $errno) === $errno); |
352 | - if($isError){ |
|
352 | + if ($isError) { |
|
353 | 353 | set_http_status_header(500); |
354 | 354 | } |
355 | - if (! (error_reporting() & $errno)) { |
|
355 | + if (!(error_reporting() & $errno)) { |
|
356 | 356 | save_to_log('error', 'An error is occurred in the file ' . $errfile . ' at line ' . $errline . ' raison : ' . $errstr, 'PHP ERROR'); |
357 | 357 | return; |
358 | 358 | } |
359 | - if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
|
359 | + if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))) { |
|
360 | 360 | $errorType = 'error'; |
361 | 361 | switch ($errno) { |
362 | 362 | case E_USER_ERROR: |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | $errorType = 'error'; |
373 | 373 | break; |
374 | 374 | } |
375 | - show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline .'</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
375 | + show_error('An error is occurred in the file <b>' . $errfile . '</b> at line <b>' . $errline . '</b> raison : ' . $errstr, 'PHP ' . $errorType); |
|
376 | 376 | } |
377 | - if ($isError){ |
|
377 | + if ($isError) { |
|
378 | 378 | die(); |
379 | 379 | } |
380 | 380 | return true; |
@@ -384,10 +384,10 @@ discard block |
||
384 | 384 | * This function is used to run in shutdown situation of the script |
385 | 385 | * @codeCoverageIgnore |
386 | 386 | */ |
387 | - function php_shudown_handler(){ |
|
387 | + function php_shudown_handler() { |
|
388 | 388 | $lastError = error_get_last(); |
389 | 389 | if (isset($lastError) && |
390 | - ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))){ |
|
390 | + ($lastError['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING))) { |
|
391 | 391 | php_error_handler($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); |
392 | 392 | } |
393 | 393 | } |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @return string string of the HTML attribute. |
407 | 407 | */ |
408 | - function attributes_to_string(array $attributes){ |
|
408 | + function attributes_to_string(array $attributes) { |
|
409 | 409 | $str = ' '; |
410 | 410 | //we check that the array passed as an argument is not empty. |
411 | - if(! empty($attributes)){ |
|
412 | - foreach($attributes as $key => $value){ |
|
411 | + if (!empty($attributes)) { |
|
412 | + foreach ($attributes as $key => $value) { |
|
413 | 413 | $key = trim(htmlspecialchars($key)); |
414 | 414 | $value = trim(htmlspecialchars($value)); |
415 | 415 | /* |
@@ -419,10 +419,10 @@ discard block |
||
419 | 419 | * $attr = array('placeholder' => 'I am a "puple"') |
420 | 420 | * $str = attributes_to_string($attr); => placeholder = "I am a \"puple\"" |
421 | 421 | */ |
422 | - if($value && strpos('"', $value) !== false){ |
|
422 | + if ($value && strpos('"', $value) !== false) { |
|
423 | 423 | $value = addslashes($value); |
424 | 424 | } |
425 | - $str .= $key.' = "'.$value.'" '; |
|
425 | + $str .= $key . ' = "' . $value . '" '; |
|
426 | 426 | } |
427 | 427 | } |
428 | 428 | //remove the space after using rtrim() |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | * |
439 | 439 | * @return string the stringfy value |
440 | 440 | */ |
441 | - function stringfy_vars($var){ |
|
441 | + function stringfy_vars($var) { |
|
442 | 442 | return print_r($var, true); |
443 | 443 | } |
444 | 444 | |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | * |
450 | 450 | * @return mixed the sanitize value |
451 | 451 | */ |
452 | - function clean_input($str){ |
|
453 | - if(is_array($str)){ |
|
452 | + function clean_input($str) { |
|
453 | + if (is_array($str)) { |
|
454 | 454 | $str = array_map('clean_input', $str); |
455 | 455 | } |
456 | - else if(is_object($str)){ |
|
456 | + else if (is_object($str)) { |
|
457 | 457 | $obj = $str; |
458 | 458 | foreach ($str as $var => $value) { |
459 | 459 | $obj->$var = clean_input($value); |
460 | 460 | } |
461 | 461 | $str = $obj; |
462 | 462 | } |
463 | - else{ |
|
463 | + else { |
|
464 | 464 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
465 | 465 | } |
466 | 466 | return $str; |
@@ -478,11 +478,11 @@ discard block |
||
478 | 478 | * |
479 | 479 | * @return string the string with the hidden part. |
480 | 480 | */ |
481 | - function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*'){ |
|
481 | + function string_hidden($str, $startCount = 0, $endCount = 0, $hiddenChar = '*') { |
|
482 | 482 | //get the string length |
483 | 483 | $len = strlen($str); |
484 | 484 | //if str is empty |
485 | - if($len <= 0){ |
|
485 | + if ($len <= 0) { |
|
486 | 486 | return str_repeat($hiddenChar, 6); |
487 | 487 | } |
488 | 488 | //if the length is less than startCount and endCount |
@@ -490,14 +490,14 @@ discard block |
||
490 | 490 | //or startCount is negative or endCount is negative |
491 | 491 | //return the full string hidden |
492 | 492 | |
493 | - if((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)){ |
|
493 | + if ((($startCount + $endCount) > $len) || ($startCount == 0 && $endCount == 0) || ($startCount < 0 || $endCount < 0)) { |
|
494 | 494 | return str_repeat($hiddenChar, $len); |
495 | 495 | } |
496 | 496 | //the start non hidden string |
497 | 497 | $startNonHiddenStr = substr($str, 0, $startCount); |
498 | 498 | //the end non hidden string |
499 | 499 | $endNonHiddenStr = null; |
500 | - if($endCount > 0){ |
|
500 | + if ($endCount > 0) { |
|
501 | 501 | $endNonHiddenStr = substr($str, - $endCount); |
502 | 502 | } |
503 | 503 | //the hidden string |
@@ -510,31 +510,31 @@ discard block |
||
510 | 510 | * This function is used to set the initial session config regarding the configuration |
511 | 511 | * @codeCoverageIgnore |
512 | 512 | */ |
513 | - function set_session_config(){ |
|
513 | + function set_session_config() { |
|
514 | 514 | //$_SESSION is not available on cli mode |
515 | - if(! IS_CLI){ |
|
516 | - $logger =& class_loader('Log', 'classes'); |
|
515 | + if (!IS_CLI) { |
|
516 | + $logger = & class_loader('Log', 'classes'); |
|
517 | 517 | $logger->setLogger('PHPSession'); |
518 | 518 | //set session params |
519 | 519 | $sessionHandler = get_config('session_handler', 'files'); //the default is to store in the files |
520 | 520 | $sessionName = get_config('session_name'); |
521 | - if($sessionName){ |
|
521 | + if ($sessionName) { |
|
522 | 522 | session_name($sessionName); |
523 | 523 | } |
524 | 524 | $logger->info('Session handler: ' . $sessionHandler); |
525 | 525 | $logger->info('Session name: ' . $sessionName); |
526 | 526 | |
527 | - if($sessionHandler == 'files'){ |
|
527 | + if ($sessionHandler == 'files') { |
|
528 | 528 | $sessionSavePath = get_config('session_save_path'); |
529 | - if($sessionSavePath){ |
|
530 | - if(! is_dir($sessionSavePath)){ |
|
529 | + if ($sessionSavePath) { |
|
530 | + if (!is_dir($sessionSavePath)) { |
|
531 | 531 | mkdir($sessionSavePath, 1773); |
532 | 532 | } |
533 | 533 | session_save_path($sessionSavePath); |
534 | 534 | $logger->info('Session save path: ' . $sessionSavePath); |
535 | 535 | } |
536 | 536 | } |
537 | - else if($sessionHandler == 'database'){ |
|
537 | + else if ($sessionHandler == 'database') { |
|
538 | 538 | //load database session handle library |
539 | 539 | //Model |
540 | 540 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
@@ -542,11 +542,11 @@ discard block |
||
542 | 542 | //Database Session handler Model |
543 | 543 | require_once CORE_CLASSES_MODEL_PATH . 'DBSessionHandlerModel.php'; |
544 | 544 | |
545 | - $DBS =& class_loader('DBSessionHandler', 'classes'); |
|
545 | + $DBS = & class_loader('DBSessionHandler', 'classes'); |
|
546 | 546 | session_set_save_handler($DBS, true); |
547 | 547 | $logger->info('session save path: ' . get_config('session_save_path')); |
548 | 548 | } |
549 | - else{ |
|
549 | + else { |
|
550 | 550 | show_error('Invalid session handler configuration'); |
551 | 551 | } |
552 | 552 | $lifetime = get_config('session_cookie_lifetime', 0); |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | $logger->info('Session lifetime: ' . $lifetime); |
570 | 570 | $logger->info('Session cookie path: ' . $path); |
571 | 571 | $logger->info('Session domain: ' . $domain); |
572 | - $logger->info('Session is secure: ' . ($secure ? 'TRUE':'FALSE')); |
|
572 | + $logger->info('Session is secure: ' . ($secure ? 'TRUE' : 'FALSE')); |
|
573 | 573 | |
574 | - if((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()){ |
|
574 | + if ((function_exists('session_status') && session_status() !== PHP_SESSION_ACTIVE) || !session_id()) { |
|
575 | 575 | $logger->info('Session not yet start, start it now'); |
576 | 576 | session_start(); |
577 | 577 | } |
@@ -230,16 +230,14 @@ discard block |
||
230 | 230 | ); |
231 | 231 | if(isset($http_status[$code])){ |
232 | 232 | $text = $http_status[$code]; |
233 | - } |
|
234 | - else{ |
|
233 | + } else{ |
|
235 | 234 | show_error('No HTTP status text found for your code please check it.'); |
236 | 235 | } |
237 | 236 | } |
238 | 237 | |
239 | 238 | if(strpos(php_sapi_name(), 'cgi') === 0){ |
240 | 239 | header('Status: ' . $code . ' ' . $text, TRUE); |
241 | - } |
|
242 | - else{ |
|
240 | + } else{ |
|
243 | 241 | $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
244 | 242 | header($proto . ' ' . $code . ' ' . $text, TRUE, $code); |
245 | 243 | } |
@@ -281,11 +279,9 @@ discard block |
||
281 | 279 | */ |
282 | 280 | if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'){ |
283 | 281 | return true; |
284 | - } |
|
285 | - else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
282 | + } else if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'){ |
|
286 | 283 | return true; |
287 | - } |
|
288 | - 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'){ |
|
289 | 285 | return true; |
290 | 286 | } |
291 | 287 | return false; |
@@ -328,8 +324,7 @@ discard block |
||
328 | 324 | function php_exception_handler($ex){ |
329 | 325 | if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors'))){ |
330 | 326 | show_error('An exception is occured in file '. $ex->getFile() .' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception #' . $ex->getCode()); |
331 | - } |
|
332 | - else{ |
|
327 | + } else{ |
|
333 | 328 | save_to_log('error', 'An exception is occured in file ' . $ex->getFile() . ' at line ' . $ex->getLine() . ' raison : ' . $ex->getMessage(), 'PHP Exception'); |
334 | 329 | } |
335 | 330 | return true; |
@@ -452,15 +447,13 @@ discard block |
||
452 | 447 | function clean_input($str){ |
453 | 448 | if(is_array($str)){ |
454 | 449 | $str = array_map('clean_input', $str); |
455 | - } |
|
456 | - else if(is_object($str)){ |
|
450 | + } else if(is_object($str)){ |
|
457 | 451 | $obj = $str; |
458 | 452 | foreach ($str as $var => $value) { |
459 | 453 | $obj->$var = clean_input($value); |
460 | 454 | } |
461 | 455 | $str = $obj; |
462 | - } |
|
463 | - else{ |
|
456 | + } else{ |
|
464 | 457 | $str = htmlspecialchars(strip_tags($str), ENT_QUOTES, 'UTF-8'); |
465 | 458 | } |
466 | 459 | return $str; |
@@ -533,8 +526,7 @@ discard block |
||
533 | 526 | session_save_path($sessionSavePath); |
534 | 527 | $logger->info('Session save path: ' . $sessionSavePath); |
535 | 528 | } |
536 | - } |
|
537 | - else if($sessionHandler == 'database'){ |
|
529 | + } else if($sessionHandler == 'database'){ |
|
538 | 530 | //load database session handle library |
539 | 531 | //Model |
540 | 532 | require_once CORE_CLASSES_MODEL_PATH . 'Model.php'; |
@@ -545,8 +537,7 @@ discard block |
||
545 | 537 | $DBS =& class_loader('DBSessionHandler', 'classes'); |
546 | 538 | session_set_save_handler($DBS, true); |
547 | 539 | $logger->info('session save path: ' . get_config('session_save_path')); |
548 | - } |
|
549 | - else{ |
|
540 | + } else{ |
|
550 | 541 | show_error('Invalid session handler configuration'); |
551 | 542 | } |
552 | 543 | $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', false); |
156 | 156 | $this->setSessionSecret($secret); |
157 | 157 | } |
158 | 158 | $this->logger->info('Session secret: ' . $secret); |
159 | 159 | |
160 | - if(! $this->getModelInstance()){ |
|
160 | + if (!$this->getModelInstance()) { |
|
161 | 161 | $this->setModelInstanceFromConfig(); |
162 | 162 | } |
163 | 163 | $this->setInitializerVector($secret); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | //set session tables columns |
166 | 166 | $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns(); |
167 | 167 | |
168 | - if(empty($this->sessionTableColumns)){ |
|
168 | + if (empty($this->sessionTableColumns)) { |
|
169 | 169 | show_error('The session handler is "database" but the table columns not set'); |
170 | 170 | } |
171 | 171 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * Close the session |
182 | 182 | * @return boolean |
183 | 183 | */ |
184 | - public function close(){ |
|
184 | + public function close() { |
|
185 | 185 | $this->logger->debug('Closing database session handler'); |
186 | 186 | return true; |
187 | 187 | } |
@@ -191,28 +191,28 @@ discard block |
||
191 | 191 | * @param string $sid the session id to use |
192 | 192 | * @return string the session data in serialiaze format |
193 | 193 | */ |
194 | - public function read($sid){ |
|
194 | + public function read($sid) { |
|
195 | 195 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
196 | 196 | $instance = $this->getModelInstance(); |
197 | 197 | $columns = $this->sessionTableColumns; |
198 | - if($this->getLoader()){ |
|
198 | + if ($this->getLoader()) { |
|
199 | 199 | $this->getLoader()->functions('user_agent'); |
200 | 200 | $this->getLoader()->library('Browser'); |
201 | 201 | } |
202 | - else{ |
|
202 | + else { |
|
203 | 203 | Loader::functions('user_agent'); |
204 | 204 | Loader::library('Browser'); |
205 | 205 | } |
206 | 206 | |
207 | 207 | $ip = get_ip(); |
208 | 208 | $host = @gethostbyaddr($ip) or null; |
209 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
209 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
210 | 210 | |
211 | 211 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
212 | - if($data && isset($data->{$columns['sdata']})){ |
|
212 | + if ($data && isset($data->{$columns['sdata']})) { |
|
213 | 213 | //checking inactivity |
214 | 214 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
215 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
215 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
216 | 216 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
217 | 217 | $this->destroy($sid); |
218 | 218 | return null; |
@@ -229,16 +229,16 @@ discard block |
||
229 | 229 | * @param mixed $data the session data to save in serialize format |
230 | 230 | * @return boolean |
231 | 231 | */ |
232 | - public function write($sid, $data){ |
|
232 | + public function write($sid, $data) { |
|
233 | 233 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
234 | 234 | $instance = $this->getModelInstance(); |
235 | 235 | $columns = $this->sessionTableColumns; |
236 | 236 | |
237 | - if($this->getLoader()){ |
|
237 | + if ($this->getLoader()) { |
|
238 | 238 | $this->getLoader()->functions('user_agent'); |
239 | 239 | $this->getLoader()->library('Browser'); |
240 | 240 | } |
241 | - else{ |
|
241 | + else { |
|
242 | 242 | Loader::functions('user_agent'); |
243 | 243 | Loader::library('Browser'); |
244 | 244 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | $ip = get_ip(); |
247 | 247 | $keyValue = $instance->getKeyValue(); |
248 | 248 | $host = @gethostbyaddr($ip) or null; |
249 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
249 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
250 | 250 | $data = $this->encode($data); |
251 | 251 | $params = array( |
252 | 252 | $columns['sid'] => $sid, |
@@ -259,13 +259,13 @@ discard block |
||
259 | 259 | ); |
260 | 260 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
261 | 261 | $exists = $instance->get($sid); |
262 | - if($exists){ |
|
262 | + if ($exists) { |
|
263 | 263 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
264 | 264 | //update |
265 | 265 | unset($params[$columns['sid']]); |
266 | 266 | $instance->update($sid, $params); |
267 | 267 | } |
268 | - else{ |
|
268 | + else { |
|
269 | 269 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
270 | 270 | $instance->insert($params); |
271 | 271 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param string $sid the session id value |
279 | 279 | * @return boolean |
280 | 280 | */ |
281 | - public function destroy($sid){ |
|
281 | + public function destroy($sid) { |
|
282 | 282 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
283 | 283 | $instance = $this->modelInstanceName; |
284 | 284 | $instance->delete($sid); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param integer $maxLifetime the max lifetime |
291 | 291 | * @return boolean |
292 | 292 | */ |
293 | - public function gc($maxLifetime){ |
|
293 | + public function gc($maxLifetime) { |
|
294 | 294 | $instance = $this->modelInstanceName; |
295 | 295 | $time = time() - $maxLifetime; |
296 | 296 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * @param mixed $data the session data to encode |
304 | 304 | * @return mixed the encoded session data |
305 | 305 | */ |
306 | - public function encode($data){ |
|
306 | + public function encode($data) { |
|
307 | 307 | $key = base64_decode($this->sessionSecret); |
308 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
308 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
309 | 309 | $output = base64_encode($dataEncrypted); |
310 | 310 | return $output; |
311 | 311 | } |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param mixed $data the data to decode |
317 | 317 | * @return mixed the decoded data |
318 | 318 | */ |
319 | - public function decode($data){ |
|
319 | + public function decode($data) { |
|
320 | 320 | $key = base64_decode($this->sessionSecret); |
321 | 321 | $data = base64_decode($data); |
322 | 322 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * Return the loader instance |
329 | 329 | * @return object Loader the loader instance |
330 | 330 | */ |
331 | - public function getLoader(){ |
|
331 | + public function getLoader() { |
|
332 | 332 | return $this->loader; |
333 | 333 | } |
334 | 334 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * set the loader instance for future use |
337 | 337 | * @param object Loader $loader the loader object |
338 | 338 | */ |
339 | - public function setLoader($loader){ |
|
339 | + public function setLoader($loader) { |
|
340 | 340 | $this->loader = $loader; |
341 | 341 | return $this; |
342 | 342 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * Return the model instance |
346 | 346 | * @return object DBSessionHandlerModel the model instance |
347 | 347 | */ |
348 | - public function getModelInstance(){ |
|
348 | + public function getModelInstance() { |
|
349 | 349 | return $this->modelInstanceName; |
350 | 350 | } |
351 | 351 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * set the model instance for future use |
354 | 354 | * @param DBSessionHandlerModel $modelInstance the model object |
355 | 355 | */ |
356 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
356 | + public function setModelInstance(DBSessionHandlerModel $modelInstance) { |
|
357 | 357 | $this->modelInstanceName = $modelInstance; |
358 | 358 | return $this; |
359 | 359 | } |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * Return the Log instance |
363 | 363 | * @return Log |
364 | 364 | */ |
365 | - public function getLogger(){ |
|
365 | + public function getLogger() { |
|
366 | 366 | return $this->logger; |
367 | 367 | } |
368 | 368 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | * Set the log instance |
371 | 371 | * @param Log $logger the log object |
372 | 372 | */ |
373 | - public function setLogger(Log $logger){ |
|
373 | + public function setLogger(Log $logger) { |
|
374 | 374 | $this->logger = $logger; |
375 | 375 | return $this; |
376 | 376 | } |
@@ -378,18 +378,18 @@ discard block |
||
378 | 378 | /** |
379 | 379 | * Set the model instance using the configuration for session |
380 | 380 | */ |
381 | - private function setModelInstanceFromConfig(){ |
|
381 | + private function setModelInstanceFromConfig() { |
|
382 | 382 | $modelName = get_config('session_save_path'); |
383 | 383 | $this->logger->info('The database session model: ' . $modelName); |
384 | - if($this->getLoader()){ |
|
384 | + if ($this->getLoader()) { |
|
385 | 385 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
386 | 386 | } |
387 | 387 | //@codeCoverageIgnoreStart |
388 | - else{ |
|
388 | + else { |
|
389 | 389 | Loader::model($modelName, 'dbsessionhandlerinstance'); |
390 | 390 | } |
391 | - if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
392 | - show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"'); |
|
391 | + if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) { |
|
392 | + show_error('To use database session handler, your class model "' . get_class($this->OBJ->dbsessionhandlerinstance) . '" need extends "DBSessionHandlerModel"'); |
|
393 | 393 | } |
394 | 394 | //@codeCoverageIgnoreEnd |
395 | 395 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - class DBSessionModel extends DBSessionHandlerModel{ |
|
2 | + class DBSessionModel extends DBSessionHandlerModel { |
|
3 | 3 | |
4 | 4 | protected $_table = 'ses'; |
5 | 5 | protected $primary_key = 's_id'; |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | 'skey' => 'test_id' //VARCHAR(255) |
15 | 15 | ); |
16 | 16 | |
17 | - public function deleteByTime($time){ |
|
17 | + public function deleteByTime($time) { |
|
18 | 18 | $this->_database->from($this->_table) |
19 | 19 | ->where('s_time', '<', $time) |
20 | 20 | ->delete(); |
21 | 21 | } |
22 | 22 | |
23 | 23 | |
24 | - public function getKeyValue(){ |
|
24 | + public function getKeyValue() { |
|
25 | 25 | $user_id = 0; |
26 | 26 | return $user_id; |
27 | 27 | } |
@@ -21,21 +21,21 @@ discard block |
||
21 | 21 | * You should have received a copy of the GNU General Public License |
22 | 22 | * along with this program; if not, write to the Free Software |
23 | 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
24 | - */ |
|
24 | + */ |
|
25 | 25 | |
26 | 26 | error_reporting(E_ALL | E_STRICT); |
27 | 27 | ini_set('display_errors', 1); |
28 | 28 | |
29 | 29 | /** |
30 | - * the directory separator, under windows it is \ and unix, linux / |
|
31 | - */ |
|
30 | + * the directory separator, under windows it is \ and unix, linux / |
|
31 | + */ |
|
32 | 32 | define('DS', DIRECTORY_SEPARATOR); |
33 | 33 | |
34 | 34 | /** |
35 | - * The root directory of the application. |
|
36 | - * |
|
37 | - * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
38 | - */ |
|
35 | + * The root directory of the application. |
|
36 | + * |
|
37 | + * you can place this directory outside of your web directory, for example "/home/your_app", etc. |
|
38 | + */ |
|
39 | 39 | define('ROOT_PATH', dirname(realpath(__FILE__)) . DS . '..' . DS); |
40 | 40 | |
41 | 41 | //tests dir path |
@@ -43,176 +43,176 @@ discard block |
||
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
46 | - * The path to the directory. |
|
47 | - * |
|
48 | - * That contains your static files (javascript, css, images, etc.) |
|
49 | - * Note: the path must be relative to the file index.php (the front-end controller). |
|
50 | - */ |
|
46 | + * The path to the directory. |
|
47 | + * |
|
48 | + * That contains your static files (javascript, css, images, etc.) |
|
49 | + * Note: the path must be relative to the file index.php (the front-end controller). |
|
50 | + */ |
|
51 | 51 | define('ASSETS_PATH', 'assets/'); |
52 | 52 | |
53 | 53 | /** |
54 | - * The path to the directory of your cache files. |
|
55 | - * |
|
56 | - * This feature is available currently for database and views. |
|
57 | - */ |
|
54 | + * The path to the directory of your cache files. |
|
55 | + * |
|
56 | + * This feature is available currently for database and views. |
|
57 | + */ |
|
58 | 58 | define('CACHE_PATH', ROOT_PATH . 'cache' . DS); |
59 | 59 | |
60 | 60 | /** |
61 | - * Custom application path for tests |
|
62 | - */ |
|
61 | + * Custom application path for tests |
|
62 | + */ |
|
63 | 63 | define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
64 | 64 | |
65 | 65 | /** |
66 | - * The path to the controller directory of your application. |
|
67 | - * |
|
68 | - * If you already know the MVC architecture you know what a controller means; |
|
69 | - * it is he who makes the business logic of your application in general. |
|
70 | - */ |
|
66 | + * The path to the controller directory of your application. |
|
67 | + * |
|
68 | + * If you already know the MVC architecture you know what a controller means; |
|
69 | + * it is he who makes the business logic of your application in general. |
|
70 | + */ |
|
71 | 71 | define('APPS_CONTROLLER_PATH', APPS_PATH . 'controllers' . DS); |
72 | 72 | |
73 | 73 | /** |
74 | - * The path to the directory of your model classes of your application. |
|
75 | - * |
|
76 | - * If you already know the MVC architecture you know what a model means; |
|
77 | - * it's the one who interacts with the database, in one word persistent data from your application. |
|
78 | - */ |
|
74 | + * The path to the directory of your model classes of your application. |
|
75 | + * |
|
76 | + * If you already know the MVC architecture you know what a model means; |
|
77 | + * it's the one who interacts with the database, in one word persistent data from your application. |
|
78 | + */ |
|
79 | 79 | define('APPS_MODEL_PATH', APPS_PATH . 'models' . DS); |
80 | 80 | |
81 | 81 | /** |
82 | - * The path to the directory of your views. |
|
83 | - * |
|
84 | - * If you already know the MVC architecture you know what a view means, |
|
85 | - * a view is just a user interface (html page, form, etc.) that is to say |
|
86 | - * everything displayed in the browser interface, etc. |
|
87 | - */ |
|
82 | + * The path to the directory of your views. |
|
83 | + * |
|
84 | + * If you already know the MVC architecture you know what a view means, |
|
85 | + * a view is just a user interface (html page, form, etc.) that is to say |
|
86 | + * everything displayed in the browser interface, etc. |
|
87 | + */ |
|
88 | 88 | define('APPS_VIEWS_PATH', APPS_PATH . 'views' . DS); |
89 | 89 | |
90 | 90 | /** |
91 | - * The path to the configuration directory. |
|
92 | - * |
|
93 | - * That contains most of the configuration files for your |
|
94 | - * application (database, class loading file, functions, etc.) |
|
95 | - */ |
|
91 | + * The path to the configuration directory. |
|
92 | + * |
|
93 | + * That contains most of the configuration files for your |
|
94 | + * application (database, class loading file, functions, etc.) |
|
95 | + */ |
|
96 | 96 | define('CONFIG_PATH', ROOT_PATH . 'config' . DS); |
97 | 97 | |
98 | 98 | /** |
99 | - * The core directory |
|
100 | - * |
|
101 | - * It is recommended to put this folder out of the web directory of your server and |
|
102 | - * you should not change its content because in case of update you could lose the modified files. |
|
103 | - */ |
|
99 | + * The core directory |
|
100 | + * |
|
101 | + * It is recommended to put this folder out of the web directory of your server and |
|
102 | + * you should not change its content because in case of update you could lose the modified files. |
|
103 | + */ |
|
104 | 104 | define('CORE_PATH', ROOT_PATH . 'core' . DS); |
105 | 105 | |
106 | 106 | /** |
107 | - * The path to the directory of core classes that used by the system. |
|
108 | - * |
|
109 | - * It contains PHP classes that are used by the framework internally. |
|
110 | - */ |
|
107 | + * The path to the directory of core classes that used by the system. |
|
108 | + * |
|
109 | + * It contains PHP classes that are used by the framework internally. |
|
110 | + */ |
|
111 | 111 | define('CORE_CLASSES_PATH', CORE_PATH . 'classes' . DS); |
112 | 112 | |
113 | 113 | /** |
114 | - * The path to the directory of core classes for the cache used by the system. |
|
115 | - * |
|
116 | - * It contains PHP classes for the cache drivers. |
|
117 | - */ |
|
114 | + * The path to the directory of core classes for the cache used by the system. |
|
115 | + * |
|
116 | + * It contains PHP classes for the cache drivers. |
|
117 | + */ |
|
118 | 118 | define('CORE_CLASSES_CACHE_PATH', CORE_CLASSES_PATH . 'cache' . DS); |
119 | 119 | |
120 | 120 | /** |
121 | - * The path to the directory of core classes for the model used by the system. |
|
122 | - * |
|
123 | - * It contains PHP classes for the models. |
|
124 | - */ |
|
121 | + * The path to the directory of core classes for the model used by the system. |
|
122 | + * |
|
123 | + * It contains PHP classes for the models. |
|
124 | + */ |
|
125 | 125 | define('CORE_CLASSES_MODEL_PATH', CORE_CLASSES_PATH . 'model' . DS); |
126 | 126 | |
127 | 127 | /** |
128 | - * The path to the directory of functions or helper systems. |
|
129 | - * |
|
130 | - * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
131 | - */ |
|
128 | + * The path to the directory of functions or helper systems. |
|
129 | + * |
|
130 | + * It contains PHP functions that perform a particular task: character string processing, URL, etc. |
|
131 | + */ |
|
132 | 132 | define('CORE_FUNCTIONS_PATH', CORE_PATH . 'functions' . DS); |
133 | 133 | |
134 | 134 | /** |
135 | - * The path to the core directory of languages files. |
|
136 | - * |
|
137 | - */ |
|
135 | + * The path to the core directory of languages files. |
|
136 | + * |
|
137 | + */ |
|
138 | 138 | define('CORE_LANG_PATH', CORE_PATH . 'lang' . DS); |
139 | 139 | |
140 | 140 | /** |
141 | - * The path to the system library directory. |
|
142 | - * |
|
143 | - * Which contains the libraries most often used in your web application, as for the |
|
144 | - * core directory it is advisable to put it out of the root directory of your application. |
|
145 | - */ |
|
141 | + * The path to the system library directory. |
|
142 | + * |
|
143 | + * Which contains the libraries most often used in your web application, as for the |
|
144 | + * core directory it is advisable to put it out of the root directory of your application. |
|
145 | + */ |
|
146 | 146 | define('CORE_LIBRARY_PATH', CORE_PATH . 'libraries' . DS); |
147 | 147 | |
148 | 148 | /** |
149 | - * The path to the system view directory. |
|
150 | - * |
|
151 | - * That contains the views used for the system, such as error messages, and so on. |
|
152 | - */ |
|
149 | + * The path to the system view directory. |
|
150 | + * |
|
151 | + * That contains the views used for the system, such as error messages, and so on. |
|
152 | + */ |
|
153 | 153 | define('CORE_VIEWS_PATH', CORE_PATH . 'views' . DS); |
154 | 154 | |
155 | 155 | /** |
156 | - * The path to the directory of your PHP personal functions or helper. |
|
157 | - * |
|
158 | - * It contains your PHP functions that perform a particular task: utilities, etc. |
|
159 | - * Note: Do not put your personal functions or helpers in the system functions directory, |
|
160 | - * because if you update the system you may lose them. |
|
161 | - */ |
|
156 | + * The path to the directory of your PHP personal functions or helper. |
|
157 | + * |
|
158 | + * It contains your PHP functions that perform a particular task: utilities, etc. |
|
159 | + * Note: Do not put your personal functions or helpers in the system functions directory, |
|
160 | + * because if you update the system you may lose them. |
|
161 | + */ |
|
162 | 162 | define('FUNCTIONS_PATH', ROOT_PATH . 'functions' . DS); |
163 | 163 | |
164 | 164 | /** |
165 | - * The path to the app directory of personal language. |
|
166 | - * |
|
167 | - * This feature is not yet available. |
|
168 | - * You can help us do this if you are nice or wish to see the developed framework. |
|
169 | - */ |
|
165 | + * The path to the app directory of personal language. |
|
166 | + * |
|
167 | + * This feature is not yet available. |
|
168 | + * You can help us do this if you are nice or wish to see the developed framework. |
|
169 | + */ |
|
170 | 170 | define('APP_LANG_PATH', ROOT_PATH . 'lang' . DS); |
171 | 171 | |
172 | 172 | /** |
173 | - * The path to the directory of your personal libraries |
|
174 | - * |
|
175 | - * It contains your PHP classes, package, etc. |
|
176 | - * Note: you should not put your personal libraries in the system library directory, |
|
177 | - * because it is recalled in case of updating the system you might have surprises. |
|
178 | - */ |
|
173 | + * The path to the directory of your personal libraries |
|
174 | + * |
|
175 | + * It contains your PHP classes, package, etc. |
|
176 | + * Note: you should not put your personal libraries in the system library directory, |
|
177 | + * because it is recalled in case of updating the system you might have surprises. |
|
178 | + */ |
|
179 | 179 | define('LIBRARY_PATH', ROOT_PATH . 'libraries' . DS); |
180 | 180 | |
181 | 181 | /** |
182 | - * The path to the directory that contains the log files. |
|
183 | - * |
|
184 | - * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
185 | - * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
186 | - * details see the documentation of your web server. |
|
187 | - * Example for Unix or linux with apache web server: |
|
188 | - * # chmod -R 700 /path/to/your/logs/directory/ |
|
189 | - * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
190 | - */ |
|
182 | + * The path to the directory that contains the log files. |
|
183 | + * |
|
184 | + * Note: This directory must be available in writing and if possible must have as owner the user who launches your web server, |
|
185 | + * under unix or linux most often with the apache web server it is "www-data" or "httpd" even "nobody" for more |
|
186 | + * details see the documentation of your web server. |
|
187 | + * Example for Unix or linux with apache web server: |
|
188 | + * # chmod -R 700 /path/to/your/logs/directory/ |
|
189 | + * # chown -R www-data:www-data /path/to/your/logs/directory/ |
|
190 | + */ |
|
191 | 191 | define('LOGS_PATH', ROOT_PATH . 'logs' . DS); |
192 | 192 | |
193 | 193 | /** |
194 | - * The path to the modules directory. |
|
195 | - * |
|
196 | - * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
197 | - * in HMVC architecture (hierichical, controllers, models, views). |
|
198 | - */ |
|
194 | + * The path to the modules directory. |
|
195 | + * |
|
196 | + * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
|
197 | + * in HMVC architecture (hierichical, controllers, models, views). |
|
198 | + */ |
|
199 | 199 | define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
200 | 200 | |
201 | 201 | /** |
202 | - * The path to the directory of sources external to your application. |
|
203 | - * |
|
204 | - * If you have already used "composer" you know what that means. |
|
205 | - */ |
|
202 | + * The path to the directory of sources external to your application. |
|
203 | + * |
|
204 | + * If you have already used "composer" you know what that means. |
|
205 | + */ |
|
206 | 206 | define('VENDOR_PATH', ROOT_PATH . 'vendor' . DS); |
207 | 207 | |
208 | 208 | /** |
209 | - * The front controller of your application. |
|
210 | - * |
|
211 | - * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
212 | - * your application by using the rewrite module URL of your web server . |
|
213 | - * For example, under apache web server, there is a configuration example file that is located at the root |
|
214 | - * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
215 | - */ |
|
209 | + * The front controller of your application. |
|
210 | + * |
|
211 | + * "index.php" it is through this file that all the requests come, there is a possibility to hidden it in the url of |
|
212 | + * your application by using the rewrite module URL of your web server . |
|
213 | + * For example, under apache web server, there is a configuration example file that is located at the root |
|
214 | + * of your framework folder : "htaccess.txt" rename it to ".htaccess". |
|
215 | + */ |
|
216 | 216 | define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); |
217 | 217 | |
218 | 218 | /** |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | define('IS_CLI', stripos('cli', php_sapi_name()) !== false); |
222 | 222 | |
223 | 223 | /** |
224 | - * The environment of your application (production, test, development). |
|
225 | - * |
|
226 | - * if your application is still in development you use the value "development" |
|
227 | - * so you will have the display of the error messages, etc. |
|
228 | - * Once you finish the development of your application that is to put it online |
|
229 | - * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
230 | - * the loading of the system, will be fast. |
|
231 | - */ |
|
224 | + * The environment of your application (production, test, development). |
|
225 | + * |
|
226 | + * if your application is still in development you use the value "development" |
|
227 | + * so you will have the display of the error messages, etc. |
|
228 | + * Once you finish the development of your application that is to put it online |
|
229 | + * you change this value to "production" or "testing", in this case there will be deactivation of error messages, |
|
230 | + * the loading of the system, will be fast. |
|
231 | + */ |
|
232 | 232 | define('ENVIRONMENT', 'testing'); |
233 | 233 | |
234 | 234 | |
@@ -259,13 +259,13 @@ discard block |
||
259 | 259 | require_once 'include/testsUtil.php'; |
260 | 260 | |
261 | 261 | /** |
262 | - * Setting of the PHP error message handling function |
|
263 | - */ |
|
262 | + * Setting of the PHP error message handling function |
|
263 | + */ |
|
264 | 264 | set_error_handler('php_error_handler'); |
265 | 265 | |
266 | 266 | /** |
267 | - * Setting of the PHP error exception handling function |
|
268 | - */ |
|
267 | + * Setting of the PHP error exception handling function |
|
268 | + */ |
|
269 | 269 | set_exception_handler('php_exception_handler'); |
270 | 270 | |
271 | 271 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * Custom application path for tests |
62 | 62 | */ |
63 | - define('APPS_PATH', TESTS_PATH .'hmvc' . DS); |
|
63 | + define('APPS_PATH', TESTS_PATH . 'hmvc' . DS); |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * The path to the controller directory of your application. |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * It contains your modules used files (config, controllers, libraries, etc.) that is to say which contains your files of the modules, |
197 | 197 | * in HMVC architecture (hierichical, controllers, models, views). |
198 | 198 | */ |
199 | - define('MODULE_PATH', dirname(realpath(__FILE__)) . DS .'hmvc' . DS . 'modules' . DS); |
|
199 | + define('MODULE_PATH', dirname(realpath(__FILE__)) . DS . 'hmvc' . DS . 'modules' . DS); |
|
200 | 200 | |
201 | 201 | /** |
202 | 202 | * The path to the directory of sources external to your application. |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | //Fix to allow test as if application is running in CLI mode $_SESSION global variable is not available |
236 | 236 | $_SESSION = array(); |
237 | 237 | |
238 | - if(! isset($_SERVER['REMOTE_ADDR'])){ |
|
238 | + if (!isset($_SERVER['REMOTE_ADDR'])) { |
|
239 | 239 | $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; |
240 | 240 | } |
241 | 241 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | require_once 'include/autoloader.php'; |
244 | 244 | |
245 | 245 | //check for composer autoload file if exists include it |
246 | - if(file_exists(VENDOR_PATH . 'autoload.php')){ |
|
246 | + if (file_exists(VENDOR_PATH . 'autoload.php')) { |
|
247 | 247 | require_once VENDOR_PATH . 'autoload.php'; |
248 | 248 | |
249 | 249 | //define the class alias for vstream |
@@ -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 | } |
@@ -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 self |
|
269 | - */ |
|
270 | - public function setCompressCacheData($status = true){ |
|
265 | + /** |
|
266 | + * @param boolean $compressCacheData |
|
267 | + * |
|
268 | + * @return self |
|
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 Log |
|
295 | - */ |
|
296 | - public function getLogger(){ |
|
297 | - return $this->logger; |
|
298 | - } |
|
293 | + * Return the Log instance |
|
294 | + * @return Log |
|
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 the full cache file path for this key |
|
314 | - */ |
|
310 | + * Get the cache file full path for the given key |
|
311 | + * |
|
312 | + * @param $key the cache item key |
|
313 | + * @return string the full cache file path for this key |
|
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 self |
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 Log |
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 the full cache file path for this key |
314 | 314 | */ |
315 | - private function getFilePath($key){ |
|
315 | + private function getFilePath($key) { |
|
316 | 316 | return CACHE_PATH . md5($key) . '.cache'; |
317 | 317 | } |
318 | 318 | } |
@@ -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; |