Skip to content

Commit 836db3c

Browse files
committed
Fixed #456 // Bug of Exception workflow in cacheManager introduced in v6
1 parent 59665e9 commit 836db3c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/phpFastCache/CacheManager.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class CacheManager
171171
* @param array $config
172172
* @return ExtendedCacheItemPoolInterface
173173
* @throws phpFastCacheDriverCheckException
174+
* @throws phpFastCacheInvalidConfigurationException
174175
*/
175176
public static function getInstance($driver = 'auto', array $config = [])
176177
{
@@ -197,12 +198,20 @@ public static function getInstance($driver = 'auto', array $config = [])
197198
self::$instances[ $instance ] = new $class($config);
198199
self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
199200
}catch(phpFastCacheDriverCheckException $e){
200-
$fallback = self::standardizeDriverName($config['fallback']);
201-
if($fallback && $fallback !== $driver){
202-
$class = self::getNamespacePath() . $fallback . '\Driver';
203-
self::$instances[ $instance ] = new $class($config);
204-
self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
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);
201+
if($config['fallback']){
202+
try{
203+
$fallback = self::standardizeDriverName($config['fallback']);
204+
if($fallback !== $driver){
205+
$class = self::getNamespacePath() . $fallback . '\Driver';
206+
self::$instances[ $instance ] = new $class($config);
207+
self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
208+
trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
209+
}else{
210+
throw new phpFastCacheInvalidConfigurationException('The fallback driver cannot be the same than the default driver', 0, $e);
211+
}
212+
}catch (phpFastCacheInvalidArgumentException $e){
213+
throw new phpFastCacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e);
214+
}
206215
}else{
207216
throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
208217
}

0 commit comments

Comments
 (0)