Removed ability to use class paths as DSN protocols.

This commit is contained in:
flash 2024-10-16 01:18:10 +00:00
parent 23ba13138e
commit c43b3b56b0
3 changed files with 7 additions and 20 deletions

View file

@ -1 +1 @@
0.2410.51409
0.2410.160117

View file

@ -1,7 +1,7 @@
<?php
// DbTools.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-16
namespace Index\Db;
@ -51,24 +51,14 @@ final class DbTools {
$backend = $backends[$scheme] ?? null;
if(!($backend instanceof DbBackend)) {
$backend = null;
if(array_key_exists($scheme, self::DB_PROTOS))
$name = self::DB_PROTOS[$scheme];
else
$name = str_replace('-', '\\', (string)$scheme);
if(class_exists($name) && is_subclass_of($name, DbBackend::class)) {
$backend = new $name;
$name = get_class($backend);
}
if($backend === null)
if(!array_key_exists($scheme, self::DB_PROTOS))
throw new RuntimeException('No implementation is available for the specified scheme.');
$backend = new (self::DB_PROTOS[$scheme]);
if(!$backend->isAvailable())
throw new RuntimeException('Requested database backend is not available, likely due to missing dependencies.');
$backends[$name] = $backend;
$backends[$scheme] = $backend;
}
return $backend;

View file

@ -1,7 +1,7 @@
<?php
// DbToolsTest.php
// Created: 2021-04-28
// Updated: 2024-10-04
// Updated: 2024-10-16
declare(strict_types=1);
@ -38,9 +38,6 @@ final class DbToolsTest extends TestCase {
$nullDbConn1 = DbTools::create('null:');
$this->assertInstanceOf(NullDbConnection::class, $nullDbConn1);
$nullDbConn2 = DbTools::create('Index-Db-NullDb-NullDbBackend:');
$this->assertInstanceOf(NullDbConnection::class, $nullDbConn2);
$maria = new MariaDbBackend;
$sqlite = new SqliteBackend;