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