|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Koded package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mihail Binev <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* Please view the LICENSE distributed with this source code |
|
9
|
|
|
* for the full copyright and license information. |
|
10
|
|
|
* |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Koded\Caching; |
|
14
|
|
|
|
|
15
|
|
|
use Exception; |
|
16
|
|
|
use Koded\Exceptions\KodedException; |
|
17
|
|
|
use Psr\SimpleCache\InvalidArgumentException; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class CacheException extends KodedException implements InvalidArgumentException |
|
21
|
|
|
{ |
|
22
|
|
|
protected $messages = [ |
|
23
|
|
|
Cache::E_INVALID_KEY => 'The cache key is invalid, given (:type) :key', |
|
24
|
|
|
Cache::E_UNSUPPORTED_LOGGER => 'The cache logger should be NULL or an instance of :supported, given :given', |
|
25
|
|
|
Cache::E_DIRECTORY_NOT_CREATED => 'Failed to create a cache directory ":dir"', |
|
26
|
|
|
Cache::E_PHP_EXCEPTION => '[Cache Exception] :message', |
|
27
|
|
|
Cache::E_CONNECTION_ERROR => '[Cache Exception] Failed to connect the :client client', |
|
28
|
|
|
Cache::E_UNSUPPORTED_CLIENT => '[Cache Exception] Unsupported cache client :name', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
977 |
|
public static function forInvalidKey($key) |
|
32
|
|
|
{ |
|
33
|
977 |
|
return new self(Cache::E_INVALID_KEY, [':key' => var_export($key, true), ':type' => gettype($key)]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
1 |
|
public static function forUnsupportedLogger(string $supported, string $given) |
|
38
|
|
|
{ |
|
39
|
1 |
|
return new self(Cache::E_UNSUPPORTED_LOGGER, [':supported' => $supported, ':given' => $given]); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
1 |
|
public static function forCreatingDirectory(string $directory) |
|
44
|
|
|
{ |
|
45
|
1 |
|
return new self(Cache::E_DIRECTORY_NOT_CREATED, [':dir' => $directory]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
161 |
|
public static function generic(string $message, Exception $previous = null) |
|
50
|
|
|
{ |
|
51
|
161 |
|
return new self(Cache::E_PHP_EXCEPTION, [':message' => $message], $previous); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
2 |
|
public static function withConnectionErrorFor(string $clientName) |
|
56
|
|
|
{ |
|
57
|
2 |
|
return new self(Cache::E_CONNECTION_ERROR, [':client' => $clientName]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
public static function forUnsupportedClient(string $client) |
|
61
|
|
|
{ |
|
62
|
1 |
|
return new self(Cache::E_UNSUPPORTED_CLIENT, [':name' => $client]); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|