@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $instance = crc32($driver . serialize($config)); |
| 190 | - if (!isset(self::$instances[ $instance ])) { |
|
| 190 | + if (!isset(self::$instances[$instance])) { |
|
| 191 | 191 | $badPracticeOmeter[$driver] = 1; |
| 192 | - if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){ |
|
| 192 | + if (!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')) { |
|
| 193 | 193 | 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); |
| 194 | 194 | } |
| 195 | 195 | $class = self::getNamespacePath() . $driver . '\Driver'; |
| 196 | - try{ |
|
| 197 | - self::$instances[ $instance ] = new $class($config); |
|
| 198 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
| 199 | - }catch(phpFastCacheDriverCheckException $e){ |
|
| 196 | + try { |
|
| 197 | + self::$instances[$instance] = new $class($config); |
|
| 198 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
| 199 | + } catch (phpFastCacheDriverCheckException $e) { |
|
| 200 | 200 | $fallback = self::standardizeDriverName($config['fallback']); |
| 201 | - if($fallback && $fallback !== $driver){ |
|
| 201 | + if ($fallback && $fallback !== $driver) { |
|
| 202 | 202 | $class = self::getNamespacePath() . $fallback . '\Driver'; |
| 203 | - self::$instances[ $instance ] = new $class($config); |
|
| 204 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
| 203 | + self::$instances[$instance] = new $class($config); |
|
| 204 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
| 205 | 205 | trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); |
| 206 | - }else{ |
|
| 206 | + } else { |
|
| 207 | 207 | throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e); |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | - } else if(++$badPracticeOmeter[$driver] >= 5){ |
|
| 210 | + } else if (++$badPracticeOmeter[$driver] >= 5) { |
|
| 211 | 211 | trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
| 212 | 212 | See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - return self::$instances[ $instance ]; |
|
| 215 | + return self::$instances[$instance]; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | public static function __callStatic($name, $arguments) |
| 275 | 275 | { |
| 276 | - $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []); |
|
| 276 | + $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[0] : []); |
|
| 277 | 277 | |
| 278 | 278 | return self::getInstance($name, $options); |
| 279 | 279 | } |
@@ -314,9 +314,9 @@ discard block |
||
| 314 | 314 | { |
| 315 | 315 | if (is_array($name)) { |
| 316 | 316 | self::$config = array_merge(self::$config, $name); |
| 317 | - } else if (is_string($name)){ |
|
| 318 | - self::$config[ $name ] = $value; |
|
| 319 | - }else{ |
|
| 317 | + } else if (is_string($name)) { |
|
| 318 | + self::$config[$name] = $value; |
|
| 319 | + } else { |
|
| 320 | 320 | throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name'); |
| 321 | 321 | } |
| 322 | 322 | } |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | */ |
| 376 | 376 | public static function standardizeDriverName($driverName) |
| 377 | 377 | { |
| 378 | - if(!is_string($driverName)){ |
|
| 378 | + if (!is_string($driverName)) { |
|
| 379 | 379 | throw new phpFastCacheInvalidArgumentException(sprintf('Expected $driverName to be a string got "%s" instead', gettype($driverName))); |
| 380 | 380 | } |
| 381 | 381 | return ucfirst(strtolower(trim($driverName))); |
@@ -390,70 +390,70 @@ discard block |
||
| 390 | 390 | protected static function validateConfig(array $config) |
| 391 | 391 | { |
| 392 | 392 | foreach ($config as $configName => $configValue) { |
| 393 | - switch($configName) |
|
| 393 | + switch ($configName) |
|
| 394 | 394 | { |
| 395 | 395 | case 'itemDetailedDate': |
| 396 | - if(!is_bool($configValue)){ |
|
| 396 | + if (!is_bool($configValue)) { |
|
| 397 | 397 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
| 398 | 398 | } |
| 399 | 399 | break; |
| 400 | 400 | case 'autoTmpFallback': |
| 401 | - if(!is_bool($configValue)){ |
|
| 401 | + if (!is_bool($configValue)) { |
|
| 402 | 402 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
| 403 | 403 | } |
| 404 | 404 | break; |
| 405 | 405 | case 'secureFileManipulation': |
| 406 | - if(!is_bool($configValue)){ |
|
| 406 | + if (!is_bool($configValue)) { |
|
| 407 | 407 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
| 408 | 408 | } |
| 409 | 409 | break; |
| 410 | 410 | case 'ignoreSymfonyNotice': |
| 411 | - if(!is_bool($configValue)){ |
|
| 411 | + if (!is_bool($configValue)) { |
|
| 412 | 412 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
| 413 | 413 | } |
| 414 | 414 | break; |
| 415 | 415 | case 'defaultTtl': |
| 416 | - if(!is_numeric($configValue)){ |
|
| 416 | + if (!is_numeric($configValue)) { |
|
| 417 | 417 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be numeric"); |
| 418 | 418 | } |
| 419 | 419 | break; |
| 420 | 420 | case 'defaultKeyHashFunction': |
| 421 | - if(!is_string($configValue) && !function_exists($configValue)){ |
|
| 421 | + if (!is_string($configValue) && !function_exists($configValue)) { |
|
| 422 | 422 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a valid function name string"); |
| 423 | 423 | } |
| 424 | 424 | break; |
| 425 | 425 | case 'securityKey': |
| 426 | - if(!is_string($configValue)){ |
|
| 426 | + if (!is_string($configValue)) { |
|
| 427 | 427 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string"); |
| 428 | 428 | } |
| 429 | 429 | break; |
| 430 | 430 | case 'htaccess': |
| 431 | - if(!is_bool($configValue)){ |
|
| 431 | + if (!is_bool($configValue)) { |
|
| 432 | 432 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
| 433 | 433 | } |
| 434 | 434 | break; |
| 435 | 435 | case 'default_chmod': |
| 436 | - if(!is_int($configValue)){ |
|
| 436 | + if (!is_int($configValue)) { |
|
| 437 | 437 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer"); |
| 438 | 438 | } |
| 439 | 439 | break; |
| 440 | 440 | case 'path': |
| 441 | - if(!is_string($configValue)){ |
|
| 441 | + if (!is_string($configValue)) { |
|
| 442 | 442 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string"); |
| 443 | 443 | } |
| 444 | 444 | break; |
| 445 | 445 | case 'fallback': |
| 446 | - if(!is_bool($configValue)){ |
|
| 446 | + if (!is_bool($configValue)) { |
|
| 447 | 447 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
| 448 | 448 | } |
| 449 | 449 | break; |
| 450 | 450 | case 'limited_memory_each_object': |
| 451 | - if(!is_int($configValue)){ |
|
| 451 | + if (!is_int($configValue)) { |
|
| 452 | 452 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer"); |
| 453 | 453 | } |
| 454 | 454 | break; |
| 455 | 455 | case 'compress_data': |
| 456 | - if(!is_bool($configValue)){ |
|
| 456 | + if (!is_bool($configValue)) { |
|
| 457 | 457 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
| 458 | 458 | } |
| 459 | 459 | break; |