mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Simplify exception handling for Framework Cache classses
This commit is contained in:
parent
042d4a4603
commit
627a1510dc
|
|
@ -33,11 +33,15 @@ class ChainCache extends AbstractCache
|
|||
* Chain Cache constructor.
|
||||
* @param array $caches
|
||||
* @param null|int|DateInterval $defaultLifetime
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException|InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $caches, $defaultLifetime = null)
|
||||
{
|
||||
parent::__construct('', $defaultLifetime);
|
||||
try {
|
||||
parent::__construct('', $defaultLifetime);
|
||||
} catch (\Psr\SimpleCache\InvalidArgumentException $e) {
|
||||
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
if (!$caches) {
|
||||
throw new InvalidArgumentException('At least one cache must be specified');
|
||||
|
|
|
|||
|
|
@ -29,12 +29,16 @@ class DoctrineCache extends AbstractCache
|
|||
* @param CacheProvider $doctrineCache
|
||||
* @param string $namespace
|
||||
* @param null|int|DateInterval $defaultLifetime
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException|InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(CacheProvider $doctrineCache, $namespace = '', $defaultLifetime = null)
|
||||
{
|
||||
// Do not use $namespace or $defaultLifetime directly, store them with constructor and fetch with methods.
|
||||
parent::__construct($namespace, $defaultLifetime);
|
||||
try {
|
||||
parent::__construct($namespace, $defaultLifetime);
|
||||
} catch (\Psr\SimpleCache\InvalidArgumentException $e) {
|
||||
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
// Set namespace to Doctrine Cache provider if it was given.
|
||||
$namespace = $this->getNamespace();
|
||||
|
|
|
|||
|
|
@ -42,9 +42,13 @@ class FileCache extends AbstractCache
|
|||
*/
|
||||
public function __construct($namespace = '', $defaultLifetime = null, $folder = null)
|
||||
{
|
||||
parent::__construct($namespace, $defaultLifetime ?: 31557600); // = 1 year
|
||||
try {
|
||||
parent::__construct($namespace, $defaultLifetime ?: 31557600); // = 1 year
|
||||
|
||||
$this->initFileCache($namespace, $folder ?? '');
|
||||
$this->initFileCache($namespace, $folder ?? '');
|
||||
} catch (\Psr\SimpleCache\InvalidArgumentException $e) {
|
||||
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,7 +107,13 @@ class FileCache extends AbstractCache
|
|||
{
|
||||
$file = $this->getFile($key);
|
||||
|
||||
return (!file_exists($file) || @unlink($file) || !file_exists($file));
|
||||
$result = false;
|
||||
if (file_exists($file)) {
|
||||
$result = @unlink($file);
|
||||
$result &= !file_exists($file);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user