@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Config{ |
|
27 | + class Config { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of loaded configuration |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * The signleton of the logger |
43 | 43 | * @return Object the Log instance |
44 | 44 | */ |
45 | - private static function getLogger(){ |
|
46 | - if(self::$logger == null){ |
|
45 | + private static function getLogger() { |
|
46 | + if (self::$logger == null) { |
|
47 | 47 | $logger = array(); |
48 | - $logger[0] =& class_loader('Log', 'classes'); |
|
48 | + $logger[0] = & class_loader('Log', 'classes'); |
|
49 | 49 | $logger[0]->setLogger('Library::Config'); |
50 | 50 | self::$logger = $logger[0]; |
51 | 51 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param Log $logger the log object |
58 | 58 | * @return Log the log instance |
59 | 59 | */ |
60 | - public static function setLogger($logger){ |
|
60 | + public static function setLogger($logger) { |
|
61 | 61 | self::$logger = $logger; |
62 | 62 | return self::$logger; |
63 | 63 | } |
@@ -65,35 +65,35 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Initialize the configuration by loading all the configuration from config file |
67 | 67 | */ |
68 | - public static function init(){ |
|
68 | + public static function init() { |
|
69 | 69 | $logger = static::getLogger(); |
70 | 70 | $logger->debug('Initialization of the configuration'); |
71 | 71 | self::$config = & load_configurations(); |
72 | - if(! self::$config['base_url'] || ! is_url(self::$config['base_url'])){ |
|
73 | - if(ENVIRONMENT == 'production'){ |
|
72 | + if (!self::$config['base_url'] || !is_url(self::$config['base_url'])) { |
|
73 | + if (ENVIRONMENT == 'production') { |
|
74 | 74 | $logger->warning('Application base URL is not set or invalid, please set application base URL to increase the application loading time'); |
75 | 75 | } |
76 | 76 | $baseUrl = null; |
77 | - if (isset($_SERVER['SERVER_ADDR'])){ |
|
77 | + if (isset($_SERVER['SERVER_ADDR'])) { |
|
78 | 78 | //check if the server is running under IPv6 |
79 | - if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
|
80 | - $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
|
79 | + if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE) { |
|
80 | + $baseUrl = '[' . $_SERVER['SERVER_ADDR'] . ']'; |
|
81 | 81 | } |
82 | - else{ |
|
82 | + else { |
|
83 | 83 | $baseUrl = $_SERVER['SERVER_ADDR']; |
84 | 84 | } |
85 | - $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
86 | - $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
|
85 | + $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && !is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https())) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
|
86 | + $baseUrl = (is_https() ? 'https' : 'http') . '://' . $baseUrl . $port |
|
87 | 87 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
88 | 88 | } |
89 | - else{ |
|
89 | + else { |
|
90 | 90 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
91 | 91 | $baseUrl = 'http://localhost/'; |
92 | 92 | } |
93 | 93 | self::set('base_url', $baseUrl); |
94 | 94 | } |
95 | - self::$config['base_url'] = rtrim(self::$config['base_url'], '/') .'/'; |
|
96 | - if(ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info','all'))){ |
|
95 | + self::$config['base_url'] = rtrim(self::$config['base_url'], '/') . '/'; |
|
96 | + if (ENVIRONMENT == 'production' && in_array(strtolower(self::$config['log_level']), array('debug', 'info', 'all'))) { |
|
97 | 97 | $logger->warning('You are in production environment, please set log level to WARNING, ERROR, FATAL to increase the application performance'); |
98 | 98 | } |
99 | 99 | $logger->info('Configuration initialized successfully'); |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | * @param mixed $default the default value to use if can not find the config item in the list |
107 | 107 | * @return mixed the config value if exist or the default value |
108 | 108 | */ |
109 | - public static function get($item, $default = null){ |
|
109 | + public static function get($item, $default = null) { |
|
110 | 110 | $logger = static::getLogger(); |
111 | - if(array_key_exists($item, self::$config)){ |
|
111 | + if (array_key_exists($item, self::$config)) { |
|
112 | 112 | return self::$config[$item]; |
113 | 113 | } |
114 | - $logger->warning('Cannot find config item ['.$item.'] using the default value ['.$default.']'); |
|
114 | + $logger->warning('Cannot find config item [' . $item . '] using the default value [' . $default . ']'); |
|
115 | 115 | return $default; |
116 | 116 | } |
117 | 117 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @param string $item the config item name to set |
121 | 121 | * @param mixed $value the config item value |
122 | 122 | */ |
123 | - public static function set($item, $value){ |
|
123 | + public static function set($item, $value) { |
|
124 | 124 | self::$config[$item] = $value; |
125 | 125 | } |
126 | 126 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * Get all the configuration values |
129 | 129 | * @return array the config values |
130 | 130 | */ |
131 | - public static function getAll(){ |
|
131 | + public static function getAll() { |
|
132 | 132 | return self::$config; |
133 | 133 | } |
134 | 134 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * Set the configuration values bu merged with the existing configuration |
137 | 137 | * @param array $config the config values to add in the configuration list |
138 | 138 | */ |
139 | - public static function setAll(array $config = array()){ |
|
139 | + public static function setAll(array $config = array()) { |
|
140 | 140 | self::$config = array_merge(self::$config, $config); |
141 | 141 | } |
142 | 142 | |
@@ -145,15 +145,15 @@ discard block |
||
145 | 145 | * @param string $item the config item name to be deleted |
146 | 146 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
147 | 147 | */ |
148 | - public static function delete($item){ |
|
148 | + public static function delete($item) { |
|
149 | 149 | $logger = static::getLogger(); |
150 | - if(array_key_exists($item, self::$config)){ |
|
151 | - $logger->info('Delete config item ['.$item.']'); |
|
150 | + if (array_key_exists($item, self::$config)) { |
|
151 | + $logger->info('Delete config item [' . $item . ']'); |
|
152 | 152 | unset(self::$config[$item]); |
153 | 153 | return true; |
154 | 154 | } |
155 | - else{ |
|
156 | - $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
|
155 | + else { |
|
156 | + $logger->warning('Config item [' . $item . '] to be deleted does not exists'); |
|
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * Load the configuration file. This an alias to Loader::config() |
163 | 163 | * @param string $config the config name to be loaded |
164 | 164 | */ |
165 | - public static function load($config){ |
|
165 | + public static function load($config) { |
|
166 | 166 | Loader::config($config); |
167 | 167 | } |
168 | 168 | } |
@@ -78,15 +78,13 @@ discard block |
||
78 | 78 | //check if the server is running under IPv6 |
79 | 79 | if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE){ |
80 | 80 | $baseUrl = '['.$_SERVER['SERVER_ADDR'].']'; |
81 | - } |
|
82 | - else{ |
|
81 | + } else{ |
|
83 | 82 | $baseUrl = $_SERVER['SERVER_ADDR']; |
84 | 83 | } |
85 | 84 | $port = ((isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80' && ! is_https() || $_SERVER['SERVER_PORT'] != '443' && is_https()) ) ? ':' . $_SERVER['SERVER_PORT'] : ''); |
86 | 85 | $baseUrl = (is_https() ? 'https' : 'http').'://' . $baseUrl . $port |
87 | 86 | . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME']))); |
88 | - } |
|
89 | - else{ |
|
87 | + } else{ |
|
90 | 88 | $logger->warning('Can not determine the application base URL automatically, use http://localhost as default'); |
91 | 89 | $baseUrl = 'http://localhost/'; |
92 | 90 | } |
@@ -151,8 +149,7 @@ discard block |
||
151 | 149 | $logger->info('Delete config item ['.$item.']'); |
152 | 150 | unset(self::$config[$item]); |
153 | 151 | return true; |
154 | - } |
|
155 | - else{ |
|
152 | + } else{ |
|
156 | 153 | $logger->warning('Config item ['.$item.'] to be deleted does not exists'); |
157 | 154 | return false; |
158 | 155 | } |
@@ -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,16 +147,16 @@ discard block |
||
147 | 147 | * @param string $sessionName the session name |
148 | 148 | * @return boolean |
149 | 149 | */ |
150 | - public function open($savePath, $sessionName){ |
|
150 | + public function open($savePath, $sessionName) { |
|
151 | 151 | $this->logger->debug('Opening database session handler for [' . $sessionName . ']'); |
152 | 152 | //try to check if session secret is set before |
153 | - if(! $this->getSessionSecret()){ |
|
153 | + if (!$this->getSessionSecret()) { |
|
154 | 154 | $secret = get_config('session_secret', false); |
155 | 155 | $this->setSessionSecret($secret); |
156 | 156 | } |
157 | 157 | $this->logger->info('Session secret: ' . $this->getSessionSecret()); |
158 | 158 | |
159 | - if(! $this->getModelInstance()){ |
|
159 | + if (!$this->getModelInstance()) { |
|
160 | 160 | $this->setModelInstanceFromConfig(); |
161 | 161 | } |
162 | 162 | $this->setInitializerVector($this->getSessionSecret()); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | //set session tables columns |
165 | 165 | $this->sessionTableColumns = $this->getModelInstance()->getSessionTableColumns(); |
166 | 166 | |
167 | - if(empty($this->sessionTableColumns)){ |
|
167 | + if (empty($this->sessionTableColumns)) { |
|
168 | 168 | show_error('The session handler is "database" but the table columns not set'); |
169 | 169 | } |
170 | 170 | $this->logger->info('Database session, the model columns are listed below: ' . stringfy_vars($this->sessionTableColumns)); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * Close the session |
181 | 181 | * @return boolean |
182 | 182 | */ |
183 | - public function close(){ |
|
183 | + public function close() { |
|
184 | 184 | $this->logger->debug('Closing database session handler'); |
185 | 185 | return true; |
186 | 186 | } |
@@ -190,28 +190,28 @@ discard block |
||
190 | 190 | * @param string $sid the session id to use |
191 | 191 | * @return mixed the session data in serialiaze format |
192 | 192 | */ |
193 | - public function read($sid){ |
|
193 | + public function read($sid) { |
|
194 | 194 | $this->logger->debug('Reading database session data for SID: ' . $sid); |
195 | 195 | $instance = $this->getModelInstance(); |
196 | 196 | $columns = $this->sessionTableColumns; |
197 | - if($this->getLoader()){ |
|
197 | + if ($this->getLoader()) { |
|
198 | 198 | $this->getLoader()->functions('user_agent'); |
199 | 199 | $this->getLoader()->library('Browser'); |
200 | 200 | } |
201 | - else{ |
|
201 | + else { |
|
202 | 202 | Loader::functions('user_agent'); |
203 | 203 | Loader::library('Browser'); |
204 | 204 | } |
205 | 205 | |
206 | 206 | $ip = get_ip(); |
207 | 207 | $host = @gethostbyaddr($ip) or null; |
208 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
208 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
209 | 209 | |
210 | 210 | $data = $instance->get_by(array($columns['sid'] => $sid, $columns['shost'] => $host, $columns['sbrowser'] => $browser)); |
211 | - if($data && isset($data->{$columns['sdata']})){ |
|
211 | + if ($data && isset($data->{$columns['sdata']})) { |
|
212 | 212 | //checking inactivity |
213 | 213 | $timeInactivity = time() - get_config('session_inactivity_time', 100); |
214 | - if($data->{$columns['stime']} < $timeInactivity){ |
|
214 | + if ($data->{$columns['stime']} < $timeInactivity) { |
|
215 | 215 | $this->logger->info('Database session data for SID: ' . $sid . ' already expired, destroy it'); |
216 | 216 | $this->destroy($sid); |
217 | 217 | return false; |
@@ -228,16 +228,16 @@ discard block |
||
228 | 228 | * @param mixed $data the session data to save in serialize format |
229 | 229 | * @return boolean |
230 | 230 | */ |
231 | - public function write($sid, $data){ |
|
231 | + public function write($sid, $data) { |
|
232 | 232 | $this->logger->debug('Saving database session data for SID: ' . $sid . ', data: ' . stringfy_vars($data)); |
233 | 233 | $instance = $this->getModelInstance(); |
234 | 234 | $columns = $this->sessionTableColumns; |
235 | 235 | |
236 | - if($this->getLoader()){ |
|
236 | + if ($this->getLoader()) { |
|
237 | 237 | $this->getLoader()->functions('user_agent'); |
238 | 238 | $this->getLoader()->library('Browser'); |
239 | 239 | } |
240 | - else{ |
|
240 | + else { |
|
241 | 241 | Loader::functions('user_agent'); |
242 | 242 | Loader::library('Browser'); |
243 | 243 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $ip = get_ip(); |
246 | 246 | $keyValue = $instance->getKeyValue(); |
247 | 247 | $host = @gethostbyaddr($ip) or null; |
248 | - $browser = $this->OBJ->browser->getPlatform().', '.$this->OBJ->browser->getBrowser().' '.$this->OBJ->browser->getVersion(); |
|
248 | + $browser = $this->OBJ->browser->getPlatform() . ', ' . $this->OBJ->browser->getBrowser() . ' ' . $this->OBJ->browser->getVersion(); |
|
249 | 249 | $data = $this->encode($data); |
250 | 250 | $params = array( |
251 | 251 | $columns['sid'] => $sid, |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | ); |
259 | 259 | $this->logger->info('Database session data to save are listed below :' . stringfy_vars($params)); |
260 | 260 | $exists = $instance->get($sid); |
261 | - if($exists){ |
|
261 | + if ($exists) { |
|
262 | 262 | $this->logger->info('Session data for SID: ' . $sid . ' already exists, just update it'); |
263 | 263 | //update |
264 | 264 | unset($params[$columns['sid']]); |
265 | 265 | $instance->update($sid, $params); |
266 | 266 | } |
267 | - else{ |
|
267 | + else { |
|
268 | 268 | $this->logger->info('Session data for SID: ' . $sid . ' not yet exists, insert it now'); |
269 | 269 | $instance->insert($params); |
270 | 270 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param string $sid the session id value |
278 | 278 | * @return boolean |
279 | 279 | */ |
280 | - public function destroy($sid){ |
|
280 | + public function destroy($sid) { |
|
281 | 281 | $this->logger->debug('Destroy of session data for SID: ' . $sid); |
282 | 282 | $instance = $this->modelInstanceName; |
283 | 283 | $instance->delete($sid); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @param integer $maxLifetime the max lifetime |
290 | 290 | * @return boolean |
291 | 291 | */ |
292 | - public function gc($maxLifetime){ |
|
292 | + public function gc($maxLifetime) { |
|
293 | 293 | $instance = $this->modelInstanceName; |
294 | 294 | $time = time() - $maxLifetime; |
295 | 295 | $this->logger->debug('Garbage collector of expired session. maxLifetime [' . $maxLifetime . '] sec, expired time [' . $time . ']'); |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | * @param mixed $data the session data to encode |
303 | 303 | * @return mixed the encoded session data |
304 | 304 | */ |
305 | - public function encode($data){ |
|
305 | + public function encode($data) { |
|
306 | 306 | $key = base64_decode($this->sessionSecret); |
307 | - $dataEncrypted = openssl_encrypt($data , self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
307 | + $dataEncrypted = openssl_encrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
|
308 | 308 | $output = base64_encode($dataEncrypted); |
309 | 309 | return $output; |
310 | 310 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param mixed $data the data to decode |
316 | 316 | * @return mixed the decoded data |
317 | 317 | */ |
318 | - public function decode($data){ |
|
318 | + public function decode($data) { |
|
319 | 319 | $key = base64_decode($this->sessionSecret); |
320 | 320 | $data = base64_decode($data); |
321 | 321 | $data = openssl_decrypt($data, self::DB_SESSION_HASH_METHOD, $key, OPENSSL_RAW_DATA, $this->getInitializerVector()); |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * Return the loader instance |
328 | 328 | * @return object Loader the loader instance |
329 | 329 | */ |
330 | - public function getLoader(){ |
|
330 | + public function getLoader() { |
|
331 | 331 | return $this->loader; |
332 | 332 | } |
333 | 333 | |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | * set the loader instance for future use |
336 | 336 | * @param object Loader $loader the loader object |
337 | 337 | */ |
338 | - public function setLoader($loader){ |
|
338 | + public function setLoader($loader) { |
|
339 | 339 | $this->loader = $loader; |
340 | 340 | return $this; |
341 | 341 | } |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * Return the model instance |
345 | 345 | * @return object DBSessionHandlerModel the model instance |
346 | 346 | */ |
347 | - public function getModelInstance(){ |
|
347 | + public function getModelInstance() { |
|
348 | 348 | return $this->modelInstanceName; |
349 | 349 | } |
350 | 350 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * set the model instance for future use |
353 | 353 | * @param DBSessionHandlerModel $modelInstance the model object |
354 | 354 | */ |
355 | - public function setModelInstance(DBSessionHandlerModel $modelInstance){ |
|
355 | + public function setModelInstance(DBSessionHandlerModel $modelInstance) { |
|
356 | 356 | $this->modelInstanceName = $modelInstance; |
357 | 357 | return $this; |
358 | 358 | } |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | * Return the Log instance |
362 | 362 | * @return Log |
363 | 363 | */ |
364 | - public function getLogger(){ |
|
364 | + public function getLogger() { |
|
365 | 365 | return $this->logger; |
366 | 366 | } |
367 | 367 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * Set the log instance |
370 | 370 | * @param Log $logger the log object |
371 | 371 | */ |
372 | - public function setLogger(Log $logger){ |
|
372 | + public function setLogger(Log $logger) { |
|
373 | 373 | $this->logger = $logger; |
374 | 374 | return $this; |
375 | 375 | } |
@@ -377,18 +377,18 @@ discard block |
||
377 | 377 | /** |
378 | 378 | * Set the model instance using the configuration for session |
379 | 379 | */ |
380 | - private function setModelInstanceFromConfig(){ |
|
380 | + private function setModelInstanceFromConfig() { |
|
381 | 381 | $modelName = get_config('session_save_path'); |
382 | 382 | $this->logger->info('The database session model: ' . $modelName); |
383 | - if($this->getLoader()){ |
|
383 | + if ($this->getLoader()) { |
|
384 | 384 | $this->getLoader()->model($modelName, 'dbsessionhandlerinstance'); |
385 | 385 | } |
386 | 386 | //@codeCoverageIgnoreStart |
387 | - else{ |
|
387 | + else { |
|
388 | 388 | Loader::model($modelName, 'dbsessionhandlerinstance'); |
389 | 389 | } |
390 | - if(isset($this->OBJ->dbsessionhandlerinstance) && ! $this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel){ |
|
391 | - show_error('To use database session handler, your class model "'.get_class($this->OBJ->dbsessionhandlerinstance).'" need extends "DBSessionHandlerModel"'); |
|
390 | + if (isset($this->OBJ->dbsessionhandlerinstance) && !$this->OBJ->dbsessionhandlerinstance instanceof DBSessionHandlerModel) { |
|
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 |
@@ -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; |