Skip to content

Commit

Permalink
Fixed infinite loop with extensions + added help in Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Geolim4 committed Jan 4, 2024
1 parent 8ad5ce0 commit fd6221c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/Phpfastcache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public static function getDriverList(bool $fqcnAsKey = false): array

if (self::getDefaultNamespacePath() === self::getNamespacePath()) {
if ($driverList === null) {
ExtensionManager::autoloadExtensions();
$prefix = self::CORE_DRIVER_NAMESPACE;
$classMap = self::createClassMap(__DIR__ . '/Drivers');
$driverList = [];
Expand Down
10 changes: 8 additions & 2 deletions lib/Phpfastcache/Core/Pool/DriverBaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface
$this->instanceId = $instanceId;

if (!$this->driverCheck()) {
throw new PhpfastcacheDriverCheckException(\sprintf(ExtendedCacheItemPoolInterface::DRIVER_CHECK_FAILURE, $this->getDriverName()));
throw new PhpfastcacheDriverCheckException(
\sprintf(
ExtendedCacheItemPoolInterface::DRIVER_CHECK_FAILURE,
$this->getDriverName(),
$this->getHelp() ? " Additionally, {$this->getHelp()}" : ''
)
);
}
$this->eventManager->dispatch(Event::CACHE_DRIVER_CHECKED, $this);

Expand All @@ -92,7 +98,7 @@ public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface
$this->getDriverName(),
$e->getMessage(),
$e->getLine() ?: 'unknown line',
$e->getFile() ?: 'unknown file'
$e->getFile() ?: 'unknown file',
),
0,
$e
Expand Down
4 changes: 2 additions & 2 deletions lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
interface ExtendedCacheItemPoolInterface extends CacheItemPoolInterface, EventManagerDispatcherInterface, ClassNamespaceResolverInterface, TaggableCacheItemPoolInterface
{
public const DRIVER_CHECK_FAILURE = '%s is not installed or is misconfigured, cannot continue.
Also, please verify the suggested dependencies in composer because as of the V6, 3rd party libraries are no longer required.';
Also, please verify the suggested dependencies in composer because as of the V6, 3rd party libraries are no longer required.%s';

public const DRIVER_CONNECT_FAILURE = '%s failed to connect with the following error message: "%s" line %d in %s';
public const DRIVER_CONNECT_FAILURE = '%s failed to connect with the following error message: "%s" line %d in %s.';

public const DRIVER_KEY_WRAPPER_INDEX = 'k';

Expand Down
7 changes: 7 additions & 0 deletions lib/Phpfastcache/Drivers/Wincache/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public function driverCheck(): bool
return extension_loaded('wincache') && function_exists('wincache_ucache_set');
}

public function getHelp(): string
{
return <<<HELP
Wincache PECL extension is not maintained anymore and has been superseded. Check sourceforge for more informations: https://sourceforge.net/projects/wincache/'
HELP;
}

/**
* @return DriverStatistic
*/
Expand Down
28 changes: 28 additions & 0 deletions tests/Wincache.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <contact@geolim4.com>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/

use Phpfastcache\CacheManager;
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
use Phpfastcache\Tests\Helper\TestHelper;
use Phpfastcache\Drivers\Wincache\Config as WincacheConfig;
use Redis as RedisClient;

chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
$testHelper = new TestHelper('Wincache');

$cacheInstance = CacheManager::getInstance('Wincache', new WincacheConfig());
$testHelper->runCRUDTests($cacheInstance);

$testHelper->terminateTest();

0 comments on commit fd6221c

Please sign in to comment.