Test Failed
Push — master ( 0f2ecd...7d85b5 )
by
unknown
16:30 queued 14s
created
vendor/phpfastcache/phpfastcache/lib/Phpfastcache/Event/EventInterface.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@
 block discarded – undo
18 18
 
19 19
 interface EventInterface
20 20
 {
21
-    /**
22
-     * @return array<string, string>
23
-     */
24
-    public static function getEvents(): array;
21
+	/**
22
+	 * @return array<string, string>
23
+	 */
24
+	public static function getEvents(): array;
25 25
 }
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxyInterface.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -65,24 +65,24 @@
 block discarded – undo
65 65
  */
66 66
 interface PhpfastcacheAbstractProxyInterface
67 67
 {
68
-    public const DRIVER_CHECK_FAILURE = ExtendedCacheItemPoolInterface::DRIVER_CHECK_FAILURE;
69
-    public const DRIVER_CONNECT_FAILURE = ExtendedCacheItemPoolInterface::DRIVER_CONNECT_FAILURE;
70
-    public const DRIVER_KEY_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX;
71
-    public const DRIVER_DATA_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX;
72
-    public const DRIVER_EDATE_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX;
73
-    public const DRIVER_CDATE_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX;
74
-    public const DRIVER_MDATE_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX;
68
+	public const DRIVER_CHECK_FAILURE = ExtendedCacheItemPoolInterface::DRIVER_CHECK_FAILURE;
69
+	public const DRIVER_CONNECT_FAILURE = ExtendedCacheItemPoolInterface::DRIVER_CONNECT_FAILURE;
70
+	public const DRIVER_KEY_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX;
71
+	public const DRIVER_DATA_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX;
72
+	public const DRIVER_EDATE_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX;
73
+	public const DRIVER_CDATE_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX;
74
+	public const DRIVER_MDATE_WRAPPER_INDEX = ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX;
75 75
 
76
-    public const DRIVER_TAGS_KEY_PREFIX = TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX;
77
-    public const DRIVER_TAGS_WRAPPER_INDEX = TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX;
78
-    public const TAG_STRATEGY_ONE = TaggableCacheItemPoolInterface::TAG_STRATEGY_ONE;
79
-    public const TAG_STRATEGY_ALL = TaggableCacheItemPoolInterface::TAG_STRATEGY_ALL;
80
-    public const TAG_STRATEGY_ONLY = TaggableCacheItemPoolInterface::TAG_STRATEGY_ONLY;
76
+	public const DRIVER_TAGS_KEY_PREFIX = TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX;
77
+	public const DRIVER_TAGS_WRAPPER_INDEX = TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX;
78
+	public const TAG_STRATEGY_ONE = TaggableCacheItemPoolInterface::TAG_STRATEGY_ONE;
79
+	public const TAG_STRATEGY_ALL = TaggableCacheItemPoolInterface::TAG_STRATEGY_ALL;
80
+	public const TAG_STRATEGY_ONLY = TaggableCacheItemPoolInterface::TAG_STRATEGY_ONLY;
81 81
 
82
-    /**
83
-     * @param string $name
84
-     * @param array<mixed> $args
85
-     * @return mixed
86
-     */
87
-    public function __call(string $name, array $args): mixed;
82
+	/**
83
+	 * @param string $name
84
+	 * @param array<mixed> $args
85
+	 * @return mixed
86
+	 */
87
+	public function __call(string $name, array $args): mixed;
88 88
 }
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -32,30 +32,30 @@
 block discarded – undo
32 32
  */
33 33
 abstract class PhpfastcacheAbstractProxy implements PhpfastcacheAbstractProxyInterface
