17 declare(strict_types=1);
64 public const CORE_DRIVER_NAMESPACE =
'Phpfastcache\Drivers\\';
80 protected static $instances = [];
85 protected static $driverOverrides = [];
90 protected static $driverCustoms = [];
105 public static function getInstanceById(
string $instanceId): ExtendedCacheItemPoolInterface
107 if (isset(self::$instances[$instanceId])) {
108 return self::$instances[$instanceId];
121 return self::$instances;
136 return self::$instances;
151 public static function __callStatic(
string $name, array $arguments): ExtendedCacheItemPoolInterface
153 $options = (\array_key_exists(0, $arguments) && \is_array($arguments) ? $arguments[0] : []);
155 return self::getInstance($name,
$options);
171 public static function getInstance(
string $driver, ?ConfigurationOptionInterface
$config = null, ?
string $instanceId = null): ExtendedCacheItemPoolInterface
174 $driver = self::standardizeDriverName($driver);
176 $instanceId = $instanceId ?:
md5($driver . \serialize(\array_filter(
$config->toArray(),
static function ($val){
177 return !\is_callable($val);
180 if (!isset(self::$instances[$instanceId])) {
181 $driverClass = self::validateDriverClass(self::getDriverClass($driver));
183 if (\class_exists($driverClass)) {
184 $configClass = $driverClass::getConfigClass();
185 self::$instances[$instanceId] =
new $driverClass(
new $configClass(
$config->toArray()), $instanceId);
186 self::$instances[$instanceId]->setEventManager(EventManager::getInstance());
192 return self::$instances[$instanceId];
204 if ($config === null) {
205 $config = self::getDefaultConfig();
207 if (!($config instanceof ConfigurationOption)) {
231 return \ucfirst(\strtolower(\
trim($driverName)));
241 if (!\is_a($driverClass, ExtendedCacheItemPoolInterface::class,
true)) {
244 'Class "%s" does not implement "%s"',
246 ExtendedCacheItemPoolInterface::class
259 if (!empty(self::$driverCustoms[$driverName])) {
260 $driverClass = self::$driverCustoms[$driverName];
262 if (!empty(self::$driverOverrides[$driverName])) {
263 $driverClass = self::$driverOverrides[$driverName];
265 $driverClass = self::getNamespacePath() . $driverName .
'\Driver';
277 return self::$namespacePath ?: self::getDefaultNamespacePath();
285 return self::CORE_DRIVER_NAMESPACE;
293 self::$instances = [];
295 \gc_collect_cycles();
296 return !\count(self::$instances);
304 public static function clearInstance(ExtendedCacheItemPoolInterface $cachePoolInstance): bool
307 self::$instances = \array_filter(
309 static function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInstance, &$found) {
310 if (\spl_object_hash($cachePool) === \spl_object_hash($cachePoolInstance)) {
341 $driverName = self::standardizeDriverName($driverName);
343 if (empty($driverName)) {
347 if (!\class_exists($className)) {
349 \
sprintf(
"Can't add '%s' because the class '%s' does not exists", $driverName, $className)
353 if (!empty(self::$driverCustoms[$driverName])) {
357 if (\in_array($driverName, self::getDriverList(),
true)) {
361 self::$driverCustoms[$driverName] = $className;
376 if (self::getDefaultNamespacePath() === self::getNamespacePath()) {
377 if ($driverList === null) {
378 $prefix = self::CORE_DRIVER_NAMESPACE;
379 $classMap = self::createClassMap(__DIR__ .
'/Drivers');
382 foreach ($classMap as
$class => $file) {
386 $driverList = \array_values(\array_unique($driverList));
389 $driverList = \array_merge($driverList, \array_keys(self::$driverCustoms));
392 $realDriverList = [];
393 foreach ($driverList as $driverName) {
394 $realDriverList[self::getDriverClass($driverName)] = $driverName;
396 $driverList = $realDriverList;
415 $driverName = self::standardizeDriverName($driverName);
417 if (empty($driverName)) {
421 if (!isset(self::$driverCustoms[$driverName])) {
425 unset(self::$driverCustoms[$driverName]);
438 $driverName = self::standardizeDriverName($driverName);
440 if (empty($driverName)) {
444 if (!\class_exists($className)) {
446 \
sprintf(
"Can't override '%s' because the class '%s' does not exists", $driverName, $className)
450 if (!empty(self::$driverOverrides[$driverName])) {
454 if (!\in_array($driverName, self::getDriverList(),
true)) {
458 if (!\is_subclass_of($className, self::CORE_DRIVER_NAMESPACE . $driverName .
'\\Driver',
true)) {
461 "Can't override '%s' because the class '%s' MUST extend '%s'",
464 self::CORE_DRIVER_NAMESPACE . $driverName .
'\\Driver' 469 self::$driverOverrides[$driverName] = $className;
480 $driverName = self::standardizeDriverName($driverName);
482 if (empty($driverName)) {
486 if (!isset(self::$driverOverrides[$driverName])) {
490 unset(self::$driverOverrides[$driverName]);
static addCoreDriverOverride(string $driverName, string $className)
static __callStatic(string $name, array $arguments)
static removeCustomDriver(string $driverName)
if(!$user||!$user->canDelete()) $name
static getInstanceById(string $instanceId)
__construct()
CacheManager constructor.
static setDefaultConfig(ConfigurationOption $config)
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
static removeCoreDriverOverride(string $driverName)
static clearInstance(ExtendedCacheItemPoolInterface $cachePoolInstance)
$config
Advanced site settings, debugging section.
static getInstances()
Return the list of instances.
static & getInternalInstances()
This method is intended for internal use only and should not be used for any external development use...
static addCustomDriver(string $driverName, string $className)
static getInstance(string $driver,?ConfigurationOptionInterface $config=null,?string $instanceId=null)
static validateDriverClass(string $driverClass)
static getNamespacePath()
static standardizeDriverName(string $driverName)
static getDriverClass(string $driverName)
static getDefaultNamespacePath()
static getDriverList(bool $FQCNAsKey=false)
Return the list of available drivers Capitalized with optional FQCN as key.
static validateConfig(?ConfigurationOptionInterface $config)
static getDefaultConfig()