Skip to content

Commit

Permalink
Fixed #456 // Bug of Exception workflow in cacheManager introduced in v6
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed May 12, 2017
1 parent 59665e9 commit 836db3c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/phpFastCache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class CacheManager
* @param array $config
* @return ExtendedCacheItemPoolInterface
* @throws phpFastCacheDriverCheckException
* @throws phpFastCacheInvalidConfigurationException
*/
public static function getInstance($driver = 'auto', array $config = [])
{
Expand All @@ -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);
}
Expand Down

0 comments on commit 836db3c

Please sign in to comment.