Skip to content

Commit e11e864

Browse files
authored
Merge pull request #645 from Geolim4/master
Added PhpfastcacheDriverConnectException exception in case that a driver failed to connect
2 parents 4f1c15b + ef34d0f commit e11e864

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
use Phpfastcache\Config\ConfigurationOption;
1919
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
20-
use Phpfastcache\Exceptions\{
21-
PhpfastcacheDriverCheckException, PhpfastcacheLogicException
22-
};
20+
use Phpfastcache\Exceptions\{PhpfastcacheDriverCheckException, PhpfastcacheDriverConnectException, PhpfastcacheLogicException};
2321

2422

2523
/**
@@ -61,6 +59,7 @@ trait DriverBaseTrait
6159
* @param ConfigurationOption $config
6260
* @param string $instanceId
6361
* @throws PhpfastcacheDriverCheckException
62+
* @throws PhpfastcacheDriverConnectException
6463
*/
6564
public function __construct(ConfigurationOption $config, $instanceId)
6665
{
@@ -71,7 +70,17 @@ public function __construct(ConfigurationOption $config, $instanceId)
7170
throw new PhpfastcacheDriverCheckException(\sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
7271
}
7372

74-
$this->driverConnect();
73+
try{
74+
$this->driverConnect();
75+
}catch(\Exception $e){
76+
throw new PhpfastcacheDriverConnectException(\sprintf(
77+
self::DRIVER_CONNECT_FAILURE,
78+
$this->getDriverName(),
79+
$e->getMessage(),
80+
$e->getLine() ?: 'unknown line',
81+
$e->getFile() ?: 'unknown file'
82+
));
83+
}
7584
}
7685

7786
/**

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ interface ExtendedCacheItemPoolInterface extends CacheItemPoolInterface
4545
const DRIVER_CHECK_FAILURE = '%s is not installed or is misconfigured, cannot continue.
4646
Also, please verify the suggested dependencies in composer because as of the V6, 3rd party libraries are no longer required.';
4747

48+
const DRIVER_CONNECT_FAILURE = '%s failed to connect with the following error message: "%s" line %d in %s';
49+
4850
const DRIVER_TAGS_KEY_PREFIX = '_TAG_';
4951
const DRIVER_TAGS_WRAPPER_INDEX = 'g';
5052
const DRIVER_DATA_WRAPPER_INDEX = 'd';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of phpFastCache.
5+
*
6+
* @license MIT License (MIT)
7+
*
8+
* For full copyright and license information, please see the docs/CREDITS.txt file.
9+
*
10+
* @author Khoa Bui (khoaofgod) <[email protected]> https://www.phpfastcache.com
11+
* @author Georges.L (Geolim4) <[email protected]>
12+
*
13+
*/
14+
declare(strict_types=1);
15+
16+
namespace Phpfastcache\Exceptions;
17+
18+
/**
19+
* Class PhpfastcacheDriverCheckException
20+
* @package phpFastCache\Exceptions
21+
*/
22+
class PhpfastcacheDriverConnectException extends PhpfastcacheDriverException
23+
{
24+
25+
}

0 commit comments

Comments
 (0)