Skip to content

Commit 4947fa5

Browse files
committed
renamed driver classes
1 parent e08a651 commit 4947fa5

30 files changed

+145
-135
lines changed

src/Dibi/Connection.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
*/
2222
class Connection
2323
{
24+
private const Drivers = [
25+
'firebird' => Drivers\Ibase\Connection::class,
26+
'mysqli' => Drivers\MySQLi\Connection::class,
27+
'odbc' => Drivers\ODBC\Connection::class,
28+
'oracle' => Drivers\OCI8\Connection::class,
29+
'pdo' => Drivers\PDO\Connection::class,
30+
'postgre' => Drivers\PgSQL\Connection::class,
31+
'sqlite3' => Drivers\SQLite3\Connection::class,
32+
'sqlite' => Drivers\SQLite3\Connection::class,
33+
'sqlsrv' => Drivers\SQLSrv\Connection::class,
34+
];
35+
2436
/** function (Event $event); Occurs after query is executed */
2537
public ?array $onEvent = [];
2638
private array $config;
@@ -129,8 +141,7 @@ final public function connect(): void
129141
$class = $this->config['driver'];
130142

131143
} else {
132-
$class = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($this->config['driver'])));
133-
$class = "Dibi\\Drivers\\{$class}Driver";
144+
$class = self::Drivers[strtolower($this->config['driver'])] ?? throw new Exception("Unknown driver '{$this->config['driver']}'.");
134145
if (!class_exists($class)) {
135146
throw new Exception("Unable to create instance of Dibi driver '$class'.");
136147
}
@@ -284,7 +295,7 @@ final public function nativeQuery(#[Language('SQL')] string $sql): Result
284295
throw $e;
285296
}
286297

287-
$res = $this->createResultSet($res ?: new Drivers\NoDataResult(max(0, $this->driver->getAffectedRows())));
298+
$res = $this->createResultSet($res ?: new Drivers\Dummy\Result(max(0, $this->driver->getAffectedRows())));
288299
if ($event) {
289300
$this->onEvent($event->done($res));
290301
}

src/Dibi/Drivers/DummyDriver.php renamed to src/Dibi/Drivers/Dummy/Connection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Dummy;
1111

1212
use Dibi;
13+
use Dibi\Drivers;
1314

1415

1516
/**
1617
* The dummy driver for testing purposes.
1718
*/
18-
class DummyDriver implements Connection, Result, Engine
19+
class Connection implements Drivers\Connection, Drivers\Result, Drivers\Engine
1920
{
2021
public function disconnect(): void
2122
{
@@ -64,7 +65,7 @@ public function getResource(): mixed
6465
/**
6566
* Returns the connection reflector.
6667
*/
67-
public function getReflector(): Engine
68+
public function getReflector(): Drivers\Engine
6869
{
6970
return $this;
7071
}

src/Dibi/Drivers/NoDataResult.php renamed to src/Dibi/Drivers/Dummy/Result.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Dummy;
1111

12+
use Dibi\Drivers;
1213

1314

1415
/**
1516
* The driver for no result set.
1617
*/
17-
class NoDataResult implements Result
18+
class Result implements Drivers\Result
1819
{
1920
public function __construct(
2021
private readonly int $rows,

src/Dibi/Drivers/FirebirdReflector.php renamed to src/Dibi/Drivers/Engines/FirebirdEngine.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Engines;
1111

12+
use Dibi\Drivers\Connection;
13+
use Dibi\Drivers\Engine;
1214

1315

1416
/**
1517
* The reflector for Firebird/InterBase database.
1618
*/
17-
class FirebirdReflector implements Engine
19+
class FirebirdEngine implements Engine
1820
{
1921
public function __construct(
2022
private readonly Connection $driver,

src/Dibi/Drivers/MySqlReflector.php renamed to src/Dibi/Drivers/Engines/MySQLEngine.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Engines;
1111

1212
use Dibi;
13+
use Dibi\Drivers\Connection;
14+
use Dibi\Drivers\Engine;
1315

1416

1517
/**
1618
* The reflector for MySQL databases.
1719
* @internal
1820
*/
19-
class MySqlReflector implements Engine
21+
class MySQLEngine implements Engine
2022
{
2123
public function __construct(
2224
private readonly Connection $driver,

src/Dibi/Drivers/OdbcReflector.php renamed to src/Dibi/Drivers/Engines/ODBCEngine.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Engines;
1111

1212
use Dibi;
13+
use Dibi\Drivers\Connection;
14+
use Dibi\Drivers\Engine;
1315

1416

1517
/**
1618
* The reflector for ODBC connections.
1719
*/
18-
class OdbcReflector implements Engine
20+
class ODBCEngine implements Engine
1921
{
2022
public function __construct(
2123
private readonly Connection $driver,

src/Dibi/Drivers/OracleReflector.php renamed to src/Dibi/Drivers/Engines/OracleEngine.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Engines;
1111

1212
use Dibi;
13+
use Dibi\Drivers\Connection;
14+
use Dibi\Drivers\Engine;
1315

1416

1517
/**
1618
* The reflector for Oracle database.
1719
*/
18-
class OracleReflector implements Engine
20+
class OracleEngine implements Engine
1921
{
2022
public function __construct(
2123
private readonly Connection $driver,

src/Dibi/Drivers/PostgreReflector.php renamed to src/Dibi/Drivers/Engines/PostgreSQLEngine.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Engines;
1111

12+
use Dibi\Drivers\Connection;
13+
use Dibi\Drivers\Engine;
1214

1315

1416
/**
1517
* The reflector for PostgreSQL database.
1618
*/
17-
class PostgreReflector implements Engine
19+
class PostgreSQLEngine implements Engine
1820
{
1921
public function __construct(
2022
private readonly Connection $driver,

src/Dibi/Drivers/SqlsrvReflector.php renamed to src/Dibi/Drivers/Engines/SQLServerEngine.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Engines;
1111

1212
use Dibi;
13+
use Dibi\Drivers\Connection;
14+
use Dibi\Drivers\Engine;
1315

1416

1517
/**
1618
* The reflector for Microsoft SQL Server and SQL Azure databases.
1719
*/
18-
class SqlsrvReflector implements Engine
20+
class SQLServerEngine implements Engine
1921
{
2022
public function __construct(
2123
private readonly Connection $driver,

src/Dibi/Drivers/SqliteReflector.php renamed to src/Dibi/Drivers/Engines/SQLiteEngine.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
declare(strict_types=1);
99

10-
namespace Dibi\Drivers;
10+
namespace Dibi\Drivers\Engines;
1111

12+
use Dibi\Drivers\Connection;
13+
use Dibi\Drivers\Engine;
1214

1315

1416
/**
1517
* The reflector for SQLite database.
1618
*/
17-
class SqliteReflector implements Engine
19+
class SQLiteEngine implements Engine
1820
{
1921
public function __construct(
2022
private readonly Connection $driver,

0 commit comments

Comments
 (0)