@@ -22,40 +22,40 @@ |
||
22 | 22 | |
23 | 23 | class CacheContract |
24 | 24 | { |
25 | - protected CacheItemPoolInterface $cacheInstance; |
|
26 | - |
|
27 | - public function __construct(CacheItemPoolInterface $cacheInstance) |
|
28 | - { |
|
29 | - $this->cacheInstance = $cacheInstance; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * @throws InvalidArgumentException |
|
34 | - */ |
|
35 | - public function get(string|\Stringable $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed |
|
36 | - { |
|
37 | - $cacheItem = $this->cacheInstance->getItem((string) $cacheKey); |
|
38 | - |
|
39 | - if (!$cacheItem->isHit()) { |
|
40 | - /* |
|
25 | + protected CacheItemPoolInterface $cacheInstance; |
|
26 | + |
|
27 | + public function __construct(CacheItemPoolInterface $cacheInstance) |
|
28 | + { |
|
29 | + $this->cacheInstance = $cacheInstance; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * @throws InvalidArgumentException |
|
34 | + */ |
|
35 | + public function get(string|\Stringable $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed |
|
36 | + { |
|
37 | + $cacheItem = $this->cacheInstance->getItem((string) $cacheKey); |
|
38 | + |
|
39 | + if (!$cacheItem->isHit()) { |
|
40 | + /* |
|
41 | 41 | * Parameter $cacheItem will be available as of 8.0.6 |
42 | 42 | */ |
43 | - $cacheItem->set($callback($cacheItem)); |
|
44 | - if ($expiresAfter) { |
|
45 | - $cacheItem->expiresAfter($expiresAfter); |
|
46 | - } |
|
47 | - |
|
48 | - $this->cacheInstance->save($cacheItem); |
|
49 | - } |
|
50 | - |
|
51 | - return $cacheItem->get(); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @throws InvalidArgumentException |
|
56 | - */ |
|
57 | - public function __invoke(string $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed |
|
58 | - { |
|
59 | - return $this->get($cacheKey, $callback, $expiresAfter); |
|
60 | - } |
|
43 | + $cacheItem->set($callback($cacheItem)); |
|
44 | + if ($expiresAfter) { |
|
45 | + $cacheItem->expiresAfter($expiresAfter); |
|
46 | + } |
|
47 | + |
|
48 | + $this->cacheInstance->save($cacheItem); |
|
49 | + } |
|
50 | + |
|
51 | + return $cacheItem->get(); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @throws InvalidArgumentException |
|
56 | + */ |
|
57 | + public function __invoke(string $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed |
|
58 | + { |
|
59 | + return $this->get($cacheKey, $callback, $expiresAfter); |
|
60 | + } |
|
61 | 61 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @throws InvalidArgumentException |
34 | 34 | */ |
35 | - public function get(string|\Stringable $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed |
|
35 | + public function get(string | \Stringable $cacheKey, callable $callback, DateInterval | int $expiresAfter = null): mixed |
|
36 | 36 | { |
37 | 37 | $cacheItem = $this->cacheInstance->getItem((string) $cacheKey); |
38 | 38 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * @throws InvalidArgumentException |
56 | 56 | */ |
57 | - public function __invoke(string $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed |
|
57 | + public function __invoke(string $cacheKey, callable $callback, DateInterval | int $expiresAfter = null): mixed |
|
58 | 58 | { |
59 | 59 | return $this->get($cacheKey, $callback, $expiresAfter); |
60 | 60 | } |
@@ -24,8 +24,7 @@ |
||
24 | 24 | { |
25 | 25 | protected CacheItemPoolInterface $cacheInstance; |
26 | 26 | |
27 | - public function __construct(CacheItemPoolInterface $cacheInstance) |
|
28 | - { |
|
27 | + public function __construct(CacheItemPoolInterface $cacheInstance) { |
|
29 | 28 | $this->cacheInstance = $cacheInstance; |
30 | 29 | } |
31 | 30 |
@@ -22,113 +22,113 @@ |
||
22 | 22 | |
23 | 23 | interface ConfigurationOptionInterface extends LockableConfigurationInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * @param array<string, mixed> $parameters |
|
27 | - * ConfigurationOptionInterface constructor. |
|
28 | - */ |
|
29 | - public function __construct(array $parameters = []); |
|
30 | - |
|
31 | - /** |
|
32 | - * @return array<string, mixed> |
|
33 | - */ |
|
34 | - public function toArray(): array; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param mixed $val |
|
38 | - * @return bool |
|
39 | - */ |
|
40 | - public function isValueSerializable(mixed $val): bool; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $optionName |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function isValidOption(string $optionName): bool; |
|
47 | - |
|
48 | - /** |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public function isItemDetailedDate(): bool; |
|
52 | - |
|
53 | - /** |
|
54 | - * @param bool $itemDetailedDate |
|
55 | - * @return ConfigurationOption |
|
56 | - */ |
|
57 | - public function setItemDetailedDate(bool $itemDetailedDate): static; |
|
58 | - |
|
59 | - /** |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function isAutoTmpFallback(): bool; |
|
63 | - /** |
|
64 | - * @param bool $autoTmpFallback |
|
65 | - * @return ConfigurationOption |
|
66 | - */ |
|
67 | - public function setAutoTmpFallback(bool $autoTmpFallback): static; |
|
68 | - /** |
|
69 | - * @return int |
|
70 | - */ |
|
71 | - public function getDefaultTtl(): int; |
|
72 | - /** |
|
73 | - * @param int $defaultTtl |
|
74 | - * @return ConfigurationOption |
|
75 | - */ |
|
76 | - public function setDefaultTtl(int $defaultTtl): static; |
|
77 | - /** |
|
78 | - * @return callable|string |
|
79 | - */ |
|
80 | - public function getDefaultKeyHashFunction(): callable|string; |
|
81 | - /** |
|
82 | - * @param callable|string $defaultKeyHashFunction |
|
83 | - * @return ConfigurationOption |
|
84 | - * @throws PhpfastcacheInvalidConfigurationException |
|
85 | - */ |
|
86 | - public function setDefaultKeyHashFunction(callable|string $defaultKeyHashFunction): static; |
|
87 | - /** |
|
88 | - * @return callable|string |
|
89 | - */ |
|
90 | - public function getDefaultFileNameHashFunction(): callable|string; |
|
91 | - /** |
|
92 | - * @param callable|string $defaultFileNameHashFunction |
|
93 | - * @return ConfigurationOption |
|
94 | - * @throws PhpfastcacheInvalidConfigurationException |
|
95 | - */ |
|
96 | - public function setDefaultFileNameHashFunction(callable|string $defaultFileNameHashFunction): static; |
|
97 | - |
|
98 | - /** |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - public function getPath(): string; |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $path |
|
105 | - * @return ConfigurationOption |
|
106 | - */ |
|
107 | - public function setPath(string $path): static; |
|
108 | - |
|
109 | - /** |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isUseStaticItemCaching(): bool; |
|
113 | - |
|
114 | - /** |
|
115 | - * @param bool $useStaticItemCaching |
|
116 | - * @return ConfigurationOption |
|
117 | - */ |
|
118 | - public function setUseStaticItemCaching(bool $useStaticItemCaching): static; |
|
119 | - |
|
120 | - /** |
|
121 | - * @return object |
|
122 | - * @throws PhpfastcacheInvalidArgumentException |
|
123 | - * @throws PhpfastcacheLogicException |
|
124 | - */ |
|
125 | - public function getSuperGlobalAccessor(): object; |
|
126 | - |
|
127 | - /** |
|
128 | - * @param ?object $superGlobalAccessor |
|
129 | - * @return static |
|
130 | - * @throws PhpfastcacheInvalidArgumentException |
|
131 | - * @throws PhpfastcacheLogicException |
|
132 | - */ |
|
133 | - public function setSuperGlobalAccessor(?object $superGlobalAccessor): static; |
|
25 | + /** |
|
26 | + * @param array<string, mixed> $parameters |
|
27 | + * ConfigurationOptionInterface constructor. |
|
28 | + */ |
|
29 | + public function __construct(array $parameters = []); |
|
30 | + |
|
31 | + /** |
|
32 | + * @return array<string, mixed> |
|
33 | + */ |
|
34 | + public function toArray(): array; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param mixed $val |
|
38 | + * @return bool |
|
39 | + */ |
|
40 | + public function isValueSerializable(mixed $val): bool; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $optionName |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function isValidOption(string $optionName): bool; |
|
47 | + |
|
48 | + /** |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public function isItemDetailedDate(): bool; |
|
52 | + |
|
53 | + /** |
|
54 | + * @param bool $itemDetailedDate |
|
55 | + * @return ConfigurationOption |
|
56 | + */ |
|
57 | + public function setItemDetailedDate(bool $itemDetailedDate): static; |
|
58 | + |
|
59 | + /** |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function isAutoTmpFallback(): bool; |
|
63 | + /** |
|
64 | + * @param bool $autoTmpFallback |
|
65 | + * @return ConfigurationOption |
|
66 | + */ |
|
67 | + public function setAutoTmpFallback(bool $autoTmpFallback): static; |
|
68 | + /** |
|
69 | + * @return int |
|
70 | + */ |
|
71 | + public function getDefaultTtl(): int; |
|
72 | + /** |
|
73 | + * @param int $defaultTtl |
|
74 | + * @return ConfigurationOption |
|
75 | + */ |
|
76 | + public function setDefaultTtl(int $defaultTtl): static; |
|
77 | + /** |
|
78 | + * @return callable|string |
|
79 | + */ |
|
80 | + public function getDefaultKeyHashFunction(): callable|string; |
|
81 | + /** |
|
82 | + * @param callable|string $defaultKeyHashFunction |
|
83 | + * @return ConfigurationOption |
|
84 | + * @throws PhpfastcacheInvalidConfigurationException |
|
85 | + */ |
|
86 | + public function setDefaultKeyHashFunction(callable|string $defaultKeyHashFunction): static; |
|
87 | + /** |
|
88 | + * @return callable|string |
|
89 | + */ |
|
90 | + public function getDefaultFileNameHashFunction(): callable|string; |
|
91 | + /** |
|
92 | + * @param callable|string $defaultFileNameHashFunction |
|
93 | + * @return ConfigurationOption |
|
94 | + * @throws PhpfastcacheInvalidConfigurationException |
|
95 | + */ |
|
96 | + public function setDefaultFileNameHashFunction(callable|string $defaultFileNameHashFunction): static; |
|
97 | + |
|
98 | + /** |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + public function getPath(): string; |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $path |
|
105 | + * @return ConfigurationOption |
|
106 | + */ |
|
107 | + public function setPath(string $path): static; |
|
108 | + |
|
109 | + /** |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isUseStaticItemCaching(): bool; |
|
113 | + |
|
114 | + /** |
|
115 | + * @param bool $useStaticItemCaching |
|
116 | + * @return ConfigurationOption |
|
117 | + */ |
|
118 | + public function setUseStaticItemCaching(bool $useStaticItemCaching): static; |
|
119 | + |
|
120 | + /** |
|
121 | + * @return object |
|
122 | + * @throws PhpfastcacheInvalidArgumentException |
|
123 | + * @throws PhpfastcacheLogicException |
|
124 | + */ |
|
125 | + public function getSuperGlobalAccessor(): object; |
|
126 | + |
|
127 | + /** |
|
128 | + * @param ?object $superGlobalAccessor |
|
129 | + * @return static |
|
130 | + * @throws PhpfastcacheInvalidArgumentException |
|
131 | + * @throws PhpfastcacheLogicException |
|
132 | + */ |
|
133 | + public function setSuperGlobalAccessor(?object $superGlobalAccessor): static; |
|
134 | 134 | } |
@@ -77,23 +77,23 @@ |
||
77 | 77 | /** |
78 | 78 | * @return callable|string |
79 | 79 | */ |
80 | - public function getDefaultKeyHashFunction(): callable|string; |
|
80 | + public function getDefaultKeyHashFunction(): callable | string; |
|
81 | 81 | /** |
82 | 82 | * @param callable|string $defaultKeyHashFunction |
83 | 83 | * @return ConfigurationOption |
84 | 84 | * @throws PhpfastcacheInvalidConfigurationException |
85 | 85 | */ |
86 | - public function setDefaultKeyHashFunction(callable|string $defaultKeyHashFunction): static; |
|
86 | + public function setDefaultKeyHashFunction(callable | string $defaultKeyHashFunction): static; |
|
87 | 87 | /** |
88 | 88 | * @return callable|string |
89 | 89 | */ |
90 | - public function getDefaultFileNameHashFunction(): callable|string; |
|
90 | + public function getDefaultFileNameHashFunction(): callable | string; |
|
91 | 91 | /** |
92 | 92 | * @param callable|string $defaultFileNameHashFunction |
93 | 93 | * @return ConfigurationOption |
94 | 94 | * @throws PhpfastcacheInvalidConfigurationException |
95 | 95 | */ |
96 | - public function setDefaultFileNameHashFunction(callable|string $defaultFileNameHashFunction): static; |
|
96 | + public function setDefaultFileNameHashFunction(callable | string $defaultFileNameHashFunction): static; |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @return string |
@@ -20,12 +20,12 @@ |
||
20 | 20 | |
21 | 21 | interface LockableConfigurationInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * @internal |
|
25 | - */ |
|
26 | - public function lock(ExtendedCacheItemPoolInterface $poolInstance): static; |
|
23 | + /** |
|
24 | + * @internal |
|
25 | + */ |
|
26 | + public function lock(ExtendedCacheItemPoolInterface $poolInstance): static; |
|
27 | 27 | |
28 | - public function lockedBy(): ExtendedCacheItemPoolInterface; |
|
28 | + public function lockedBy(): ExtendedCacheItemPoolInterface; |
|
29 | 29 | |
30 | - public function isLocked(): bool; |
|
30 | + public function isLocked(): bool; |
|
31 | 31 | } |
@@ -23,347 +23,347 @@ |
||
23 | 23 | |
24 | 24 | class ConfigurationOption extends AbstractConfigurationOption implements ConfigurationOptionInterface |
25 | 25 | { |
26 | - protected bool $itemDetailedDate = false; |
|
27 | - |
|
28 | - protected bool $autoTmpFallback = false; |
|
29 | - |
|
30 | - protected int $defaultTtl = 900; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string|callable |
|
34 | - */ |
|
35 | - protected mixed $defaultKeyHashFunction = 'md5'; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string|callable |
|
39 | - */ |
|
40 | - protected mixed $defaultFileNameHashFunction = 'md5'; |
|
41 | - |
|
42 | - protected string $path = ''; |
|
43 | - |
|
44 | - protected bool $preventCacheSlams = false; |
|
45 | - |
|
46 | - protected int $cacheSlamsTimeout = 15; |
|
47 | - |
|
48 | - protected bool $useStaticItemCaching = true; |
|
49 | - |
|
50 | - protected ?object $superGlobalAccessor = null; |
|
51 | - |
|
52 | - /** |
|
53 | - * @inheritDoc |
|
54 | - * @throws PhpfastcacheInvalidConfigurationException |
|
55 | - * @throws PhpfastcacheInvalidTypeException |
|
56 | - */ |
|
57 | - public function __construct(array $parameters = []) |
|
58 | - { |
|
59 | - foreach ($parameters as $configKey => $configVal) { |
|
60 | - try { |
|
61 | - if (\property_exists($this, $configKey)) { |
|
62 | - $this->{'set' . \ucfirst($configKey)}($configVal); |
|
63 | - } else { |
|
64 | - throw new PhpfastcacheInvalidConfigurationException( |
|
65 | - sprintf( |
|
66 | - 'Unknown configuration option name "%s" for the config class "%s". Allowed configurations options are "%s"', |
|
67 | - $configKey, |
|
68 | - $this::class, |
|
69 | - \implode('", "', \array_keys($this->toArray())), |
|
70 | - ) |
|
71 | - ); |
|
72 | - } |
|
73 | - } catch (\TypeError $e) { |
|
74 | - throw new PhpfastcacheInvalidTypeException( |
|
75 | - \sprintf( |
|
76 | - 'TypeError exception thrown while trying to set your configuration: %s', |
|
77 | - $e->getMessage() |
|
78 | - ) |
|
79 | - ); |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - public function toArray(): array |
|
85 | - { |
|
86 | - return \get_object_vars($this); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @throws \ReflectionException |
|
91 | - */ |
|
92 | - public function isValueSerializable(mixed $val): bool |
|
93 | - { |
|
94 | - return !\is_callable($val) && !(is_object($val) && (new \ReflectionClass($val))->isAnonymous()); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $optionName |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function isValidOption(string $optionName): bool |
|
102 | - { |
|
103 | - return \property_exists($this, $optionName); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - public function isItemDetailedDate(): bool |
|
110 | - { |
|
111 | - return $this->itemDetailedDate; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param bool $itemDetailedDate |
|
116 | - * @return ConfigurationOption |
|
117 | - * @throws PhpfastcacheLogicException |
|
118 | - */ |
|
119 | - public function setItemDetailedDate(bool $itemDetailedDate): static |
|
120 | - { |
|
121 | - $this->enforceLockedProperty(__FUNCTION__); |
|
122 | - $this->itemDetailedDate = $itemDetailedDate; |
|
123 | - return $this; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return bool |
|
128 | - */ |
|
129 | - public function isAutoTmpFallback(): bool |
|
130 | - { |
|
131 | - return $this->autoTmpFallback; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @param bool $autoTmpFallback |
|
136 | - * @return ConfigurationOption |
|
137 | - * @throws PhpfastcacheLogicException |
|
138 | - */ |
|
139 | - public function setAutoTmpFallback(bool $autoTmpFallback): static |
|
140 | - { |
|
141 | - $this->enforceLockedProperty(__FUNCTION__); |
|
142 | - $this->autoTmpFallback = $autoTmpFallback; |
|
143 | - return $this; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return int |
|
148 | - */ |
|
149 | - public function getDefaultTtl(): int |
|
150 | - { |
|
151 | - return $this->defaultTtl; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * @param int $defaultTtl |
|
156 | - * @return ConfigurationOption |
|
157 | - * @throws PhpfastcacheLogicException |
|
158 | - */ |
|
159 | - public function setDefaultTtl(int $defaultTtl): static |
|
160 | - { |
|
161 | - $this->enforceLockedProperty(__FUNCTION__); |
|
162 | - $this->defaultTtl = $defaultTtl; |
|
163 | - return $this; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return callable|string |
|
168 | - */ |
|
169 | - public function getDefaultKeyHashFunction(): callable|string |
|
170 | - { |
|
171 | - return $this->defaultKeyHashFunction; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param callable|string $defaultKeyHashFunction |
|
176 | - * @return ConfigurationOption |
|
177 | - * @throws PhpfastcacheInvalidConfigurationException |
|
178 | - * @throws PhpfastcacheLogicException |
|
179 | - */ |
|
180 | - public function setDefaultKeyHashFunction(callable|string $defaultKeyHashFunction): static |
|
181 | - { |
|
182 | - $this->enforceLockedProperty(__FUNCTION__); |
|
183 | - if ($defaultKeyHashFunction && !\is_callable($defaultKeyHashFunction) && (\is_string($defaultKeyHashFunction) && !\function_exists($defaultKeyHashFunction))) { |
|
184 | - throw new PhpfastcacheInvalidConfigurationException('defaultKeyHashFunction must be a valid function name string'); |
|
185 | - } |
|
186 | - $this->defaultKeyHashFunction = $defaultKeyHashFunction; |
|
187 | - return $this; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @return callable|string |
|
192 | - */ |
|
193 | - public function getDefaultFileNameHashFunction(): callable|string |
|
194 | - { |
|
195 | - return $this->defaultFileNameHashFunction; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @param callable|string $defaultFileNameHashFunction |
|
200 | - * @return ConfigurationOption |
|
201 | - * @throws PhpfastcacheInvalidConfigurationException |
|
202 | - * @throws PhpfastcacheLogicException |
|
203 | - */ |
|
204 | - public function setDefaultFileNameHashFunction(callable|string $defaultFileNameHashFunction): static |
|
205 | - { |
|
206 | - $this->enforceLockedProperty(__FUNCTION__); |
|
207 | - if (!\is_callable($defaultFileNameHashFunction) && (\is_string($defaultFileNameHashFunction) && !\function_exists($defaultFileNameHashFunction))) { |
|
208 | - throw new PhpfastcacheInvalidConfigurationException('defaultFileNameHashFunction must be a valid function name string'); |
|
209 | - } |
|
210 | - $this->defaultFileNameHashFunction = $defaultFileNameHashFunction; |
|
211 | - return $this; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - public function getPath(): string |
|
218 | - { |
|
219 | - return $this->path; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @param string $path |
|
224 | - * @return ConfigurationOption |
|
225 | - * @throws PhpfastcacheLogicException |
|
226 | - */ |
|
227 | - public function setPath(string $path): static |
|
228 | - { |
|
229 | - $this->enforceLockedProperty(__FUNCTION__); |
|
230 | - $this->path = $path; |
|
231 | - return $this; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - public function isPreventCacheSlams(): bool |
|
239 | - { |
|
240 | - return $this->preventCacheSlams; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
245 | - * @param bool $preventCacheSlams |
|
246 | - * @return ConfigurationOption |
|
247 | - * @throws PhpfastcacheLogicException |
|
248 | - */ |
|
249 | - public function setPreventCacheSlams(bool $preventCacheSlams): static |
|
250 | - { |
|
251 | - if ($preventCacheSlams !== $this->preventCacheSlams) { |
|
252 | - trigger_error( |
|
253 | - 'This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers.', |
|
254 | - E_USER_DEPRECATED |
|
255 | - ); |
|
256 | - } |
|
257 | - |
|
258 | - $this->enforceLockedProperty(__FUNCTION__); |
|
259 | - $this->preventCacheSlams = $preventCacheSlams; |
|
260 | - return $this; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
265 | - * @return int |
|
266 | - */ |
|
267 | - public function getCacheSlamsTimeout(): int |
|
268 | - { |
|
269 | - return $this->cacheSlamsTimeout; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
274 | - * @param int $cacheSlamsTimeout |
|
275 | - * @return ConfigurationOption |
|
276 | - * @throws PhpfastcacheLogicException |
|
277 | - */ |
|
278 | - public function setCacheSlamsTimeout(int $cacheSlamsTimeout): static |
|
279 | - { |
|
280 | - if ($cacheSlamsTimeout !== $this->cacheSlamsTimeout) { |
|
281 | - trigger_error( |
|
282 | - 'This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers.', |
|
283 | - E_USER_DEPRECATED |
|
284 | - ); |
|
285 | - } |
|
286 | - $this->enforceLockedProperty(__FUNCTION__); |
|
287 | - $this->cacheSlamsTimeout = $cacheSlamsTimeout; |
|
288 | - return $this; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * @return bool |
|
293 | - */ |
|
294 | - public function isUseStaticItemCaching(): bool |
|
295 | - { |
|
296 | - return $this->useStaticItemCaching; |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * @param bool $useStaticItemCaching |
|
301 | - * @return ConfigurationOption |
|
302 | - * @throws PhpfastcacheLogicException |
|
303 | - */ |
|
304 | - public function setUseStaticItemCaching(bool $useStaticItemCaching): static |
|
305 | - { |
|
306 | - $this->enforceLockedProperty(__FUNCTION__); |
|
307 | - $this->useStaticItemCaching = $useStaticItemCaching; |
|
308 | - return $this; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @return object |
|
313 | - */ |
|
314 | - public function getSuperGlobalAccessor(): object |
|
315 | - { |
|
316 | - if (!isset($this->superGlobalAccessor)) { |
|
317 | - $this->superGlobalAccessor = $this->getDefaultSuperGlobalAccessor(); |
|
318 | - } |
|
319 | - |
|
320 | - return $this->superGlobalAccessor; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @param ?object $superGlobalAccessor |
|
325 | - * @return static |
|
326 | - * @throws PhpfastcacheInvalidArgumentException |
|
327 | - * @throws PhpfastcacheLogicException |
|
328 | - */ |
|
329 | - public function setSuperGlobalAccessor(?object $superGlobalAccessor): static |
|
330 | - { |
|
331 | - $this->enforceLockedProperty(__FUNCTION__); |
|
332 | - /** |
|
333 | - * Symfony's implementation for users that want a good control of their code: |
|
334 | - * |
|
335 | - * $config['superGlobalAccessor'] = \Closure::fromCallable(static function(string $superGlobalName, string $keyName) use ($request) { |
|
336 | - * return match ($superGlobalName) { |
|
337 | - * 'SERVER' => $request->server->get($keyName), |
|
338 | - * 'REQUEST' => $request->request->get($keyName), |
|
339 | - * }; |
|
340 | - * }); |
|
341 | - */ |
|
342 | - |
|
343 | - if ($superGlobalAccessor === null) { |
|
344 | - $this->superGlobalAccessor = $this->getDefaultSuperGlobalAccessor(); |
|
345 | - } elseif (!\is_callable($superGlobalAccessor)) { |
|
346 | - throw new PhpfastcacheInvalidArgumentException('The "superGlobalAccessor" callback must be callable using "__invoke" or \Closure implementation'); |
|
347 | - } else { |
|
348 | - $this->superGlobalAccessor = $superGlobalAccessor; |
|
349 | - } |
|
350 | - |
|
351 | - return $this; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * @return \Closure |
|
356 | - * @SuppressWarnings(PHPMD.Superglobals) |
|
357 | - */ |
|
358 | - protected function getDefaultSuperGlobalAccessor(): \Closure |
|
359 | - { |
|
360 | - return \Closure::fromCallable(static function (string $superGlobalName, ?string $keyName = null): string|int|float|array|bool|null { |
|
361 | - return match ($superGlobalName) { |
|
362 | - 'SERVER' => $keyName !== null ? $_SERVER[$keyName] ?? null : $_SERVER, |
|
363 | - 'REQUEST' => $keyName !== null ? $_REQUEST[$keyName] ?? null : $_REQUEST, |
|
364 | - 'COOKIE' => $keyName !== null ? $_COOKIE[$keyName] ?? null : $_COOKIE, |
|
365 | - default => null, |
|
366 | - }; |
|
367 | - }); |
|
368 | - } |
|
26 | + protected bool $itemDetailedDate = false; |
|
27 | + |
|
28 | + protected bool $autoTmpFallback = false; |
|
29 | + |
|
30 | + protected int $defaultTtl = 900; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string|callable |
|
34 | + */ |
|
35 | + protected mixed $defaultKeyHashFunction = 'md5'; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string|callable |
|
39 | + */ |
|
40 | + protected mixed $defaultFileNameHashFunction = 'md5'; |
|
41 | + |
|
42 | + protected string $path = ''; |
|
43 | + |
|
44 | + protected bool $preventCacheSlams = false; |
|
45 | + |
|
46 | + protected int $cacheSlamsTimeout = 15; |
|
47 | + |
|
48 | + protected bool $useStaticItemCaching = true; |
|
49 | + |
|
50 | + protected ?object $superGlobalAccessor = null; |
|
51 | + |
|
52 | + /** |
|
53 | + * @inheritDoc |
|
54 | + * @throws PhpfastcacheInvalidConfigurationException |
|
55 | + * @throws PhpfastcacheInvalidTypeException |
|
56 | + */ |
|
57 | + public function __construct(array $parameters = []) |
|
58 | + { |
|
59 | + foreach ($parameters as $configKey => $configVal) { |
|
60 | + try { |
|
61 | + if (\property_exists($this, $configKey)) { |
|
62 | + $this->{'set' . \ucfirst($configKey)}($configVal); |
|
63 | + } else { |
|
64 | + throw new PhpfastcacheInvalidConfigurationException( |
|
65 | + sprintf( |
|
66 | + 'Unknown configuration option name "%s" for the config class "%s". Allowed configurations options are "%s"', |
|
67 | + $configKey, |
|
68 | + $this::class, |
|
69 | + \implode('", "', \array_keys($this->toArray())), |
|
70 | + ) |
|
71 | + ); |
|
72 | + } |
|
73 | + } catch (\TypeError $e) { |
|
74 | + throw new PhpfastcacheInvalidTypeException( |
|
75 | + \sprintf( |
|
76 | + 'TypeError exception thrown while trying to set your configuration: %s', |
|
77 | + $e->getMessage() |
|
78 | + ) |
|
79 | + ); |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + public function toArray(): array |
|
85 | + { |
|
86 | + return \get_object_vars($this); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @throws \ReflectionException |
|
91 | + */ |
|
92 | + public function isValueSerializable(mixed $val): bool |
|
93 | + { |
|
94 | + return !\is_callable($val) && !(is_object($val) && (new \ReflectionClass($val))->isAnonymous()); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $optionName |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function isValidOption(string $optionName): bool |
|
102 | + { |
|
103 | + return \property_exists($this, $optionName); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + public function isItemDetailedDate(): bool |
|
110 | + { |
|
111 | + return $this->itemDetailedDate; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param bool $itemDetailedDate |
|
116 | + * @return ConfigurationOption |
|
117 | + * @throws PhpfastcacheLogicException |
|
118 | + */ |
|
119 | + public function setItemDetailedDate(bool $itemDetailedDate): static |
|
120 | + { |
|
121 | + $this->enforceLockedProperty(__FUNCTION__); |
|
122 | + $this->itemDetailedDate = $itemDetailedDate; |
|
123 | + return $this; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return bool |
|
128 | + */ |
|
129 | + public function isAutoTmpFallback(): bool |
|
130 | + { |
|
131 | + return $this->autoTmpFallback; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @param bool $autoTmpFallback |
|
136 | + * @return ConfigurationOption |
|
137 | + * @throws PhpfastcacheLogicException |
|
138 | + */ |
|
139 | + public function setAutoTmpFallback(bool $autoTmpFallback): static |
|
140 | + { |
|
141 | + $this->enforceLockedProperty(__FUNCTION__); |
|
142 | + $this->autoTmpFallback = $autoTmpFallback; |
|
143 | + return $this; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return int |
|
148 | + */ |
|
149 | + public function getDefaultTtl(): int |
|
150 | + { |
|
151 | + return $this->defaultTtl; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * @param int $defaultTtl |
|
156 | + * @return ConfigurationOption |
|
157 | + * @throws PhpfastcacheLogicException |
|
158 | + */ |
|
159 | + public function setDefaultTtl(int $defaultTtl): static |
|
160 | + { |
|
161 | + $this->enforceLockedProperty(__FUNCTION__); |
|
162 | + $this->defaultTtl = $defaultTtl; |
|
163 | + return $this; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return callable|string |
|
168 | + */ |
|
169 | + public function getDefaultKeyHashFunction(): callable|string |
|
170 | + { |
|
171 | + return $this->defaultKeyHashFunction; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param callable|string $defaultKeyHashFunction |
|
176 | + * @return ConfigurationOption |
|
177 | + * @throws PhpfastcacheInvalidConfigurationException |
|
178 | + * @throws PhpfastcacheLogicException |
|
179 | + */ |
|
180 | + public function setDefaultKeyHashFunction(callable|string $defaultKeyHashFunction): static |
|
181 | + { |
|
182 | + $this->enforceLockedProperty(__FUNCTION__); |
|
183 | + if ($defaultKeyHashFunction && !\is_callable($defaultKeyHashFunction) && (\is_string($defaultKeyHashFunction) && !\function_exists($defaultKeyHashFunction))) { |
|
184 | + throw new PhpfastcacheInvalidConfigurationException('defaultKeyHashFunction must be a valid function name string'); |
|
185 | + } |
|
186 | + $this->defaultKeyHashFunction = $defaultKeyHashFunction; |
|
187 | + return $this; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @return callable|string |
|
192 | + */ |
|
193 | + public function getDefaultFileNameHashFunction(): callable|string |
|
194 | + { |
|
195 | + return $this->defaultFileNameHashFunction; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @param callable|string $defaultFileNameHashFunction |
|
200 | + * @return ConfigurationOption |
|
201 | + * @throws PhpfastcacheInvalidConfigurationException |
|
202 | + * @throws PhpfastcacheLogicException |
|
203 | + */ |
|
204 | + public function setDefaultFileNameHashFunction(callable|string $defaultFileNameHashFunction): static |
|
205 | + { |
|
206 | + $this->enforceLockedProperty(__FUNCTION__); |
|
207 | + if (!\is_callable($defaultFileNameHashFunction) && (\is_string($defaultFileNameHashFunction) && !\function_exists($defaultFileNameHashFunction))) { |
|
208 | + throw new PhpfastcacheInvalidConfigurationException('defaultFileNameHashFunction must be a valid function name string'); |
|
209 | + } |
|
210 | + $this->defaultFileNameHashFunction = $defaultFileNameHashFunction; |
|
211 | + return $this; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + public function getPath(): string |
|
218 | + { |
|
219 | + return $this->path; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @param string $path |
|
224 | + * @return ConfigurationOption |
|
225 | + * @throws PhpfastcacheLogicException |
|
226 | + */ |
|
227 | + public function setPath(string $path): static |
|
228 | + { |
|
229 | + $this->enforceLockedProperty(__FUNCTION__); |
|
230 | + $this->path = $path; |
|
231 | + return $this; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + public function isPreventCacheSlams(): bool |
|
239 | + { |
|
240 | + return $this->preventCacheSlams; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
245 | + * @param bool $preventCacheSlams |
|
246 | + * @return ConfigurationOption |
|
247 | + * @throws PhpfastcacheLogicException |
|
248 | + */ |
|
249 | + public function setPreventCacheSlams(bool $preventCacheSlams): static |
|
250 | + { |
|
251 | + if ($preventCacheSlams !== $this->preventCacheSlams) { |
|
252 | + trigger_error( |
|
253 | + 'This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers.', |
|
254 | + E_USER_DEPRECATED |
|
255 | + ); |
|
256 | + } |
|
257 | + |
|
258 | + $this->enforceLockedProperty(__FUNCTION__); |
|
259 | + $this->preventCacheSlams = $preventCacheSlams; |
|
260 | + return $this; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
265 | + * @return int |
|
266 | + */ |
|
267 | + public function getCacheSlamsTimeout(): int |
|
268 | + { |
|
269 | + return $this->cacheSlamsTimeout; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @deprecated This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers. |
|
274 | + * @param int $cacheSlamsTimeout |
|
275 | + * @return ConfigurationOption |
|
276 | + * @throws PhpfastcacheLogicException |
|
277 | + */ |
|
278 | + public function setCacheSlamsTimeout(int $cacheSlamsTimeout): static |
|
279 | + { |
|
280 | + if ($cacheSlamsTimeout !== $this->cacheSlamsTimeout) { |
|
281 | + trigger_error( |
|
282 | + 'This method is deprecated and will be soon moved to IOConfigurationOption class, which means they will only be available for `IO` drivers.', |
|
283 | + E_USER_DEPRECATED |
|
284 | + ); |
|
285 | + } |
|
286 | + $this->enforceLockedProperty(__FUNCTION__); |
|
287 | + $this->cacheSlamsTimeout = $cacheSlamsTimeout; |
|
288 | + return $this; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * @return bool |
|
293 | + */ |
|
294 | + public function isUseStaticItemCaching(): bool |
|
295 | + { |
|
296 | + return $this->useStaticItemCaching; |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * @param bool $useStaticItemCaching |
|
301 | + * @return ConfigurationOption |
|
302 | + * @throws PhpfastcacheLogicException |
|
303 | + */ |
|
304 | + public function setUseStaticItemCaching(bool $useStaticItemCaching): static |
|
305 | + { |
|
306 | + $this->enforceLockedProperty(__FUNCTION__); |
|
307 | + $this->useStaticItemCaching = $useStaticItemCaching; |
|
308 | + return $this; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @return object |
|
313 | + */ |
|
314 | + public function getSuperGlobalAccessor(): object |
|
315 | + { |
|
316 | + if (!isset($this->superGlobalAccessor)) { |
|
317 | + $this->superGlobalAccessor = $this->getDefaultSuperGlobalAccessor(); |
|
318 | + } |
|
319 | + |
|
320 | + return $this->superGlobalAccessor; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @param ?object $superGlobalAccessor |
|
325 | + * @return static |
|
326 | + * @throws PhpfastcacheInvalidArgumentException |
|
327 | + * @throws PhpfastcacheLogicException |
|
328 | + */ |
|
329 | + public function setSuperGlobalAccessor(?object $superGlobalAccessor): static |
|
330 | + { |
|
331 | + $this->enforceLockedProperty(__FUNCTION__); |
|
332 | + /** |
|
333 | + * Symfony's implementation for users that want a good control of their code: |
|
334 | + * |
|
335 | + * $config['superGlobalAccessor'] = \Closure::fromCallable(static function(string $superGlobalName, string $keyName) use ($request) { |
|
336 | + * return match ($superGlobalName) { |
|
337 | + * 'SERVER' => $request->server->get($keyName), |
|
338 | + * 'REQUEST' => $request->request->get($keyName), |
|
339 | + * }; |
|
340 | + * }); |
|
341 | + */ |
|
342 | + |
|
343 | + if ($superGlobalAccessor === null) { |
|
344 | + $this->superGlobalAccessor = $this->getDefaultSuperGlobalAccessor(); |
|
345 | + } elseif (!\is_callable($superGlobalAccessor)) { |
|
346 | + throw new PhpfastcacheInvalidArgumentException('The "superGlobalAccessor" callback must be callable using "__invoke" or \Closure implementation'); |
|
347 | + } else { |
|
348 | + $this->superGlobalAccessor = $superGlobalAccessor; |
|
349 | + } |
|
350 | + |
|
351 | + return $this; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * @return \Closure |
|
356 | + * @SuppressWarnings(PHPMD.Superglobals) |
|
357 | + */ |
|
358 | + protected function getDefaultSuperGlobalAccessor(): \Closure |
|
359 | + { |
|
360 | + return \Closure::fromCallable(static function (string $superGlobalName, ?string $keyName = null): string|int|float|array|bool|null { |
|
361 | + return match ($superGlobalName) { |
|
362 | + 'SERVER' => $keyName !== null ? $_SERVER[$keyName] ?? null : $_SERVER, |
|
363 | + 'REQUEST' => $keyName !== null ? $_REQUEST[$keyName] ?? null : $_REQUEST, |
|
364 | + 'COOKIE' => $keyName !== null ? $_COOKIE[$keyName] ?? null : $_COOKIE, |
|
365 | + default => null, |
|
366 | + }; |
|
367 | + }); |
|
368 | + } |
|
369 | 369 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | /** |
167 | 167 | * @return callable|string |
168 | 168 | */ |
169 | - public function getDefaultKeyHashFunction(): callable|string |
|
169 | + public function getDefaultKeyHashFunction(): callable | string |
|
170 | 170 | { |
171 | 171 | return $this->defaultKeyHashFunction; |
172 | 172 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @throws PhpfastcacheInvalidConfigurationException |
178 | 178 | * @throws PhpfastcacheLogicException |
179 | 179 | */ |
180 | - public function setDefaultKeyHashFunction(callable|string $defaultKeyHashFunction): static |
|
180 | + public function setDefaultKeyHashFunction(callable | string $defaultKeyHashFunction): static |
|
181 | 181 | { |
182 | 182 | $this->enforceLockedProperty(__FUNCTION__); |
183 | 183 | if ($defaultKeyHashFunction && !\is_callable($defaultKeyHashFunction) && (\is_string($defaultKeyHashFunction) && !\function_exists($defaultKeyHashFunction))) { |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | /** |
191 | 191 | * @return callable|string |
192 | 192 | */ |
193 | - public function getDefaultFileNameHashFunction(): callable|string |
|
193 | + public function getDefaultFileNameHashFunction(): callable | string |
|
194 | 194 | { |
195 | 195 | return $this->defaultFileNameHashFunction; |
196 | 196 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @throws PhpfastcacheInvalidConfigurationException |
202 | 202 | * @throws PhpfastcacheLogicException |
203 | 203 | */ |
204 | - public function setDefaultFileNameHashFunction(callable|string $defaultFileNameHashFunction): static |
|
204 | + public function setDefaultFileNameHashFunction(callable | string $defaultFileNameHashFunction): static |
|
205 | 205 | { |
206 | 206 | $this->enforceLockedProperty(__FUNCTION__); |
207 | 207 | if (!\is_callable($defaultFileNameHashFunction) && (\is_string($defaultFileNameHashFunction) && !\function_exists($defaultFileNameHashFunction))) { |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | */ |
358 | 358 | protected function getDefaultSuperGlobalAccessor(): \Closure |
359 | 359 | { |
360 | - return \Closure::fromCallable(static function (string $superGlobalName, ?string $keyName = null): string|int|float|array|bool|null { |
|
360 | + return \Closure::fromCallable(static function(string $superGlobalName, ?string $keyName = null): string | int | float | array | bool | null { |
|
361 | 361 | return match ($superGlobalName) { |
362 | 362 | 'SERVER' => $keyName !== null ? $_SERVER[$keyName] ?? null : $_SERVER, |
363 | 363 | 'REQUEST' => $keyName !== null ? $_REQUEST[$keyName] ?? null : $_REQUEST, |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | * @throws PhpfastcacheInvalidConfigurationException |
55 | 55 | * @throws PhpfastcacheInvalidTypeException |
56 | 56 | */ |
57 | - public function __construct(array $parameters = []) |
|
58 | - { |
|
57 | + public function __construct(array $parameters = []) { |
|
59 | 58 | foreach ($parameters as $configKey => $configVal) { |
60 | 59 | try { |
61 | 60 | if (\property_exists($this, $configKey)) { |
62 | 61 | $this->{'set' . \ucfirst($configKey)}($configVal); |
63 | - } else { |
|
62 | + } |
|
63 | + else { |
|
64 | 64 | throw new PhpfastcacheInvalidConfigurationException( |
65 | 65 | sprintf( |
66 | 66 | 'Unknown configuration option name "%s" for the config class "%s". Allowed configurations options are "%s"', |
@@ -70,7 +70,8 @@ discard block |
||
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | } |
73 | - } catch (\TypeError $e) { |
|
73 | + } |
|
74 | + catch (\TypeError $e) { |
|
74 | 75 | throw new PhpfastcacheInvalidTypeException( |
75 | 76 | \sprintf( |
76 | 77 | 'TypeError exception thrown while trying to set your configuration: %s', |
@@ -342,9 +343,11 @@ discard block |
||
342 | 343 | |
343 | 344 | if ($superGlobalAccessor === null) { |
344 | 345 | $this->superGlobalAccessor = $this->getDefaultSuperGlobalAccessor(); |
345 | - } elseif (!\is_callable($superGlobalAccessor)) { |
|
346 | + } |
|
347 | + elseif (!\is_callable($superGlobalAccessor)) { |
|
346 | 348 | throw new PhpfastcacheInvalidArgumentException('The "superGlobalAccessor" callback must be callable using "__invoke" or \Closure implementation'); |
347 | - } else { |
|
349 | + } |
|
350 | + else { |
|
348 | 351 | $this->superGlobalAccessor = $superGlobalAccessor; |
349 | 352 | } |
350 | 353 |
@@ -24,133 +24,133 @@ |
||
24 | 24 | */ |
25 | 25 | class IOConfigurationOption extends ConfigurationOption |
26 | 26 | { |
27 | - protected bool $secureFileManipulation = false; |
|
28 | - |
|
29 | - protected string $securityKey = ''; |
|
30 | - |
|
31 | - protected string $cacheFileExtension = 'txt'; |
|
32 | - |
|
33 | - protected int $defaultChmod = 0777; |
|
34 | - |
|
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getSecurityKey(): string |
|
39 | - { |
|
40 | - return $this->securityKey; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $securityKey |
|
45 | - * @return static |
|
46 | - * @throws PhpfastcacheLogicException |
|
47 | - */ |
|
48 | - public function setSecurityKey(string $securityKey): static |
|
49 | - { |
|
50 | - return $this->setProperty('securityKey', $securityKey); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function isSecureFileManipulation(): bool |
|
57 | - { |
|
58 | - return $this->secureFileManipulation; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param bool $secureFileManipulation |
|
63 | - * @return static |
|
64 | - * @throws PhpfastcacheLogicException |
|
65 | - */ |
|
66 | - public function setSecureFileManipulation(bool $secureFileManipulation): static |
|
67 | - { |
|
68 | - return $this->setProperty('secureFileManipulation', $secureFileManipulation); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function getCacheFileExtension(): string |
|
76 | - { |
|
77 | - return $this->cacheFileExtension; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param string $cacheFileExtension |
|
82 | - * @return static |
|
83 | - * @throws PhpfastcacheInvalidConfigurationException |
|
84 | - * @throws PhpfastcacheLogicException |
|
85 | - */ |
|
86 | - public function setCacheFileExtension(string $cacheFileExtension): static |
|
87 | - { |
|
88 | - $safeFileExtensions = \explode('|', IOConfigurationOptionInterface::SAFE_FILE_EXTENSIONS); |
|
89 | - |
|
90 | - if (\str_contains($cacheFileExtension, '.')) { |
|
91 | - throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."'); |
|
92 | - } |
|
93 | - if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { |
|
94 | - throw new PhpfastcacheInvalidConfigurationException( |
|
95 | - "Extension \"$cacheFileExtension\" is unsafe, currently allowed extension names: " . \implode(', ', $safeFileExtensions) |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - return $this->setProperty('cacheFileExtension', $cacheFileExtension); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function getDefaultChmod(): int |
|
106 | - { |
|
107 | - return $this->defaultChmod; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param int $defaultChmod |
|
112 | - * @return static |
|
113 | - * @throws PhpfastcacheLogicException |
|
114 | - */ |
|
115 | - public function setDefaultChmod(int $defaultChmod): static |
|
116 | - { |
|
117 | - return $this->setProperty('defaultChmod', $defaultChmod); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return bool |
|
123 | - */ |
|
124 | - public function isPreventCacheSlams(): bool |
|
125 | - { |
|
126 | - return $this->preventCacheSlams; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @param bool $preventCacheSlams |
|
131 | - * @return static |
|
132 | - * @throws PhpfastcacheLogicException |
|
133 | - */ |
|
134 | - public function setPreventCacheSlams(bool $preventCacheSlams): static |
|
135 | - { |
|
136 | - return $this->setProperty('preventCacheSlams', $preventCacheSlams); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return int |
|
141 | - */ |
|
142 | - public function getCacheSlamsTimeout(): int |
|
143 | - { |
|
144 | - return $this->cacheSlamsTimeout; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param int $cacheSlamsTimeout |
|
149 | - * @return static |
|
150 | - * @throws PhpfastcacheLogicException |
|
151 | - */ |
|
152 | - public function setCacheSlamsTimeout(int $cacheSlamsTimeout): static |
|
153 | - { |
|
154 | - return $this->setProperty('cacheSlamsTimeout', $cacheSlamsTimeout); |
|
155 | - } |
|
27 | + protected bool $secureFileManipulation = false; |
|
28 | + |
|
29 | + protected string $securityKey = ''; |
|
30 | + |
|
31 | + protected string $cacheFileExtension = 'txt'; |
|
32 | + |
|
33 | + protected int $defaultChmod = 0777; |
|
34 | + |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getSecurityKey(): string |
|
39 | + { |
|
40 | + return $this->securityKey; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $securityKey |
|
45 | + * @return static |
|
46 | + * @throws PhpfastcacheLogicException |
|
47 | + */ |
|
48 | + public function setSecurityKey(string $securityKey): static |
|
49 | + { |
|
50 | + return $this->setProperty('securityKey', $securityKey); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function isSecureFileManipulation(): bool |
|
57 | + { |
|
58 | + return $this->secureFileManipulation; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param bool $secureFileManipulation |
|
63 | + * @return static |
|
64 | + * @throws PhpfastcacheLogicException |
|
65 | + */ |
|
66 | + public function setSecureFileManipulation(bool $secureFileManipulation): static |
|
67 | + { |
|
68 | + return $this->setProperty('secureFileManipulation', $secureFileManipulation); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function getCacheFileExtension(): string |
|
76 | + { |
|
77 | + return $this->cacheFileExtension; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param string $cacheFileExtension |
|
82 | + * @return static |
|
83 | + * @throws PhpfastcacheInvalidConfigurationException |
|
84 | + * @throws PhpfastcacheLogicException |
|
85 | + */ |
|
86 | + public function setCacheFileExtension(string $cacheFileExtension): static |
|
87 | + { |
|
88 | + $safeFileExtensions = \explode('|', IOConfigurationOptionInterface::SAFE_FILE_EXTENSIONS); |
|
89 | + |
|
90 | + if (\str_contains($cacheFileExtension, '.')) { |
|
91 | + throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."'); |
|
92 | + } |
|
93 | + if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { |
|
94 | + throw new PhpfastcacheInvalidConfigurationException( |
|
95 | + "Extension \"$cacheFileExtension\" is unsafe, currently allowed extension names: " . \implode(', ', $safeFileExtensions) |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + return $this->setProperty('cacheFileExtension', $cacheFileExtension); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function getDefaultChmod(): int |
|
106 | + { |
|
107 | + return $this->defaultChmod; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param int $defaultChmod |
|
112 | + * @return static |
|
113 | + * @throws PhpfastcacheLogicException |
|
114 | + */ |
|
115 | + public function setDefaultChmod(int $defaultChmod): static |
|
116 | + { |
|
117 | + return $this->setProperty('defaultChmod', $defaultChmod); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return bool |
|
123 | + */ |
|
124 | + public function isPreventCacheSlams(): bool |
|
125 | + { |
|
126 | + return $this->preventCacheSlams; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @param bool $preventCacheSlams |
|
131 | + * @return static |
|
132 | + * @throws PhpfastcacheLogicException |
|
133 | + */ |
|
134 | + public function setPreventCacheSlams(bool $preventCacheSlams): static |
|
135 | + { |
|
136 | + return $this->setProperty('preventCacheSlams', $preventCacheSlams); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return int |
|
141 | + */ |
|
142 | + public function getCacheSlamsTimeout(): int |
|
143 | + { |
|
144 | + return $this->cacheSlamsTimeout; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param int $cacheSlamsTimeout |
|
149 | + * @return static |
|
150 | + * @throws PhpfastcacheLogicException |
|
151 | + */ |
|
152 | + public function setCacheSlamsTimeout(int $cacheSlamsTimeout): static |
|
153 | + { |
|
154 | + return $this->setProperty('cacheSlamsTimeout', $cacheSlamsTimeout); |
|
155 | + } |
|
156 | 156 | } |
@@ -21,16 +21,16 @@ |
||
21 | 21 | */ |
22 | 22 | class Config extends ConfigurationOption |
23 | 23 | { |
24 | - public function __construct(array $parameters = []) |
|
25 | - { |
|
26 | - \trigger_error( |
|
27 | - \sprintf( |
|
28 | - '%s class is deprecated and will be removed in v10, use %s instead.', |
|
29 | - self::class, |
|
30 | - ConfigurationOption::class |
|
31 | - ), |
|
32 | - \E_USER_DEPRECATED |
|
33 | - ); |
|
34 | - parent::__construct($parameters); |
|
35 | - } |
|
24 | + public function __construct(array $parameters = []) |
|
25 | + { |
|
26 | + \trigger_error( |
|
27 | + \sprintf( |
|
28 | + '%s class is deprecated and will be removed in v10, use %s instead.', |
|
29 | + self::class, |
|
30 | + ConfigurationOption::class |
|
31 | + ), |
|
32 | + \E_USER_DEPRECATED |
|
33 | + ); |
|
34 | + parent::__construct($parameters); |
|
35 | + } |
|
36 | 36 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | */ |
22 | 22 | class Config extends ConfigurationOption |
23 | 23 | { |
24 | - public function __construct(array $parameters = []) |
|
25 | - { |
|
24 | + public function __construct(array $parameters = []) { |
|
26 | 25 | \trigger_error( |
27 | 26 | \sprintf( |
28 | 27 | '%s class is deprecated and will be removed in v10, use %s instead.', |
@@ -18,33 +18,33 @@ |
||
18 | 18 | |
19 | 19 | interface IOConfigurationOptionInterface extends ConfigurationOptionInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Feel free to propose your own one |
|
23 | - * by opening a pull request :) |
|
24 | - */ |
|
25 | - public const SAFE_FILE_EXTENSIONS = 'txt|cache|db|pfc'; |
|
21 | + /** |
|
22 | + * Feel free to propose your own one |
|
23 | + * by opening a pull request :) |
|
24 | + */ |
|
25 | + public const SAFE_FILE_EXTENSIONS = 'txt|cache|db|pfc'; |
|
26 | 26 | |
27 | - public function getSecurityKey(): string; |
|
27 | + public function getSecurityKey(): string; |
|
28 | 28 | |
29 | - public function setSecurityKey(string $securityKey): static; |
|
29 | + public function setSecurityKey(string $securityKey): static; |
|
30 | 30 | |
31 | - public function isSecureFileManipulation(): bool; |
|
31 | + public function isSecureFileManipulation(): bool; |
|
32 | 32 | |
33 | - public function setSecureFileManipulation(bool $secureFileManipulation): static; |
|
33 | + public function setSecureFileManipulation(bool $secureFileManipulation): static; |
|
34 | 34 | |
35 | - public function getCacheFileExtension(): string; |
|
35 | + public function getCacheFileExtension(): string; |
|
36 | 36 | |
37 | - public function setCacheFileExtension(string $cacheFileExtension): static; |
|
37 | + public function setCacheFileExtension(string $cacheFileExtension): static; |
|
38 | 38 | |
39 | - public function getDefaultChmod(): int; |
|
39 | + public function getDefaultChmod(): int; |
|
40 | 40 | |
41 | - public function setDefaultChmod(int $defaultChmod): static; |
|
41 | + public function setDefaultChmod(int $defaultChmod): static; |
|
42 | 42 | |
43 | - public function isPreventCacheSlams(): bool; |
|
43 | + public function isPreventCacheSlams(): bool; |
|
44 | 44 | |
45 | - public function setPreventCacheSlams(bool $preventCacheSlams): static; |
|
45 | + public function setPreventCacheSlams(bool $preventCacheSlams): static; |
|
46 | 46 | |
47 | - public function getCacheSlamsTimeout(): int; |
|
47 | + public function getCacheSlamsTimeout(): int; |
|
48 | 48 | |
49 | - public function setCacheSlamsTimeout(int $cacheSlamsTimeout): static; |
|
49 | + public function setCacheSlamsTimeout(int $cacheSlamsTimeout): static; |
|
50 | 50 | } |
@@ -22,62 +22,62 @@ |
||
22 | 22 | |
23 | 23 | abstract class AbstractConfigurationOption implements LockableConfigurationInterface |
24 | 24 | { |
25 | - private bool $lockedObject = false; |
|
26 | - private ExtendedCacheItemPoolInterface $locker; |
|
25 | + private bool $lockedObject = false; |
|
26 | + private ExtendedCacheItemPoolInterface $locker; |
|
27 | 27 | |
28 | - protected function getClassName(): string |
|
29 | - { |
|
30 | - return $this::class; |
|
31 | - } |
|
28 | + protected function getClassName(): string |
|
29 | + { |
|
30 | + return $this::class; |
|
31 | + } |
|
32 | 32 | |
33 | - public function lock(ExtendedCacheItemPoolInterface $poolInstance): static |
|
34 | - { |
|
35 | - $this->lockedObject = true; |
|
36 | - $this->locker = $poolInstance; |
|
37 | - return $this; |
|
38 | - } |
|
33 | + public function lock(ExtendedCacheItemPoolInterface $poolInstance): static |
|
34 | + { |
|
35 | + $this->lockedObject = true; |
|
36 | + $this->locker = $poolInstance; |
|
37 | + return $this; |
|
38 | + } |
|
39 | 39 | |
40 | - public function lockedBy(): ExtendedCacheItemPoolInterface |
|
41 | - { |
|
42 | - return $this->locker; |
|
43 | - } |
|
40 | + public function lockedBy(): ExtendedCacheItemPoolInterface |
|
41 | + { |
|
42 | + return $this->locker; |
|
43 | + } |
|
44 | 44 | |
45 | - public function isLocked(): bool |
|
46 | - { |
|
47 | - return $this->lockedObject; |
|
48 | - } |
|
45 | + public function isLocked(): bool |
|
46 | + { |
|
47 | + return $this->lockedObject; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @throws PhpfastcacheLogicException |
|
52 | - * @throws PhpfastcacheInvalidArgumentException |
|
53 | - */ |
|
54 | - protected function setProperty(string $propertyName, mixed $propertyValue): static |
|
55 | - { |
|
56 | - $this->enforceLockedProperty($propertyName); |
|
57 | - if (property_exists($this, $propertyName)) { |
|
58 | - $this->$propertyName = $propertyValue; |
|
59 | - return $this; |
|
60 | - } |
|
61 | - throw new PhpfastcacheInvalidArgumentException("Unknown property $propertyName in {$this->getClassName()} context."); |
|
62 | - } |
|
50 | + /** |
|
51 | + * @throws PhpfastcacheLogicException |
|
52 | + * @throws PhpfastcacheInvalidArgumentException |
|
53 | + */ |
|
54 | + protected function setProperty(string $propertyName, mixed $propertyValue): static |
|
55 | + { |
|
56 | + $this->enforceLockedProperty($propertyName); |
|
57 | + if (property_exists($this, $propertyName)) { |
|
58 | + $this->$propertyName = $propertyValue; |
|
59 | + return $this; |
|
60 | + } |
|
61 | + throw new PhpfastcacheInvalidArgumentException("Unknown property $propertyName in {$this->getClassName()} context."); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @throws PhpfastcacheLogicException |
|
66 | - */ |
|
67 | - protected function enforceLockedProperty(string $propertyName): void |
|
68 | - { |
|
69 | - if ($this->lockedObject === true) { |
|
70 | - $dbt = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 3); |
|
71 | - $cause = $dbt[\array_key_last($dbt)] ?? null; |
|
72 | - if ($cause) { |
|
73 | - $moreInfo = \sprintf('Caused line %d in %s', $cause['line'], $cause['file']); |
|
74 | - } |
|
64 | + /** |
|
65 | + * @throws PhpfastcacheLogicException |
|
66 | + */ |
|
67 | + protected function enforceLockedProperty(string $propertyName): void |
|
68 | + { |
|
69 | + if ($this->lockedObject === true) { |
|
70 | + $dbt = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 3); |
|
71 | + $cause = $dbt[\array_key_last($dbt)] ?? null; |
|
72 | + if ($cause) { |
|
73 | + $moreInfo = \sprintf('Caused line %d in %s', $cause['line'], $cause['file']); |
|
74 | + } |
|
75 | 75 | |
76 | - throw new PhpfastcacheLogicException(\sprintf( |
|
77 | - 'You can no longer change the configuration "%s" as the cache pool instance is now running. %s', |
|
78 | - $propertyName, |
|
79 | - $moreInfo ?? '' |
|
80 | - )); |
|
81 | - } |
|
82 | - } |
|
76 | + throw new PhpfastcacheLogicException(\sprintf( |
|
77 | + 'You can no longer change the configuration "%s" as the cache pool instance is now running. %s', |
|
78 | + $propertyName, |
|
79 | + $moreInfo ?? '' |
|
80 | + )); |
|
81 | + } |
|
82 | + } |
|
83 | 83 | } |
@@ -35,182 +35,182 @@ |
||
35 | 35 | |
36 | 36 | class Psr16Adapter implements CacheInterface |
37 | 37 | { |
38 | - /** |
|
39 | - * @var ExtendedCacheItemPoolInterface |
|
40 | - */ |
|
41 | - protected ExtendedCacheItemPoolInterface $internalCacheInstance; |
|
42 | - |
|
43 | - /** |
|
44 | - * Psr16Adapter constructor. |
|
45 | - * @param string|ExtendedCacheItemPoolInterface $driver |
|
46 | - * @param null|ConfigurationOptionInterface $config |
|
47 | - * @throws PhpfastcacheDriverCheckException |
|
48 | - * @throws PhpfastcacheLogicException |
|
49 | - * @throws PhpfastcacheDriverException |
|
50 | - * @throws PhpfastcacheDriverNotFoundException |
|
51 | - */ |
|
52 | - public function __construct(string|ExtendedCacheItemPoolInterface $driver, ConfigurationOptionInterface $config = null) |
|
53 | - { |
|
54 | - if ($driver instanceof ExtendedCacheItemPoolInterface) { |
|
55 | - if ($config !== null) { |
|
56 | - throw new PhpfastcacheLogicException("You can't pass a config parameter along with an non-string '\$driver' parameter."); |
|
57 | - } |
|
58 | - $this->internalCacheInstance = $driver; |
|
59 | - } else { |
|
60 | - $this->internalCacheInstance = CacheManager::getInstance($driver, $config); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param string $key |
|
66 | - * @param mixed $default |
|
67 | - * @return mixed |
|
68 | - * @throws PhpfastcacheSimpleCacheException |
|
69 | - */ |
|
70 | - public function get(string $key, mixed $default = null): mixed |
|
71 | - { |
|
72 | - try { |
|
73 | - $cacheItem = $this->internalCacheInstance->getItem($key); |
|
74 | - if (!$cacheItem->isExpired() && $cacheItem->get() !== null) { |
|
75 | - return $cacheItem->get(); |
|
76 | - } |
|
77 | - |
|
78 | - return $default; |
|
79 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
80 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $key |
|
86 | - * @param mixed $value |
|
87 | - * @param null|int|DateInterval $ttl |
|
88 | - * @return bool |
|
89 | - * @throws PhpfastcacheSimpleCacheException |
|
90 | - */ |
|
91 | - public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool |
|
92 | - { |
|
93 | - try { |
|
94 | - $cacheItem = $this->internalCacheInstance |
|
95 | - ->getItem($key) |
|
96 | - ->set($value); |
|
97 | - if (\is_int($ttl) && $ttl <= 0) { |
|
98 | - $cacheItem->expiresAt((new DateTime('@0'))); |
|
99 | - } elseif ($ttl !== null) { |
|
100 | - $cacheItem->expiresAfter($ttl); |
|
101 | - } |
|
102 | - return $this->internalCacheInstance->save($cacheItem); |
|
103 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
104 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $key |
|
110 | - * @return bool |
|
111 | - * @throws PhpfastcacheSimpleCacheException |
|
112 | - * @throws InvalidArgumentException |
|
113 | - */ |
|
114 | - public function delete(string $key): bool |
|
115 | - { |
|
116 | - try { |
|
117 | - return $this->internalCacheInstance->deleteItem($key); |
|
118 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
119 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @return bool |
|
125 | - * @throws PhpfastcacheSimpleCacheException |
|
126 | - */ |
|
127 | - public function clear(): bool |
|
128 | - { |
|
129 | - try { |
|
130 | - return $this->internalCacheInstance->clear(); |
|
131 | - } catch (PhpfastcacheRootException $e) { |
|
132 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param iterable<string> $keys |
|
138 | - * @param null $default |
|
139 | - * @return ExtendedCacheItemInterface[] |
|
140 | - * @throws PhpfastcacheSimpleCacheException |
|
141 | - */ |
|
142 | - public function getMultiple(iterable $keys, mixed $default = null): iterable |
|
143 | - { |
|
144 | - if ($keys instanceof Traversable) { |
|
145 | - $keys = \iterator_to_array($keys); |
|
146 | - } |
|
147 | - try { |
|
148 | - return \array_map( |
|
149 | - static fn (ExtendedCacheItemInterface $item) => $item->isHit() ? $item->get() : $default, |
|
150 | - $this->internalCacheInstance->getItems($keys) |
|
151 | - ); |
|
152 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
153 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param iterable<string, mixed> $values |
|
159 | - * @param null|int|DateInterval $ttl |
|
160 | - * @return bool |
|
161 | - * @throws PhpfastcacheSimpleCacheException |
|
162 | - */ |
|
163 | - public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool |
|
164 | - { |
|
165 | - try { |
|
166 | - foreach ($values as $key => $value) { |
|
167 | - $cacheItem = $this->internalCacheInstance->getItem($key)->set($value); |
|
168 | - |
|
169 | - if (\is_int($ttl) && $ttl <= 0) { |
|
170 | - $cacheItem->expiresAt((new DateTime('@0'))); |
|
171 | - } elseif ($ttl !== null) { |
|
172 | - $cacheItem->expiresAfter($ttl); |
|
173 | - } |
|
174 | - $this->internalCacheInstance->saveDeferred($cacheItem); |
|
175 | - unset($cacheItem); |
|
176 | - } |
|
177 | - return $this->internalCacheInstance->commit(); |
|
178 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
179 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @param iterable<string> $keys |
|
185 | - * @return bool |
|
186 | - * @throws PhpfastcacheSimpleCacheException |
|
187 | - * @throws InvalidArgumentException |
|
188 | - */ |
|
189 | - public function deleteMultiple(iterable $keys): bool |
|
190 | - { |
|
191 | - try { |
|
192 | - if (\is_array($keys)) { |
|
193 | - return $this->internalCacheInstance->deleteItems($keys); |
|
194 | - } |
|
195 | - |
|
196 | - return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys)); |
|
197 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
198 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @param string $key |
|
204 | - * @return bool |
|
205 | - * @throws PhpfastcacheSimpleCacheException |
|
206 | - */ |
|
207 | - public function has(string $key): bool |
|
208 | - { |
|
209 | - try { |
|
210 | - $cacheItem = $this->internalCacheInstance->getItem($key); |
|
211 | - return $cacheItem->isHit() && !$cacheItem->isExpired(); |
|
212 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
213 | - throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
214 | - } |
|
215 | - } |
|
38 | + /** |
|
39 | + * @var ExtendedCacheItemPoolInterface |
|
40 | + */ |
|
41 | + protected ExtendedCacheItemPoolInterface $internalCacheInstance; |
|
42 | + |
|
43 | + /** |
|
44 | + * Psr16Adapter constructor. |
|
45 | + * @param string|ExtendedCacheItemPoolInterface $driver |
|
46 | + * @param null|ConfigurationOptionInterface $config |
|
47 | + * @throws PhpfastcacheDriverCheckException |
|
48 | + * @throws PhpfastcacheLogicException |
|
49 | + * @throws PhpfastcacheDriverException |
|
50 | + * @throws PhpfastcacheDriverNotFoundException |
|
51 | + */ |
|
52 | + public function __construct(string|ExtendedCacheItemPoolInterface $driver, ConfigurationOptionInterface $config = null) |
|
53 | + { |
|
54 | + if ($driver instanceof ExtendedCacheItemPoolInterface) { |
|
55 | + if ($config !== null) { |
|
56 | + throw new PhpfastcacheLogicException("You can't pass a config parameter along with an non-string '\$driver' parameter."); |
|
57 | + } |
|
58 | + $this->internalCacheInstance = $driver; |
|
59 | + } else { |
|
60 | + $this->internalCacheInstance = CacheManager::getInstance($driver, $config); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param string $key |
|
66 | + * @param mixed $default |
|
67 | + * @return mixed |
|
68 | + * @throws PhpfastcacheSimpleCacheException |
|
69 | + */ |
|
70 | + public function get(string $key, mixed $default = null): mixed |
|
71 | + { |
|
72 | + try { |
|
73 | + $cacheItem = $this->internalCacheInstance->getItem($key); |
|
74 | + if (!$cacheItem->isExpired() && $cacheItem->get() !== null) { |
|
75 | + return $cacheItem->get(); |
|
76 | + } |
|
77 | + |
|
78 | + return $default; |
|
79 | + } catch (PhpfastcacheInvalidArgumentException $e) { |
|
80 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $key |
|
86 | + * @param mixed $value |
|
87 | + * @param null|int|DateInterval $ttl |
|
88 | + * @return bool |
|
89 | + * @throws PhpfastcacheSimpleCacheException |
|
90 | + */ |
|
91 | + public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool |
|
92 | + { |
|
93 | + try { |
|
94 | + $cacheItem = $this->internalCacheInstance |
|
95 | + ->getItem($key) |
|
96 | + ->set($value); |
|
97 | + if (\is_int($ttl) && $ttl <= 0) { |
|
98 | + $cacheItem->expiresAt((new DateTime('@0'))); |
|
99 | + } elseif ($ttl !== null) { |
|
100 | + $cacheItem->expiresAfter($ttl); |
|
101 | + } |
|
102 | + return $this->internalCacheInstance->save($cacheItem); |
|
103 | + } catch (PhpfastcacheInvalidArgumentException $e) { |
|
104 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $key |
|
110 | + * @return bool |
|
111 | + * @throws PhpfastcacheSimpleCacheException |
|
112 | + * @throws InvalidArgumentException |
|
113 | + */ |
|
114 | + public function delete(string $key): bool |
|
115 | + { |
|
116 | + try { |
|
117 | + return $this->internalCacheInstance->deleteItem($key); |
|
118 | + } catch (PhpfastcacheInvalidArgumentException $e) { |
|
119 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @return bool |
|
125 | + * @throws PhpfastcacheSimpleCacheException |
|
126 | + */ |
|
127 | + public function clear(): bool |
|
128 | + { |
|
129 | + try { |
|
130 | + return $this->internalCacheInstance->clear(); |
|
131 | + } catch (PhpfastcacheRootException $e) { |
|
132 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param iterable<string> $keys |
|
138 | + * @param null $default |
|
139 | + * @return ExtendedCacheItemInterface[] |
|
140 | + * @throws PhpfastcacheSimpleCacheException |
|
141 | + */ |
|
142 | + public function getMultiple(iterable $keys, mixed $default = null): iterable |
|
143 | + { |
|
144 | + if ($keys instanceof Traversable) { |
|
145 | + $keys = \iterator_to_array($keys); |
|
146 | + } |
|
147 | + try { |
|
148 | + return \array_map( |
|
149 | + static fn (ExtendedCacheItemInterface $item) => $item->isHit() ? $item->get() : $default, |
|
150 | + $this->internalCacheInstance->getItems($keys) |
|
151 | + ); |
|
152 | + } catch (PhpfastcacheInvalidArgumentException $e) { |
|
153 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param iterable<string, mixed> $values |
|
159 | + * @param null|int|DateInterval $ttl |
|
160 | + * @return bool |
|
161 | + * @throws PhpfastcacheSimpleCacheException |
|
162 | + */ |
|
163 | + public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool |
|
164 | + { |
|
165 | + try { |
|
166 | + foreach ($values as $key => $value) { |
|
167 | + $cacheItem = $this->internalCacheInstance->getItem($key)->set($value); |
|
168 | + |
|
169 | + if (\is_int($ttl) && $ttl <= 0) { |
|
170 | + $cacheItem->expiresAt((new DateTime('@0'))); |
|
171 | + } elseif ($ttl !== null) { |
|
172 | + $cacheItem->expiresAfter($ttl); |
|
173 | + } |
|
174 | + $this->internalCacheInstance->saveDeferred($cacheItem); |
|
175 | + unset($cacheItem); |
|
176 | + } |
|
177 | + return $this->internalCacheInstance->commit(); |
|
178 | + } catch (PhpfastcacheInvalidArgumentException $e) { |
|
179 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @param iterable<string> $keys |
|
185 | + * @return bool |
|
186 | + * @throws PhpfastcacheSimpleCacheException |
|
187 | + * @throws InvalidArgumentException |
|
188 | + */ |
|
189 | + public function deleteMultiple(iterable $keys): bool |
|
190 | + { |
|
191 | + try { |
|
192 | + if (\is_array($keys)) { |
|
193 | + return $this->internalCacheInstance->deleteItems($keys); |
|
194 | + } |
|
195 | + |
|
196 | + return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys)); |
|
197 | + } catch (PhpfastcacheInvalidArgumentException $e) { |
|
198 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @param string $key |
|
204 | + * @return bool |
|
205 | + * @throws PhpfastcacheSimpleCacheException |
|
206 | + */ |
|
207 | + public function has(string $key): bool |
|
208 | + { |
|
209 | + try { |
|
210 | + $cacheItem = $this->internalCacheInstance->getItem($key); |
|
211 | + return $cacheItem->isHit() && !$cacheItem->isExpired(); |
|
212 | + } catch (PhpfastcacheInvalidArgumentException $e) { |
|
213 | + throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
|
214 | + } |
|
215 | + } |
|
216 | 216 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @throws PhpfastcacheDriverException |
50 | 50 | * @throws PhpfastcacheDriverNotFoundException |
51 | 51 | */ |
52 | - public function __construct(string|ExtendedCacheItemPoolInterface $driver, ConfigurationOptionInterface $config = null) |
|
52 | + public function __construct(string | ExtendedCacheItemPoolInterface $driver, ConfigurationOptionInterface $config = null) |
|
53 | 53 | { |
54 | 54 | if ($driver instanceof ExtendedCacheItemPoolInterface) { |
55 | 55 | if ($config !== null) { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @return bool |
89 | 89 | * @throws PhpfastcacheSimpleCacheException |
90 | 90 | */ |
91 | - public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool |
|
91 | + public function set(string $key, mixed $value, null | int | \DateInterval $ttl = null): bool |
|
92 | 92 | { |
93 | 93 | try { |
94 | 94 | $cacheItem = $this->internalCacheInstance |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @return bool |
161 | 161 | * @throws PhpfastcacheSimpleCacheException |
162 | 162 | */ |
163 | - public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool |
|
163 | + public function setMultiple(iterable $values, null | int | \DateInterval $ttl = null): bool |
|
164 | 164 | { |
165 | 165 | try { |
166 | 166 | foreach ($values as $key => $value) { |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | * @throws PhpfastcacheDriverException |
50 | 50 | * @throws PhpfastcacheDriverNotFoundException |
51 | 51 | */ |
52 | - public function __construct(string|ExtendedCacheItemPoolInterface $driver, ConfigurationOptionInterface $config = null) |
|
53 | - { |
|
52 | + public function __construct(string|ExtendedCacheItemPoolInterface $driver, ConfigurationOptionInterface $config = null) { |
|
54 | 53 | if ($driver instanceof ExtendedCacheItemPoolInterface) { |
55 | 54 | if ($config !== null) { |
56 | 55 | throw new PhpfastcacheLogicException("You can't pass a config parameter along with an non-string '\$driver' parameter."); |
57 | 56 | } |
58 | 57 | $this->internalCacheInstance = $driver; |
59 | - } else { |
|
58 | + } |
|
59 | + else { |
|
60 | 60 | $this->internalCacheInstance = CacheManager::getInstance($driver, $config); |
61 | 61 | } |
62 | 62 | } |
@@ -76,7 +76,8 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | return $default; |
79 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
79 | + } |
|
80 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
80 | 81 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
81 | 82 | } |
82 | 83 | } |
@@ -96,11 +97,13 @@ discard block |
||
96 | 97 | ->set($value); |
97 | 98 | if (\is_int($ttl) && $ttl <= 0) { |
98 | 99 | $cacheItem->expiresAt((new DateTime('@0'))); |
99 | - } elseif ($ttl !== null) { |
|
100 | + } |
|
101 | + elseif ($ttl !== null) { |
|
100 | 102 | $cacheItem->expiresAfter($ttl); |
101 | 103 | } |
102 | 104 | return $this->internalCacheInstance->save($cacheItem); |
103 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
105 | + } |
|
106 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
104 | 107 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
105 | 108 | } |
106 | 109 | } |
@@ -115,7 +118,8 @@ discard block |
||
115 | 118 | { |
116 | 119 | try { |
117 | 120 | return $this->internalCacheInstance->deleteItem($key); |
118 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
121 | + } |
|
122 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
119 | 123 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
120 | 124 | } |
121 | 125 | } |
@@ -128,7 +132,8 @@ discard block |
||
128 | 132 | { |
129 | 133 | try { |
130 | 134 | return $this->internalCacheInstance->clear(); |
131 | - } catch (PhpfastcacheRootException $e) { |
|
135 | + } |
|
136 | + catch (PhpfastcacheRootException $e) { |
|
132 | 137 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
133 | 138 | } |
134 | 139 | } |
@@ -149,7 +154,8 @@ discard block |
||
149 | 154 | static fn (ExtendedCacheItemInterface $item) => $item->isHit() ? $item->get() : $default, |
150 | 155 | $this->internalCacheInstance->getItems($keys) |
151 | 156 | ); |
152 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
157 | + } |
|
158 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
153 | 159 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
154 | 160 | } |
155 | 161 | } |
@@ -168,14 +174,16 @@ discard block |
||
168 | 174 | |
169 | 175 | if (\is_int($ttl) && $ttl <= 0) { |
170 | 176 | $cacheItem->expiresAt((new DateTime('@0'))); |
171 | - } elseif ($ttl !== null) { |
|
177 | + } |
|
178 | + elseif ($ttl !== null) { |
|
172 | 179 | $cacheItem->expiresAfter($ttl); |
173 | 180 | } |
174 | 181 | $this->internalCacheInstance->saveDeferred($cacheItem); |
175 | 182 | unset($cacheItem); |
176 | 183 | } |
177 | 184 | return $this->internalCacheInstance->commit(); |
178 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
185 | + } |
|
186 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
179 | 187 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
180 | 188 | } |
181 | 189 | } |
@@ -194,7 +202,8 @@ discard block |
||
194 | 202 | } |
195 | 203 | |
196 | 204 | return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys)); |
197 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
205 | + } |
|
206 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
198 | 207 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
199 | 208 | } |
200 | 209 | } |
@@ -209,7 +218,8 @@ discard block |
||
209 | 218 | try { |
210 | 219 | $cacheItem = $this->internalCacheInstance->getItem($key); |
211 | 220 | return $cacheItem->isHit() && !$cacheItem->isExpired(); |
212 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
221 | + } |
|
222 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
213 | 223 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
214 | 224 | } |
215 | 225 | } |