From 836db3c8eea5af8867c5ddb89154674c168178c7 Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Fri, 12 May 2017 18:19:12 +0200 Subject: [PATCH] Fixed #456 // Bug of Exception workflow in cacheManager introduced in v6 --- src/phpFastCache/CacheManager.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/phpFastCache/CacheManager.php b/src/phpFastCache/CacheManager.php index 87271a622..f69f9d397 100644 --- a/src/phpFastCache/CacheManager.php +++ b/src/phpFastCache/CacheManager.php @@ -171,6 +171,7 @@ class CacheManager * @param array $config * @return ExtendedCacheItemPoolInterface * @throws phpFastCacheDriverCheckException + * @throws phpFastCacheInvalidConfigurationException */ public static function getInstance($driver = 'auto', array $config = []) { @@ -197,12 +198,20 @@ public static function getInstance($driver = 'auto', array $config = []) self::$instances[ $instance ] = new $class($config); self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); }catch(phpFastCacheDriverCheckException $e){ - $fallback = self::standardizeDriverName($config['fallback']); - if($fallback && $fallback !== $driver){ - $class = self::getNamespacePath() . $fallback . '\Driver'; - self::$instances[ $instance ] = new $class($config); - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); - trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); + if($config['fallback']){ + try{ + $fallback = self::standardizeDriverName($config['fallback']); + if($fallback !== $driver){ + $class = self::getNamespacePath() . $fallback . '\Driver'; + self::$instances[ $instance ] = new $class($config); + self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); + trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); + }else{ + throw new phpFastCacheInvalidConfigurationException('The fallback driver cannot be the same than the default driver', 0, $e); + } + }catch (phpFastCacheInvalidArgumentException $e){ + throw new phpFastCacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e); + } }else{ throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e); }