34 34
 {
35
-    /**
36
-     * @var ExtendedCacheItemPoolInterface
37
-     */
38
-    protected ExtendedCacheItemPoolInterface $instance;
35
+	/**
36
+	 * @var ExtendedCacheItemPoolInterface
37
+	 */
38
+	protected ExtendedCacheItemPoolInterface $instance;
39 39
 
40
-    /**
41
-     * PhpfastcacheAbstractProxy constructor.
42
-     * @param string $driver
43
-     * @param null|ConfigurationOptionInterface $config
44
-     * @throws PhpfastcacheDriverCheckException
45
-     * @throws PhpfastcacheDriverException
46
-     * @throws PhpfastcacheDriverNotFoundException
47
-     * @throws PhpfastcacheLogicException
48
-     */
49
-    public function __construct(string $driver, ?ConfigurationOptionInterface $config = null)
50
-    {
51
-        $this->instance = CacheManager::getInstance($driver, $config);
52
-    }
40
+	/**
41
+	 * PhpfastcacheAbstractProxy constructor.
42
+	 * @param string $driver
43
+	 * @param null|ConfigurationOptionInterface $config
44
+	 * @throws PhpfastcacheDriverCheckException
45
+	 * @throws PhpfastcacheDriverException
46
+	 * @throws PhpfastcacheDriverNotFoundException
47
+	 * @throws PhpfastcacheLogicException
48
+	 */
49
+	public function __construct(string $driver, ?ConfigurationOptionInterface $config = null)
50
+	{
51
+		$this->instance = CacheManager::getInstance($driver, $config);
52
+	}
53 53
 
54
-    /**
55
-     * @inheritDoc
56
-     */
57
-    public function __call(string $name, array $args): mixed
58
-    {
59
-        return $this->instance->$name(...$args);
60
-    }
54
+	/**
55
+	 * @inheritDoc
56
+	 */
57
+	public function __call(string $name, array $args): mixed
58
+	{
59
+		return $this->instance->$name(...$args);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
php/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/CacheManager.php 1 patch
Indentation   +406 added lines, -406 removed lines patch added patch discarded remove patch
@@ -36,410 +36,410 @@
 block discarded – undo
36 36
  */
37 37
 class CacheManager
38 38
 {
39
-    use ClassNamespaceResolverTrait;
40
-    use UninstanciableObjectTrait;
41
-
42
-    public const CORE_DRIVER_NAMESPACE = 'Phpfastcache\Drivers\\';
43
-
44
-    protected static ConfigurationOptionInterface $config;
45
-
46
-    protected static string $namespacePath;
47
-
48
-    /**
49
-     * @var ExtendedCacheItemPoolInterface[]
50
-     */
51
-    protected static array $instances = [];
52
-
53
-    /**
54
-     * @var string[]
55
-     */
56
-    protected static array $driverOverrides = [];
57
-
58
-    /**
59
-     * @var string[]
60
-     */
61
-    protected static array $driverCustoms = [];
62
-
63
-    /**
64
-     * @var string[]
65
-     */
66
-    protected static array $driverExtensions = [];
67
-
68
-    /**
69
-     * @param string $instanceId
70
-     * @return ExtendedCacheItemPoolInterface
71
-     * @throws PhpfastcacheInstanceNotFoundException
72
-     */
73
-    public static function getInstanceById(string $instanceId): ExtendedCacheItemPoolInterface
74
-    {
75
-        if (isset(self::$instances[$instanceId])) {
76
-            return self::$instances[$instanceId];
77
-        }
78
-
79
-        throw new PhpfastcacheInstanceNotFoundException(sprintf('Instance ID %s not found', $instanceId));
80
-    }
81
-
82
-    /**
83
-     * Return the list of instances
84
-     *
85
-     * @return ExtendedCacheItemPoolInterface[]
86
-     */
87
-    public static function getInstances(): array
88
-    {
89
-        return self::$instances;
90
-    }
91
-
92
-    /**
93
-     * @param string $driver
94
-     * @param ConfigurationOptionInterface|null $config
95
-     * @param string|null $instanceId
96
-     * @return ExtendedCacheItemPoolInterface
97
-     * @throws PhpfastcacheDriverCheckException
98
-     * @throws PhpfastcacheDriverException
99
-     * @throws PhpfastcacheDriverNotFoundException
100
-     * @throws PhpfastcacheExtensionNotInstalledException
101
-     * @throws PhpfastcacheLogicException
102
-     */
103
-    public static function getInstance(string $driver, ?ConfigurationOptionInterface $config = null, ?string $instanceId = null): ExtendedCacheItemPoolInterface
104
-    {
105
-        if (\class_exists($driver) && \str_starts_with($driver, 'Phpfastcache')) {
106
-            $driverClass = $driver;
107
-        } else {
108
-            $driver = self::normalizeDriverName($driver);
109
-            $driverClass = self::getDriverClass($driver);
110
-        }
111
-        $config = self::validateConfig($config);
112
-        $instanceId = $instanceId ?: self::getInstanceHash($driverClass, $config);
113
-
114
-        if (!isset(self::$instances[$instanceId])) {
115
-            if (\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) {
116
-                if (($configClass = $driverClass::getConfigClass()) !== $config::class) {
117
-                    $config = new $configClass($config->toArray());
118
-                }
119
-                self::$instances[$instanceId] = new $driverClass(
120
-                    $config,
121
-                    $instanceId,
122
-                    EventManager::getInstance()
123
-                );
124
-            } else {
125
-                try {
126
-                    self::$driverExtensions[$driver] = ExtensionManager::getExtension($driver);
127
-                    return CacheManager::getInstance($driver, $config, $instanceId);
128
-                } catch (PhpfastcacheExtensionNotFoundException) {
129
-                    if (in_array($driver, ExtensionManager::KNOWN_EXTENSION_NAMES, true)) {
130
-                        throw new PhpfastcacheExtensionNotInstalledException(sprintf(
131
-                            'You requested a driver which is now an extension. Run the following command to solve this issue: %s',
132
-                            sprintf('composer install phpfastcache/%s-extension', strtolower($driver))
133
-                        ));
134
-                    }
135
-                    throw new PhpfastcacheDriverNotFoundException(sprintf(
136
-                        'The driver "%s" does not exist or does not implement %s.',
137
-                        $driver,
138
-                        ExtendedCacheItemPoolInterface::class,
139
-                    ));
140
-                }
141
-            }
142
-        }
143
-
144
-        return self::$instances[$instanceId];
145
-    }
146
-
147
-    /**
148
-     * @param string $driverClass
149
-     * @param ConfigurationOptionInterface $config
150
-     * @return string
151
-     */
152
-    protected static function getInstanceHash(string $driverClass, ConfigurationOptionInterface $config): string
153
-    {
154
-        return \md5($driverClass . \serialize(
155
-            \array_filter(
156
-                $config->toArray(),
157
-                static fn ($val) => $config->isValueSerializable($val)
158
-            )
159
-        ));
160
-    }
161
-
162
-    /**
163
-     * @param ConfigurationOptionInterface|null $config
164
-     * @return ConfigurationOptionInterface
165
-     * @throws PhpfastcacheLogicException
166
-     */
167
-    protected static function validateConfig(?ConfigurationOptionInterface $config): ConfigurationOptionInterface
168
-    {
169
-        if ($config instanceof ConfigurationOptionInterface && $config->isLocked()) {
170
-            throw new PhpfastcacheLogicException('You provided an already locked configuration, cannot continue.');
171
-        }
172
-        return $config ?? self::getDefaultConfig();
173
-    }
174
-
175
-    /**
176
-     * @return ConfigurationOptionInterface
177
-     */
178
-    public static function getDefaultConfig(): ConfigurationOptionInterface
179
-    {
180
-        return self::$config ?? self::$config = new ConfigurationOption();
181
-    }
182
-
183
-    /**
184
-     * @param string $driverName
185
-     * @return string
186
-     */
187
-    public static function normalizeDriverName(string $driverName): string
188
-    {
189
-        return \ucfirst(\strtolower(\trim($driverName)));
190
-    }
191
-
192
-    /**
193
-     * @param string $driverName
194
-     * @return string
195
-     */
196
-    public static function getDriverClass(string $driverName): string
197
-    {
198
-        if (!empty(self::$driverExtensions[$driverName])) {
199
-            $driverClass = self::$driverExtensions[$driverName];
200
-        } elseif (!empty(self::$driverCustoms[$driverName])) {
201
-            $driverClass = self::$driverCustoms[$driverName];
202
-        } elseif (!empty(self::$driverOverrides[$driverName])) {
203
-            $driverClass = self::$driverOverrides[$driverName];
204
-        } else {
205
-            $driverClass = self::getNamespacePath() . $driverName . '\Driver';
206
-        }
207
-
208
-        return $driverClass;
209
-    }
210
-
211
-    /**
212
-     * @return string
213
-     */
214
-    public static function getNamespacePath(): string
215
-    {
216
-        return self::$namespacePath ?? self::getDefaultNamespacePath();
217
-    }
218
-
219
-    /**
220
-     * @return string
221
-     */
222
-    public static function getDefaultNamespacePath(): string
223
-    {
224
-        return self::CORE_DRIVER_NAMESPACE;
225
-    }
226
-
227
-    /**
228
-     * @return bool
229
-     */
230
-    public static function clearInstances(): bool
231
-    {
232
-        self::$instances = [];
233
-
234
-        \gc_collect_cycles();
235
-
236
-        return true;
237
-    }
238
-
239
-    /**
240
-     * @param ExtendedCacheItemPoolInterface $cachePoolInstance
241
-     * @return bool
242
-     * @since 7.0.4
243
-     */
244
-    public static function clearInstance(ExtendedCacheItemPoolInterface $cachePoolInstance): bool
245
-    {
246
-        $found = false;
247
-        self::$instances = \array_filter(
248
-            \array_map(
249
-                static function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInstance, &$found) {
250
-                    if (\spl_object_hash($cachePool) === \spl_object_hash($cachePoolInstance)) {
251
-                        $found = true;
252
-                        return null;
253
-                    }
254
-                    return $cachePool;
255
-                },
256
-                self::$instances
257
-            )
258
-        );
259
-
260
-        return $found;
261
-    }
262
-
263
-    /**
264
-     * @param ConfigurationOptionInterface $config
265
-     * @throws PhpfastcacheInvalidArgumentException
266
-     */
267
-    public static function setDefaultConfig(ConfigurationOptionInterface $config): void
268
-    {
269
-        if (\is_subclass_of($config, ConfigurationOption::class)) {
270
-            throw new PhpfastcacheInvalidArgumentException('Default configuration cannot be a child class of ConfigurationOption::class');
271
-        }
272
-        self::$config = $config;
273
-    }
274
-
275
-    /**
276
-     * @param string $driverName
277
-     * @param string $className
278
-     * @return void
279
-     * @throws PhpfastcacheLogicException
280
-     * @throws PhpfastcacheUnsupportedOperationException
281
-     * @throws PhpfastcacheInvalidArgumentException
282
-     */
283
-    public static function addCustomDriver(string $driverName, string $className): void
284
-    {
285
-        $driverName = self::normalizeDriverName($driverName);
286
-
287
-        if (empty($driverName)) {
288
-            throw new PhpfastcacheInvalidArgumentException("Can't add a custom driver because its name is empty");
289
-        }
290
-
291
-        if (!\class_exists($className)) {
292
-            throw new PhpfastcacheInvalidArgumentException(
293
-                \sprintf("Can't add '%s' because the class '%s' does not exist", $driverName, $className)
294
-            );
295
-        }
296
-
297
-        if (!empty(self::$driverCustoms[$driverName])) {
298
-            throw new PhpfastcacheLogicException(\sprintf("Driver '%s' has been already added", $driverName));
299
-        }
300
-
301
-        if (\in_array($driverName, self::getDriverList(), true)) {
302
-            throw new PhpfastcacheLogicException(\sprintf("Driver '%s' is already a part of the Phpfastcache core", $driverName));
303
-        }
304
-
305
-        self::$driverCustoms[$driverName] = $className;
306
-    }
307
-
308
-    /**
309
-     * @param string $driverName
310
-     * @return bool
311
-     */
312
-    public static function customDriverExists(string $driverName): bool
313
-    {
314
-        return isset(self::$driverCustoms[$driverName]);
315
-    }
316
-
317
-    /**
318
-     * Return the list of available drivers Capitalized
319
-     * with optional FQCN as key
320
-     *
321
-     * @param bool $fqcnAsKey Describe keys with Full Qualified Class Name
322
-     * @return string[]
323
-     * @throws PhpfastcacheUnsupportedOperationException
324
-     */
325
-    public static function getDriverList(bool $fqcnAsKey = false): array
326
-    {
327
-        static $driverList;
328
-
329
-        if (self::getDefaultNamespacePath() === self::getNamespacePath()) {
330
-            if ($driverList === null) {
331
-                $prefix = self::CORE_DRIVER_NAMESPACE;
332
-                $classMap = self::createClassMap(__DIR__ . '/Drivers');
333
-                $driverList = [];
334
-
335
-                foreach (\array_keys($classMap) as $class) {
336
-                    $driverList[] = \str_replace($prefix, '', \substr($class, 0, \strrpos($class, '\\')));
337
-                }
338
-
339
-                $driverList = \array_values(\array_unique($driverList));
340
-            }
341
-
342
-            $driverList = \array_merge($driverList, \array_keys(self::$driverCustoms));
343
-
344
-            if ($fqcnAsKey) {
345
-                $realDriverList = [];
346
-                foreach ($driverList as $driverName) {
347
-                    $realDriverList[self::getDriverClass($driverName)] = $driverName;
348
-                }
349
-                $driverList = $realDriverList;
350
-            }
351
-
352
-            \asort($driverList);
353
-
354
-            return $driverList;
355
-        }
356
-
357
-        throw new PhpfastcacheUnsupportedOperationException('Cannot get the driver list if the default namespace path has changed.');
358
-    }
359
-
360
-    /**
361
-     * @param string $driverName
362
-     * @return void
363
-     * @throws PhpfastcacheLogicException
364
-     * @throws PhpfastcacheInvalidArgumentException
365
-     */
366
-    public static function removeCustomDriver(string $driverName): void
367
-    {
368
-        $driverName = self::normalizeDriverName($driverName);
369
-
370
-        if (empty($driverName)) {
371
-            throw new PhpfastcacheInvalidArgumentException("Can't remove a custom driver because its name is empty");
372
-        }
373
-
374
-        if (!isset(self::$driverCustoms[$driverName])) {
375
-            throw new PhpfastcacheLogicException(\sprintf("Driver '%s' does not exist", $driverName));
376
-        }
377
-
378
-        unset(self::$driverCustoms[$driverName]);
379
-    }
380
-
381
-    /**
382
-     * @param string $driverName
383
-     * @param string $className
384
-     * @return void
385
-     * @throws PhpfastcacheLogicException
386
-     * @throws PhpfastcacheUnsupportedOperationException
387
-     * @throws PhpfastcacheInvalidArgumentException
388
-     */
389
-    public static function addCoreDriverOverride(string $driverName, string $className): void
390
-    {
391
-        $driverName = self::normalizeDriverName($driverName);
392
-
393
-        if (empty($driverName)) {
394
-            throw new PhpfastcacheInvalidArgumentException("Can't add a core driver override because its name is empty");
395
-        }
396
-
397
-        if (!\class_exists($className)) {
398
-            throw new PhpfastcacheInvalidArgumentException(
399
-                \sprintf("Can't override '%s' because the class '%s' does not exist", $driverName, $className)
400
-            );
401
-        }
402
-
403
-        if (!empty(self::$driverOverrides[$driverName])) {
404
-            throw new PhpfastcacheLogicException(\sprintf("Driver '%s' has been already overridden", $driverName));
405
-        }
406
-
407
-        if (!\in_array($driverName, self::getDriverList(), true)) {
408
-            throw new PhpfastcacheLogicException(\sprintf("Driver '%s' can't be overridden since its not a part of the Phpfastcache core", $driverName));
409
-        }
410
-
411
-        if (!\is_subclass_of($className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver', true)) {
412
-            throw new PhpfastcacheLogicException(
413
-                \sprintf(
414
-                    "Can't override '%s' because the class '%s' MUST extend '%s'",
415
-                    $driverName,
416
-                    $className,
417
-                    self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver'
418
-                )
419
-            );
420
-        }
421
-
422
-        self::$driverOverrides[$driverName] = $className;
423
-    }
424
-
425
-    /**
426
-     * @param string $driverName
427
-     * @return void
428
-     * @throws PhpfastcacheLogicException
429
-     * @throws PhpfastcacheInvalidArgumentException
430
-     */
431
-    public static function removeCoreDriverOverride(string $driverName): void
432
-    {
433
-        $driverName = self::normalizeDriverName($driverName);
434
-
435
-        if (empty($driverName)) {
436
-            throw new PhpfastcacheInvalidArgumentException("Can't remove a core driver override because its name is empty");
437
-        }
438
-
439
-        if (!isset(self::$driverOverrides[$driverName])) {
440
-            throw new PhpfastcacheLogicException(\sprintf("Driver '%s' were not overridden", $driverName));
441
-        }
442
-
443
-        unset(self::$driverOverrides[$driverName]);
444
-    }
39
+	use ClassNamespaceResolverTrait;
40
+	use UninstanciableObjectTrait;
41
+
42
+	public const CORE_DRIVER_NAMESPACE = 'Phpfastcache\Drivers\\';
43
+
44
+	protected static ConfigurationOptionInterface $config;
45
+
46
+	protected static string $namespacePath;
47
+
48
+	/**
49
+	 * @var ExtendedCacheItemPoolInterface[]
50
+	 */
51
+	protected static array $instances = [];
52
+
53
+	/**
54
+	 * @var string[]
55
+	 */
56
+	protected static array $driverOverrides = [];
57
+
58
+	/**
59
+	 * @var string[]
60
+	 */
61
+	protected static array $driverCustoms = [];
62
+
63
+	/**
64
+	 * @var string[]
65
+	 */
66
+	protected static array $driverExtensions = [];
67
+
68
+	/**
69
+	 * @param string $instanceId
70
+	 * @return ExtendedCacheItemPoolInterface
71
+	 * @throws PhpfastcacheInstanceNotFoundException
72
+	 */
73
+	public static function getInstanceById(string $instanceId): ExtendedCacheItemPoolInterface
74
+	{
75
+		if (isset(self::$instances[$instanceId])) {
76
+			return self::$instances[$instanceId];
77
+		}
78
+
79
+		throw new PhpfastcacheInstanceNotFoundException(sprintf('Instance ID %s not found', $instanceId));
80
+	}
81
+
82
+	/**
83
+	 * Return the list of instances
84
+	 *
85
+	 * @return ExtendedCacheItemPoolInterface[]
86
+	 */
87
+	public static function getInstances(): array
88
+	{
89
+		return self::$instances;
90
+	}
91
+
92
+	/**
93
+	 * @param string $driver
94
+	 * @param ConfigurationOptionInterface|null $config
95
+	 * @param string|null $instanceId
96
+	 * @return ExtendedCacheItemPoolInterface
97
+	 * @throws PhpfastcacheDriverCheckException
98
+	 * @throws PhpfastcacheDriverException
99
+	 * @throws PhpfastcacheDriverNotFoundException
100
+	 * @throws PhpfastcacheExtensionNotInstalledException
101
+	 * @throws PhpfastcacheLogicException
102
+	 */
103
+	public static function getInstance(string $driver, ?ConfigurationOptionInterface $config = null, ?string $instanceId = null): ExtendedCacheItemPoolInterface
104
+	{
105
+		if (\class_exists($driver) && \str_starts_with($driver, 'Phpfastcache')) {
106
+			$driverClass = $driver;
107
+		} else {
108
+			$driver = self::normalizeDriverName($driver);
109
+			$driverClass = self::getDriverClass($driver);
110
+		}
111
+		$config = self::validateConfig($config);
112
+		$instanceId = $instanceId ?: self::getInstanceHash($driverClass, $config);
113
+
114
+		if (!isset(self::$instances[$instanceId])) {
115
+			if (\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) {
116
+				if (($configClass = $driverClass::getConfigClass()) !== $config::class) {
117
+					$config = new $configClass($config->toArray());
118
+				}
119
+				self::$instances[$instanceId] = new $driverClass(
120
+					$config,
121
+					$instanceId,
122
+					EventManager::getInstance()
123
+				);
124
+			} else {
125
+				try {
126
+					self::$driverExtensions[$driver] = ExtensionManager::getExtension($driver);
127
+					return CacheManager::getInstance($driver, $config, $instanceId);
128
+				} catch (PhpfastcacheExtensionNotFoundException) {
129
+					if (in_array($driver, ExtensionManager::KNOWN_EXTENSION_NAMES, true)) {
130
+						throw new PhpfastcacheExtensionNotInstalledException(sprintf(
131
+							'You requested a driver which is now an extension. Run the following command to solve this issue: %s',
132
+							sprintf('composer install phpfastcache/%s-extension', strtolower($driver))
133
+						));
134
+					}
135
+					throw new PhpfastcacheDriverNotFoundException(sprintf(
136
+						'The driver "%s" does not exist or does not implement %s.',
137
+						$driver,
138
+						ExtendedCacheItemPoolInterface::class,
139
+					));
140
+				}
141
+			}
142
+		}
143
+
144
+		return self::$instances[$instanceId];
145
+	}
146
+
147
+	/**
148
+	 * @param string $driverClass
149
+	 * @param ConfigurationOptionInterface $config
150
+	 * @return string
151
+	 */
152
+	protected static function getInstanceHash(string $driverClass, ConfigurationOptionInterface $config): string
153
+	{
154
+		return \md5($driverClass . \serialize(
155
+			\array_filter(
156
+				$config->toArray(),
157
+				static fn ($val) => $config->isValueSerializable($val)
158
+			)
159
+		));
160
+	}
161
+
162
+	/**
163
+	 * @param ConfigurationOptionInterface|null $config
164
+	 * @return ConfigurationOptionInterface
165
+	 * @throws PhpfastcacheLogicException
166
+	 */
167
+	protected static function validateConfig(?ConfigurationOptionInterface $config): ConfigurationOptionInterface
168
+	{
169
+		if ($config instanceof ConfigurationOptionInterface && $config->isLocked()) {
170
+			throw new PhpfastcacheLogicException('You provided an already locked configuration, cannot continue.');
171
+		}
172
+		return $config ?? self::getDefaultConfig();
173
+	}
174
+
175
+	/**
176
+	 * @return ConfigurationOptionInterface
177
+	 */
178
+	public static function getDefaultConfig(): ConfigurationOptionInterface
179
+	{
180
+		return self::$config ?? self::$config = new ConfigurationOption();
181
+	}
182
+
183
+	/**
184
+	 * @param string $driverName
185
+	 * @return string
186
+	 */
187
+	public static function normalizeDriverName(string $driverName): string
188
+	{
189
+		return \ucfirst(\strtolower(\trim($driverName)));
190
+	}
191
+
192
+	/**
193
+	 * @param string $driverName
194
+	 * @return string
195
+	 */
196
+	public static function getDriverClass(string $driverName): string
197
+	{
198
+		if (!empty(self::$driverExtensions[$driverName])) {
199
+			$driverClass = self::$driverExtensions[$driverName];
200
+		} elseif (!empty(self::$driverCustoms[$driverName])) {
201
+			$driverClass = self::$driverCustoms[$driverName];
202
+		} elseif (!empty(self::$driverOverrides[$driverName])) {
203
+			$driverClass = self::$driverOverrides[$driverName];
204
+		} else {
205
+			$driverClass = self::getNamespacePath() . $driverName . '\Driver';
206
+		}
207
+
208
+		return $driverClass;
209
+	}
210
+
211
+	/**
212
+	 * @return string
213
+	 */
214
+	public static function getNamespacePath(): string
215
+	{
216
+		return self::$namespacePath ?? self::getDefaultNamespacePath();
217
+	}
218
+
219
+	/**
220
+	 * @return string
221
+	 */
222
+	public static function getDefaultNamespacePath(): string
223
+	{
224
+		return self::CORE_DRIVER_NAMESPACE;
225
+	}
226
+
227
+	/**
228
+	 * @return bool
229
+	 */
230
+	public static function clearInstances(): bool
231
+	{
232
+		self::$instances = [];
233
+
234
+		\gc_collect_cycles();
235
+
236
+		return true;
237
+	}
238
+
239
+	/**
240
+	 * @param ExtendedCacheItemPoolInterface $cachePoolInstance
241
+	 * @return bool
242
+	 * @since 7.0.4
243
+	 */
244
+	public static function clearInstance(ExtendedCacheItemPoolInterface $cachePoolInstance): bool
245
+	{
246
+		$found = false;
247
+		self::$instances = \array_filter(
248
+			\array_map(
249
+				static function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInstance, &$found) {
250
+					if (\spl_object_hash($cachePool) === \spl_object_hash($cachePoolInstance)) {
251
+						$found = true;
252
+						return null;
253
+					}
254
+					return $cachePool;
255
+				},
256
+				self::$instances
257
+			)
258
+		);
259
+
260
+		return $found;
261
+	}
262
+
263
+	/**
264
+	 * @param ConfigurationOptionInterface $config
265
+	 * @throws PhpfastcacheInvalidArgumentException
266
+	 */
267
+	public static function setDefaultConfig(ConfigurationOptionInterface $config): void
268
+	{
269
+		if (\is_subclass_of($config, ConfigurationOption::class)) {
270
+			throw new PhpfastcacheInvalidArgumentException('Default configuration cannot be a child class of ConfigurationOption::class');
271
+		}
272
+		self::$config = $config;
273
+	}
274
+
275
+	/**
276
+	 * @param string $driverName
277
+	 * @param string $className
278
+	 * @return void
279
+	 * @throws PhpfastcacheLogicException
280
+	 * @throws PhpfastcacheUnsupportedOperationException
281
+	 * @throws PhpfastcacheInvalidArgumentException
282
+	 */
283
+	public static function addCustomDriver(string $driverName, string $className): void
284
+	{
285
+		$driverName = self::normalizeDriverName($driverName);
286
+
287
+		if (empty($driverName)) {
288
+			throw new PhpfastcacheInvalidArgumentException("Can't add a custom driver because its name is empty");
289
+		}
290
+
291
+		if (!\class_exists($className)) {
292
+			throw new PhpfastcacheInvalidArgumentException(
293
+				\sprintf("Can't add '%s' because the class '%s' does not exist", $driverName, $className)
294
+			);
295
+		}
296
+
297
+		if (!empty(self::$driverCustoms[$driverName])) {
298
+			throw new PhpfastcacheLogicException(\sprintf("Driver '%s' has been already added", $driverName));
299
+		}
300
+
301
+		if (\in_array($driverName, self::getDriverList(), true)) {
302
+			throw new PhpfastcacheLogicException(\sprintf("Driver '%s' is already a part of the Phpfastcache core", $driverName));
303
+		}
304
+
305
+		self::$driverCustoms[$driverName] = $className;
306
+	}
307
+
308
+	/**
309
+	 * @param string $driverName
310
+	 * @return bool
311
+	 */
312
+	public static function customDriverExists(string $driverName): bool
313
+	{
314
+		return isset(self::$driverCustoms[$driverName]);
315
+	}
316
+
317
+	/**
318
+	 * Return the list of available drivers Capitalized
319
+	 * with optional FQCN as key
320
+	 *
321
+	 * @param bool $fqcnAsKey Describe keys with Full Qualified Class Name
322
+	 * @return string[]
323
+	 * @throws PhpfastcacheUnsupportedOperationException
324
+	 */
325
+	public static function getDriverList(bool $fqcnAsKey = false): array
326
+	{
327
+		static $driverList;
328
+
329
+		if (self::getDefaultNamespacePath() === self::getNamespacePath()) {
330
+			if ($driverList === null) {
331
+				$prefix = self::CORE_DRIVER_NAMESPACE;
332
+				$classMap = self::createClassMap(__DIR__ . '/Drivers');
333
+				$driverList = [];
334
+
335
+				foreach (\array_keys($classMap) as $class) {
336
+					$driverList[] = \str_replace($prefix, '', \substr($class, 0, \strrpos($class, '\\')));
337
+				}
338
+
339
+				$driverList = \array_values(\array_unique($driverList));
340
+			}
341
+
342
+			$driverList = \array_merge($driverList, \array_keys(self::$driverCustoms));
343
+
344
+			if ($fqcnAsKey) {
345
+				$realDriverList = [];
346
+				foreach ($driverList as $driverName) {
347
+					$realDriverList[self::getDriverClass($driverName)] = $driverName;
348
+				}
349
+				$driverList = $realDriverList;
350
+			}
351
+
352
+			\asort($driverList);
353
+
354
+			return $driverList;
355
+		}
356
+
357
+		throw new PhpfastcacheUnsupportedOperationException('Cannot get the driver list if the default namespace path has changed.');
358
+	}
359
+
360
+	/**
361
+	 * @param string $driverName
362
+	 * @return void
363
+	 * @throws PhpfastcacheLogicException
364
+	 * @throws PhpfastcacheInvalidArgumentException
365
+	 */
366
+	public static function removeCustomDriver(string $driverName): void
367
+	{
368
+		$driverName = self::normalizeDriverName($driverName);
369
+
370
+		if (empty($driverName)) {
371
+			throw new PhpfastcacheInvalidArgumentException("Can't remove a custom driver because its name is empty");
372
+		}
373
+
374
+		if (!isset(self::$driverCustoms[$driverName])) {
375
+			throw new PhpfastcacheLogicException(\sprintf("Driver '%s' does not exist", $driverName));
376
+		}
377
+
378
+		unset(self::$driverCustoms[$driverName]);
379
+	}
380
+
381
+	/**
382
+	 * @param string $driverName
383
+	 * @param string $className
384
+	 * @return void
385
+	 * @throws PhpfastcacheLogicException
386
+	 * @throws PhpfastcacheUnsupportedOperationException
387
+	 * @throws PhpfastcacheInvalidArgumentException
388
+	 */
389
+	public static function addCoreDriverOverride(string $driverName, string $className): void
390
+	{
391
+		$driverName = self::normalizeDriverName($driverName);
392
+
393
+		if (empty($driverName)) {
394
+			throw new PhpfastcacheInvalidArgumentException("Can't add a core driver override because its name is empty");
395
+		}
396
+
397
+		if (!\class_exists($className)) {
398
+			throw new PhpfastcacheInvalidArgumentException(
399
+				\sprintf("Can't override '%s' because the class '%s' does not exist", $driverName, $className)
400
+			);
401
+		}
402
+
403
+		if (!empty(self::$driverOverrides[$driverName])) {
404
+			throw new PhpfastcacheLogicException(\sprintf("Driver '%s' has been already overridden", $driverName));
405
+		}
406
+
407
+		if (!\in_array($driverName, self::getDriverList(), true)) {
408
+			throw new PhpfastcacheLogicException(\sprintf("Driver '%s' can't be overridden since its not a part of the Phpfastcache core", $driverName));
409
+		}
410
+
411
+		if (!\is_subclass_of($className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver', true)) {
412
+			throw new PhpfastcacheLogicException(
413
+				\sprintf(
414
+					"Can't override '%s' because the class '%s' MUST extend '%s'",
415
+					$driverName,
416
+					$className,
417
+					self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver'
418
+				)
419
+			);
420
+		}
421
+
422
+		self::$driverOverrides[$driverName] = $className;
423
+	}
424
+
425
+	/**
426
+	 * @param string $driverName
427
+	 * @return void
428
+	 * @throws PhpfastcacheLogicException
429
+	 * @throws PhpfastcacheInvalidArgumentException
430
+	 */
431
+	public static function removeCoreDriverOverride(string $driverName): void
432
+	{
433
+		$driverName = self::normalizeDriverName($driverName);
434
+
435
+		if (empty($driverName)) {
436
+			throw new PhpfastcacheInvalidArgumentException("Can't remove a core driver override because its name is empty");
437
+		}
438
+
439
+		if (!isset(self::$driverOverrides[$driverName])) {
440
+			throw new PhpfastcacheLogicException(\sprintf("Driver '%s' were not overridden", $driverName));
441
+		}
442
+
443
+		unset(self::$driverOverrides[$driverName]);
444
+	}
445 445
 }
Please login to merge, or discard this patch.
php/vendor/phpfastcache/phpfastcache/lib/Phpfastcache/CacheContract.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -22,40 +22,40 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Config/ConfigurationOptionInterface.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -22,113 +22,113 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Config/LockableConfigurationInterface.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
phpfastcache/phpfastcache/lib/Phpfastcache/Config/ConfigurationOption.php 1 patch
Indentation   +343 added lines, -343 removed lines patch added patch discarded remove patch
@@ -23,347 +23,347 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
phpfastcache/phpfastcache/lib/Phpfastcache/Config/IOConfigurationOption.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -24,133 +24,133 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.