Skip to content

Commit c2ec86b

Browse files
committed
Make sure that core driver override actually extends existing core driver
1 parent b946a82 commit c2ec86b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/Phpfastcache/CacheManager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
class CacheManager
5454
{
5555
const AUTOMATIC_DRIVER_CLASS = 'Auto';
56+
const CORE_DRIVER_NAMESPACE = 'Phpfastcache\Drivers\\';
5657

5758
use ClassNamespaceResolverTrait;
5859

@@ -375,7 +376,7 @@ public static function getDriverList(): array
375376

376377
if(self::getDefaultNamespacePath() === self::getNamespacePath()){
377378
if($driverList === null){
378-
$prefix = 'Phpfastcache\Drivers\\';
379+
$prefix = self::CORE_DRIVER_NAMESPACE;
379380
$classMap = self::createClassMap(__DIR__ . '/Drivers');
380381
$driverList = [];
381382

@@ -504,6 +505,12 @@ public static function addCoreDriverOverride(string $driverName, string $classNa
504505
throw new PhpfastcacheLogicException(sprintf("Driver '%s' can't be overridden since its not a part of the PhpFastCache core", $driverName));
505506
}
506507

508+
if(!\is_subclass_of($className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver', true)){
509+
throw new PhpfastcacheLogicException(
510+
sprintf("Can't override '%s' because the class '%s' MUST extend '%s'", $driverName, $className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver')
511+
);
512+
}
513+
507514
self::$driverOverrides[$driverName] = $className;
508515
}
509516

0 commit comments

Comments
 (0)