Removed ability to use class paths as Cache DSN protocols.
This commit is contained in:
parent
bc407f4a8a
commit
b4ff61ad96
3 changed files with 10 additions and 23 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.2410.160117
|
0.2410.160124
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// CacheTools.php
|
// CacheTools.php
|
||||||
// Created: 2024-04-10
|
// Created: 2024-04-10
|
||||||
// Updated: 2024-10-02
|
// Updated: 2024-10-16
|
||||||
|
|
||||||
namespace Index\Cache;
|
namespace Index\Cache;
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ use RuntimeException;
|
||||||
* the rest of the URL is described in the documentation of the parseDsn implementation of the respective backend.
|
* the rest of the URL is described in the documentation of the parseDsn implementation of the respective backend.
|
||||||
*
|
*
|
||||||
* The scheme can be a PHP classpath to an implementation of CacheBackend, or any of these aliases:
|
* The scheme can be a PHP classpath to an implementation of CacheBackend, or any of these aliases:
|
||||||
* - `array`, `null`: maps to `ArrayCache\ArrayCacheBackend` or `Index-Cache-ArrayCache-ArrayCacheBackend`, uses a simple array backed cache that doesn't get saved.
|
* - `array`, `null`: maps to `ArrayCache\ArrayCacheBackend`, uses a simple array backed cache that doesn't get saved.
|
||||||
* - `memcached`, `memcache`: maps to `Memcached\MemcachedBackend` or `Index-Cache-Memcached-MemcachedBackend`, provides a backend based on the memcached or memcache extension.
|
* - `memcached`, `memcache`: maps to `Memcached\MemcachedBackend`, provides a backend based on the memcached or memcache extension.
|
||||||
* - `valkey`, `keydb`, `redis`: maps to `Valkey\ValkeyBackend` or `Index-Cache-Valkey-ValkeyBackend`, provides a backend based on the phpredis extension.
|
* - `valkey`, `keydb`, `redis`: maps to `Valkey\ValkeyBackend`, provides a backend based on the phpredis extension.
|
||||||
*
|
*
|
||||||
* Short names are currently hardcoded and cannot be expanded.
|
* Short names are currently hardcoded and cannot be expanded.
|
||||||
*/
|
*/
|
||||||
|
@ -52,24 +52,14 @@ final class CacheTools {
|
||||||
$backend = $backends[$scheme] ?? null;
|
$backend = $backends[$scheme] ?? null;
|
||||||
|
|
||||||
if(!($backend instanceof CacheBackend)) {
|
if(!($backend instanceof CacheBackend)) {
|
||||||
$backend = null;
|
if(!array_key_exists($scheme, self::CACHE_PROTOS))
|
||||||
|
|
||||||
if(array_key_exists($scheme, self::CACHE_PROTOS))
|
|
||||||
$name = self::CACHE_PROTOS[$scheme];
|
|
||||||
else
|
|
||||||
$name = str_replace('-', '\\', (string)$scheme);
|
|
||||||
|
|
||||||
if(class_exists($name) && is_subclass_of($name, CacheBackend::class)) {
|
|
||||||
$backend = new $name;
|
|
||||||
$name = get_class($backend);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($backend === null)
|
|
||||||
throw new RuntimeException('No implementation is available for the specified scheme.');
|
throw new RuntimeException('No implementation is available for the specified scheme.');
|
||||||
|
|
||||||
|
$backend = new (self::CACHE_PROTOS[$scheme]);
|
||||||
if(!$backend->isAvailable())
|
if(!$backend->isAvailable())
|
||||||
throw new RuntimeException('Requested cache backend is not available, likely due to missing dependencies.');
|
throw new RuntimeException('Requested cache backend is not available, likely due to missing dependencies.');
|
||||||
|
|
||||||
$backends[$name] = $backend;
|
$backends[$scheme] = $backend;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $backend;
|
return $backend;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// CacheToolsTest.php
|
// CacheToolsTest.php
|
||||||
// Created: 2024-04-10
|
// Created: 2024-04-10
|
||||||
// Updated: 2024-10-02
|
// Updated: 2024-10-16
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
@ -25,9 +25,6 @@ final class CacheToolsTest extends TestCase {
|
||||||
public function testBasicDSN(): void {
|
public function testBasicDSN(): void {
|
||||||
$arrayCache = CacheTools::create('array:');
|
$arrayCache = CacheTools::create('array:');
|
||||||
$this->assertInstanceOf(ArrayCacheProvider::class, $arrayCache);
|
$this->assertInstanceOf(ArrayCacheProvider::class, $arrayCache);
|
||||||
|
|
||||||
$arrayCache = CacheTools::create('Index-Cache-ArrayCache-ArrayCacheBackend:');
|
|
||||||
$this->assertInstanceOf(ArrayCacheProvider::class, $arrayCache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMemcachedDSN(): void {
|
public function testMemcachedDSN(): void {
|
||||||
|
|
Loading…
Reference in a new issue