@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * @param $keyword |
|
133 | + * @param string|false $keyword |
|
134 | 134 | * @param bool $skip |
135 | 135 | * @return string |
136 | 136 | * @throws phpFastCacheIOException |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | /** |
178 | 178 | * @param $filename |
179 | - * @return mixed |
|
179 | + * @return string |
|
180 | 180 | */ |
181 | 181 | protected static function cleanFileName($filename) |
182 | 182 | { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * @param $path |
|
194 | + * @param string $path |
|
195 | 195 | * @param bool $create |
196 | 196 | * @throws phpFastCacheIOException |
197 | 197 | */ |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | |
226 | 226 | |
227 | 227 | /** |
228 | - * @param $file |
|
228 | + * @param string $file |
|
229 | 229 | * @return string |
230 | 230 | * @throws phpFastCacheIOException |
231 | 231 | */ |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | { |
35 | 35 | $tmp_dir = rtrim(ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(), '\\/') . DIRECTORY_SEPARATOR . 'phpfastcache'; |
36 | 36 | |
37 | - if (!isset($this->config[ 'path' ]) || $this->config[ 'path' ] == '') { |
|
37 | + if (!isset($this->config['path']) || $this->config['path'] == '') { |
|
38 | 38 | if (self::isPHPModule()) { |
39 | 39 | $path = $tmp_dir; |
40 | 40 | } else { |
41 | - $document_root_path = rtrim($_SERVER[ 'DOCUMENT_ROOT' ], '/') . '/../'; |
|
42 | - $path = isset($_SERVER[ 'DOCUMENT_ROOT' ]) && is_writable($document_root_path) ? $document_root_path : rtrim(__DIR__, '/') . 'PathSeekerTrait.php/'; |
|
41 | + $document_root_path = rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/../'; |
|
42 | + $path = isset($_SERVER['DOCUMENT_ROOT']) && is_writable($document_root_path) ? $document_root_path : rtrim(__DIR__, '/') . 'PathSeekerTrait.php/'; |
|
43 | 43 | } |
44 | 44 | |
45 | - if ($this->config[ 'path' ] != '') { |
|
46 | - $path = $this->config[ 'path' ]; |
|
45 | + if ($this->config['path'] != '') { |
|
46 | + $path = $this->config['path']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | } else { |
50 | - $path = $this->config[ 'path' ]; |
|
50 | + $path = $this->config['path']; |
|
51 | 51 | } |
52 | 52 | |
53 | - $securityKey = array_key_exists('securityKey', $this->config) ? $this->config[ 'securityKey' ] : ''; |
|
53 | + $securityKey = array_key_exists('securityKey', $this->config) ? $this->config['securityKey'] : ''; |
|
54 | 54 | if (!$securityKey || $securityKey === 'auto') { |
55 | - if (isset($_SERVER[ 'HTTP_HOST' ])) { |
|
56 | - $securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER[ 'HTTP_HOST' ]))); |
|
55 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
56 | + $securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER['HTTP_HOST']))); |
|
57 | 57 | } else { |
58 | 58 | $securityKey = ($this->isPHPModule() ? 'web' : 'cli'); |
59 | 59 | } |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | return $full_path; |
73 | 73 | } |
74 | 74 | |
75 | - if (!isset($this->tmp[ $full_pathx ]) || (!@file_exists($full_path) || !@is_writable($full_path))) { |
|
75 | + if (!isset($this->tmp[$full_pathx]) || (!@file_exists($full_path) || !@is_writable($full_path))) { |
|
76 | 76 | if (!@file_exists($full_path)) { |
77 | 77 | @mkdir($full_path, $this->setChmodAuto(), true); |
78 | - }else if (!@is_writable($full_path)) { |
|
78 | + } else if (!@is_writable($full_path)) { |
|
79 | 79 | @chmod($full_path, $this->setChmodAuto()); |
80 | 80 | } |
81 | 81 | |
82 | - if ($this->config[ 'autoTmpFallback' ] && !@is_writable($full_path)) { |
|
82 | + if ($this->config['autoTmpFallback'] && !@is_writable($full_path)) { |
|
83 | 83 | /** |
84 | 84 | * Switch back to tmp dir |
85 | 85 | * again if the path is not writable |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | throw new phpFastCacheIOException('PLEASE CREATE OR CHMOD ' . $full_path . ' - 0777 OR ANY WRITABLE PERMISSION!'); |
94 | 94 | } |
95 | 95 | |
96 | - $this->tmp[ $full_pathx ] = true; |
|
97 | - $this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config[ 'htaccess' ] : false); |
|
96 | + $this->tmp[$full_pathx] = true; |
|
97 | + $this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config['htaccess'] : false); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | return realpath($full_path); |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function setChmodAuto() |
169 | 169 | { |
170 | - if (!isset($this->config[ 'default_chmod' ]) || $this->config[ 'default_chmod' ] == '' || is_null($this->config[ 'default_chmod' ])) { |
|
170 | + if (!isset($this->config['default_chmod']) || $this->config['default_chmod'] == '' || is_null($this->config['default_chmod'])) { |
|
171 | 171 | return 0777; |
172 | 172 | } else { |
173 | - return $this->config[ 'default_chmod' ]; |
|
173 | + return $this->config['default_chmod']; |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | if ($create === true) { |
201 | 201 | if (!is_writable($path)) { |
202 | 202 | try { |
203 | - if(!chmod($path, 0777)){ |
|
203 | + if (!chmod($path, 0777)) { |
|
204 | 204 | throw new phpFastCacheIOException('Chmod failed on : ' . $path); |
205 | 205 | } |
206 | 206 | } catch (phpFastCacheIOException $e) { |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | $this->eventManager->dispatch('CacheWriteFileOnDisk', $this, $file, $secureFileManipulation); |
270 | 270 | |
271 | - if($secureFileManipulation){ |
|
271 | + if ($secureFileManipulation) { |
|
272 | 272 | $tmpFilename = Directory::getAbsolutePath(dirname($file) . '/tmp_' . md5( |
273 | 273 | str_shuffle(uniqid($this->getDriverName(), false)) |
274 | 274 | . str_shuffle(uniqid($this->getDriverName(), false)) |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | flock($f, LOCK_UN); |
281 | 281 | fclose($f); |
282 | 282 | |
283 | - if(!rename($tmpFilename, $file)){ |
|
283 | + if (!rename($tmpFilename, $file)) { |
|
284 | 284 | throw new phpFastCacheIOException(sprintf('Failed to rename %s to %s', $tmpFilename, $file)); |
285 | 285 | } |
286 | - }else{ |
|
286 | + } else { |
|
287 | 287 | $f = fopen($file, 'w+'); |
288 | 288 | $octetWritten = fwrite($f, $data); |
289 | 289 | fclose($f); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | if (!isset($this->tmp[ $full_pathx ]) || (!@file_exists($full_path) || !@is_writable($full_path))) { |
76 | 76 | if (!@file_exists($full_path)) { |
77 | 77 | @mkdir($full_path, $this->setChmodAuto(), true); |
78 | - }else if (!@is_writable($full_path)) { |
|
78 | + } else if (!@is_writable($full_path)) { |
|
79 | 79 | @chmod($full_path, $this->setChmodAuto()); |
80 | 80 | } |
81 | 81 | |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | if(!rename($tmpFilename, $file)){ |
284 | 284 | throw new phpFastCacheIOException(sprintf('Failed to rename %s to %s', $tmpFilename, $file)); |
285 | 285 | } |
286 | - }else{ |
|
286 | + } else{ |
|
287 | 287 | $f = fopen($file, 'w+'); |
288 | 288 | $octetWritten = fwrite($f, $data); |
289 | 289 | fclose($f); |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | * @var ExtendedCacheItemPoolInterface[] |
57 | 57 | */ |
58 | 58 | protected static $config = [ |
59 | - 'itemDetailedDate' => false,// Specify if the item must provide detailed creation/modification dates |
|
60 | - 'autoTmpFallback' => false,// Automatically attempt to fallback to temporary directory if the cache fails to write on the specified directory |
|
61 | - 'secureFileManipulation' => false,// Provide a secure file manipulation mechanism, on intensive usage the performance can be affected. |
|
62 | - 'ignoreSymfonyNotice' => false,// Ignore Symfony notice for Symfony project which do not makes use of PhpFastCache's Symfony Bundle |
|
63 | - 'defaultTtl' => 900,// Default time-to-live in second |
|
64 | - 'securityKey' => 'auto',// The securityKey that will be used to create sub-directory |
|
65 | - 'htaccess' => true,// Auto-generate .htaccess if tit is missing |
|
66 | - 'default_chmod' => 0777, // 0777 recommended |
|
67 | - 'path' => '',// if not set will be the value of sys_get_temp_dir() |
|
68 | - 'fallback' => false, //Fall back when old driver is not support |
|
69 | - 'limited_memory_each_object' => 4096, // maximum size (bytes) of object store in memory |
|
70 | - 'compress_data' => false, // compress stored data, if the backend supports it |
|
59 | + 'itemDetailedDate' => false,// Specify if the item must provide detailed creation/modification dates |
|
60 | + 'autoTmpFallback' => false,// Automatically attempt to fallback to temporary directory if the cache fails to write on the specified directory |
|
61 | + 'secureFileManipulation' => false,// Provide a secure file manipulation mechanism, on intensive usage the performance can be affected. |
|
62 | + 'ignoreSymfonyNotice' => false,// Ignore Symfony notice for Symfony project which do not makes use of PhpFastCache's Symfony Bundle |
|
63 | + 'defaultTtl' => 900,// Default time-to-live in second |
|
64 | + 'securityKey' => 'auto',// The securityKey that will be used to create sub-directory |
|
65 | + 'htaccess' => true,// Auto-generate .htaccess if tit is missing |
|
66 | + 'default_chmod' => 0777, // 0777 recommended |
|
67 | + 'path' => '',// if not set will be the value of sys_get_temp_dir() |
|
68 | + 'fallback' => false, //Fall back when old driver is not support |
|
69 | + 'limited_memory_each_object' => 4096, // maximum size (bytes) of object store in memory |
|
70 | + 'compress_data' => false, // compress stored data, if the backend supports it |
|
71 | 71 | ]; |
72 | 72 | |
73 | 73 | /** |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | } |
123 | 123 | } else if(++$badPracticeOmeter[$driver] >= 5){ |
124 | - trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
|
124 | + trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
|
125 | 125 | See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); |
126 | 126 | } |
127 | 127 | |
@@ -260,21 +260,21 @@ discard block |
||
260 | 260 | public static function getStaticSystemDrivers() |
261 | 261 | { |
262 | 262 | return [ |
263 | - 'Sqlite', |
|
264 | - 'Files', |
|
265 | - 'Apc', |
|
266 | - 'Apcu', |
|
267 | - 'Memcache', |
|
268 | - 'Memcached', |
|
269 | - 'Couchbase', |
|
270 | - 'Mongodb', |
|
271 | - 'Predis', |
|
272 | - 'Redis', |
|
273 | - 'Ssdb', |
|
274 | - 'Leveldb', |
|
275 | - 'Wincache', |
|
276 | - 'Xcache', |
|
277 | - 'Devnull', |
|
263 | + 'Sqlite', |
|
264 | + 'Files', |
|
265 | + 'Apc', |
|
266 | + 'Apcu', |
|
267 | + 'Memcache', |
|
268 | + 'Memcached', |
|
269 | + 'Couchbase', |
|
270 | + 'Mongodb', |
|
271 | + 'Predis', |
|
272 | + 'Redis', |
|
273 | + 'Ssdb', |
|
274 | + 'Leveldb', |
|
275 | + 'Wincache', |
|
276 | + 'Xcache', |
|
277 | + 'Devnull', |
|
278 | 278 | ]; |
279 | 279 | } |
280 | 280 |
@@ -56,15 +56,15 @@ discard block |
||
56 | 56 | * @var ExtendedCacheItemPoolInterface[] |
57 | 57 | */ |
58 | 58 | protected static $config = [ |
59 | - 'itemDetailedDate' => false,// Specify if the item must provide detailed creation/modification dates |
|
60 | - 'autoTmpFallback' => false,// Automatically attempt to fallback to temporary directory if the cache fails to write on the specified directory |
|
61 | - 'secureFileManipulation' => false,// Provide a secure file manipulation mechanism, on intensive usage the performance can be affected. |
|
62 | - 'ignoreSymfonyNotice' => false,// Ignore Symfony notice for Symfony project which do not makes use of PhpFastCache's Symfony Bundle |
|
63 | - 'defaultTtl' => 900,// Default time-to-live in second |
|
64 | - 'securityKey' => 'auto',// The securityKey that will be used to create sub-directory |
|
65 | - 'htaccess' => true,// Auto-generate .htaccess if tit is missing |
|
59 | + 'itemDetailedDate' => false, // Specify if the item must provide detailed creation/modification dates |
|
60 | + 'autoTmpFallback' => false, // Automatically attempt to fallback to temporary directory if the cache fails to write on the specified directory |
|
61 | + 'secureFileManipulation' => false, // Provide a secure file manipulation mechanism, on intensive usage the performance can be affected. |
|
62 | + 'ignoreSymfonyNotice' => false, // Ignore Symfony notice for Symfony project which do not makes use of PhpFastCache's Symfony Bundle |
|
63 | + 'defaultTtl' => 900, // Default time-to-live in second |
|
64 | + 'securityKey' => 'auto', // The securityKey that will be used to create sub-directory |
|
65 | + 'htaccess' => true, // Auto-generate .htaccess if tit is missing |
|
66 | 66 | 'default_chmod' => 0777, // 0777 recommended |
67 | - 'path' => '',// if not set will be the value of sys_get_temp_dir() |
|
67 | + 'path' => '', // if not set will be the value of sys_get_temp_dir() |
|
68 | 68 | 'fallback' => false, //Fall back when old driver is not support |
69 | 69 | 'limited_memory_each_object' => 4096, // maximum size (bytes) of object store in memory |
70 | 70 | 'compress_data' => false, // compress stored data, if the backend supports it |
@@ -100,32 +100,32 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | $instance = crc32($driver . serialize($config)); |
103 | - if (!isset(self::$instances[ $instance ])) { |
|
103 | + if (!isset(self::$instances[$instance])) { |
|
104 | 104 | $badPracticeOmeter[$driver] = 1; |
105 | - if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){ |
|
105 | + if (!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')) { |
|
106 | 106 | trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle', E_USER_NOTICE); |
107 | 107 | } |
108 | 108 | $class = self::getNamespacePath() . $driver . '\Driver'; |
109 | - try{ |
|
110 | - self::$instances[ $instance ] = new $class($config); |
|
111 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
112 | - }catch(phpFastCacheDriverCheckException $e){ |
|
109 | + try { |
|
110 | + self::$instances[$instance] = new $class($config); |
|
111 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
112 | + } catch (phpFastCacheDriverCheckException $e) { |
|
113 | 113 | $fallback = self::standardizeDriverName($config['fallback']); |
114 | - if($fallback && $fallback !== $driver){ |
|
114 | + if ($fallback && $fallback !== $driver) { |
|
115 | 115 | $class = self::getNamespacePath() . $fallback . '\Driver'; |
116 | - self::$instances[ $instance ] = new $class($config); |
|
117 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
116 | + self::$instances[$instance] = new $class($config); |
|
117 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
118 | 118 | trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); |
119 | - }else{ |
|
119 | + } else { |
|
120 | 120 | throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e); |
121 | 121 | } |
122 | 122 | } |
123 | - } else if(++$badPracticeOmeter[$driver] >= 5){ |
|
123 | + } else if (++$badPracticeOmeter[$driver] >= 5) { |
|
124 | 124 | trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
125 | 125 | See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); |
126 | 126 | } |
127 | 127 | |
128 | - return self::$instances[ $instance ]; |
|
128 | + return self::$instances[$instance]; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public static function __callStatic($name, $arguments) |
188 | 188 | { |
189 | - $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []); |
|
189 | + $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[0] : []); |
|
190 | 190 | |
191 | 191 | return self::getInstance($name, $options); |
192 | 192 | } |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | { |
240 | 240 | if (is_array($name)) { |
241 | 241 | self::$config = array_merge(self::$config, $name); |
242 | - } else if (is_string($name)){ |
|
243 | - self::$config[ $name ] = $value; |
|
244 | - }else{ |
|
242 | + } else if (is_string($name)) { |
|
243 | + self::$config[$name] = $value; |
|
244 | + } else { |
|
245 | 245 | throw new \InvalidArgumentException('Invalid variable type: $name'); |
246 | 246 | } |
247 | 247 | } |