|
10 | 10 | use Tempest\Cache\Lock; |
11 | 11 | use Tempest\DateTime\DateTimeInterface; |
12 | 12 | use Tempest\DateTime\Duration; |
| 13 | +use UnitEnum; |
13 | 14 |
|
14 | 15 | final class RestrictedCache implements Cache |
15 | 16 | { |
16 | 17 | public bool $enabled; |
17 | 18 |
|
18 | 19 | public function __construct( |
19 | | - private ?string $tag = null, |
| 20 | + private null|string|UnitEnum $tag = null, |
20 | 21 | ) {} |
21 | 22 |
|
| 23 | + private function resolveTag(): ?string |
| 24 | + { |
| 25 | + return $this->tag instanceof UnitEnum ? $this->tag->name : $this->tag; |
| 26 | + } |
| 27 | + |
22 | 28 | public function lock(Stringable|string $key, null|Duration|DateTimeInterface $expiration = null, null|Stringable|string $owner = null): Lock |
23 | 29 | { |
24 | | - throw new CacheUsageWasForbidden($this->tag); |
| 30 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
25 | 31 | } |
26 | 32 |
|
27 | 33 | public function has(Stringable|string $key): bool |
28 | 34 | { |
29 | | - throw new CacheUsageWasForbidden($this->tag); |
| 35 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
30 | 36 | } |
31 | 37 |
|
32 | 38 | public function put(Stringable|string $key, mixed $value, null|Duration|DateTimeInterface $expiration = null): CacheItemInterface |
33 | 39 | { |
34 | | - throw new CacheUsageWasForbidden($this->tag); |
| 40 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
35 | 41 | } |
36 | 42 |
|
37 | 43 | public function putMany(iterable $values, null|Duration|DateTimeInterface $expiration = null): array |
38 | 44 | { |
39 | | - throw new CacheUsageWasForbidden($this->tag); |
| 45 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
40 | 46 | } |
41 | 47 |
|
42 | 48 | public function increment(Stringable|string $key, int $by = 1): int |
43 | 49 | { |
44 | | - throw new CacheUsageWasForbidden($this->tag); |
| 50 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
45 | 51 | } |
46 | 52 |
|
47 | 53 | public function decrement(Stringable|string $key, int $by = 1): int |
48 | 54 | { |
49 | | - throw new CacheUsageWasForbidden($this->tag); |
| 55 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
50 | 56 | } |
51 | 57 |
|
52 | 58 | public function get(Stringable|string $key): mixed |
53 | 59 | { |
54 | | - throw new CacheUsageWasForbidden($this->tag); |
| 60 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
55 | 61 | } |
56 | 62 |
|
57 | 63 | public function getMany(iterable $key): array |
58 | 64 | { |
59 | | - throw new CacheUsageWasForbidden($this->tag); |
| 65 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
60 | 66 | } |
61 | 67 |
|
62 | 68 | public function resolve(Stringable|string $key, Closure $callback, null|Duration|DateTimeInterface $expiration = null, ?Duration $stale = null): mixed |
63 | 69 | { |
64 | | - throw new CacheUsageWasForbidden($this->tag); |
| 70 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
65 | 71 | } |
66 | 72 |
|
67 | 73 | public function remove(Stringable|string $key): void |
68 | 74 | { |
69 | | - throw new CacheUsageWasForbidden($this->tag); |
| 75 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
70 | 76 | } |
71 | 77 |
|
72 | 78 | public function clear(): void |
73 | 79 | { |
74 | | - throw new CacheUsageWasForbidden($this->tag); |
| 80 | + throw new CacheUsageWasForbidden($this->resolveTag()); |
75 | 81 | } |
76 | 82 | } |
0 commit comments