From bdf9111150366641e07031a3710eddd8893ff6e3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 3 Sep 2024 16:39:56 +0200 Subject: [PATCH] renamed driver classes --- src/Dibi/Connection.php | 17 +++++++++-- .../{DummyDriver.php => Dummy/Connection.php} | 7 +++-- .../{NoDataResult.php => Dummy/Result.php} | 5 ++-- .../FirebirdEngine.php} | 6 ++-- .../MySQLEngine.php} | 6 ++-- .../ODBCEngine.php} | 6 ++-- .../OracleEngine.php} | 6 ++-- .../PostgreSQLEngine.php} | 6 ++-- .../SQLServerEngine.php} | 6 ++-- .../SQLiteEngine.php} | 6 ++-- .../Connection.php} | 13 ++++---- .../Result.php} | 7 +++-- .../Connection.php} | 13 ++++---- .../{MySqliResult.php => MySQLi/Result.php} | 5 ++-- .../{OracleDriver.php => OCI8/Connection.php} | 13 ++++---- .../{OracleResult.php => OCI8/Result.php} | 5 ++-- .../{OdbcDriver.php => ODBC/Connection.php} | 13 ++++---- .../{OdbcResult.php => ODBC/Result.php} | 5 ++-- .../{PdoDriver.php => PDO/Connection.php} | 30 ++++++++++--------- .../Drivers/{PdoResult.php => PDO/Result.php} | 5 ++-- .../Connection.php} | 13 ++++---- .../{PostgreResult.php => PgSQL/Result.php} | 5 ++-- .../Connection.php} | 13 ++++---- .../{SqlsrvResult.php => SQLSrv/Result.php} | 5 ++-- .../Connection.php} | 13 ++++---- .../{SqliteResult.php => SQLite3/Result.php} | 5 ++-- src/Dibi/Drivers/Sqlite3Driver.php | 18 ----------- src/Dibi/Drivers/Sqlite3Result.php | 18 ----------- tests/dibi/Fluent.fetch.limit.mssql.phpt | 8 +++-- tests/dibi/PdoDriver.providedConnection.phpt | 2 +- 30 files changed, 145 insertions(+), 135 deletions(-) rename src/Dibi/Drivers/{DummyDriver.php => Dummy/Connection.php} (94%) rename src/Dibi/Drivers/{NoDataResult.php => Dummy/Result.php} (90%) rename src/Dibi/Drivers/{FirebirdReflector.php => Engines/FirebirdEngine.php} (98%) rename src/Dibi/Drivers/{MySqlReflector.php => Engines/MySQLEngine.php} (96%) rename src/Dibi/Drivers/{OdbcReflector.php => Engines/ODBCEngine.php} (93%) rename src/Dibi/Drivers/{OracleReflector.php => Engines/OracleEngine.php} (92%) rename src/Dibi/Drivers/{PostgreReflector.php => Engines/PostgreSQLEngine.php} (98%) rename src/Dibi/Drivers/{SqlsrvReflector.php => Engines/SQLServerEngine.php} (96%) rename src/Dibi/Drivers/{SqliteReflector.php => Engines/SQLiteEngine.php} (96%) rename src/Dibi/Drivers/{FirebirdDriver.php => Firebird/Connection.php} (95%) rename src/Dibi/Drivers/{FirebirdResult.php => Firebird/Result.php} (94%) rename src/Dibi/Drivers/{MySqliDriver.php => MySQLi/Connection.php} (96%) rename src/Dibi/Drivers/{MySqliResult.php => MySQLi/Result.php} (96%) rename src/Dibi/Drivers/{OracleDriver.php => OCI8/Connection.php} (96%) rename src/Dibi/Drivers/{OracleResult.php => OCI8/Result.php} (96%) rename src/Dibi/Drivers/{OdbcDriver.php => ODBC/Connection.php} (95%) rename src/Dibi/Drivers/{OdbcResult.php => ODBC/Result.php} (96%) rename src/Dibi/Drivers/{PdoDriver.php => PDO/Connection.php} (91%) rename src/Dibi/Drivers/{PdoResult.php => PDO/Result.php} (96%) rename src/Dibi/Drivers/{PostgreDriver.php => PgSQL/Connection.php} (95%) rename src/Dibi/Drivers/{PostgreResult.php => PgSQL/Result.php} (95%) rename src/Dibi/Drivers/{SqlsrvDriver.php => SQLSrv/Connection.php} (95%) rename src/Dibi/Drivers/{SqlsrvResult.php => SQLSrv/Result.php} (95%) rename src/Dibi/Drivers/{SqliteDriver.php => SQLite3/Connection.php} (95%) rename src/Dibi/Drivers/{SqliteResult.php => SQLite3/Result.php} (96%) delete mode 100644 src/Dibi/Drivers/Sqlite3Driver.php delete mode 100644 src/Dibi/Drivers/Sqlite3Result.php diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index 7ec884633..84ab5c069 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -21,6 +21,18 @@ */ class Connection { + private const Drivers = [ + 'firebird' => Drivers\Ibase\Connection::class, + 'mysqli' => Drivers\MySQLi\Connection::class, + 'odbc' => Drivers\ODBC\Connection::class, + 'oracle' => Drivers\OCI8\Connection::class, + 'pdo' => Drivers\PDO\Connection::class, + 'postgre' => Drivers\PgSQL\Connection::class, + 'sqlite3' => Drivers\SQLite3\Connection::class, + 'sqlite' => Drivers\SQLite3\Connection::class, + 'sqlsrv' => Drivers\SQLSrv\Connection::class, + ]; + /** function (Event $event); Occurs after query is executed */ public ?array $onEvent = []; private array $config; @@ -129,8 +141,7 @@ final public function connect(): void $class = $this->config['driver']; } else { - $class = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($this->config['driver']))); - $class = "Dibi\\Drivers\\{$class}Driver"; + $class = self::Drivers[strtolower($this->config['driver'])] ?? throw new Exception("Unknown driver '{$this->config['driver']}'."); if (!class_exists($class)) { throw new Exception("Unable to create instance of Dibi driver '$class'."); } @@ -284,7 +295,7 @@ final public function nativeQuery(#[Language('SQL')] string $sql): Result throw $e; } - $res = $this->createResultSet($res ?: new Drivers\NoDataResult(max(0, $this->driver->getAffectedRows()))); + $res = $this->createResultSet($res ?: new Drivers\Dummy\Result(max(0, $this->driver->getAffectedRows()))); if ($event) { $this->onEvent($event->done($res)); } diff --git a/src/Dibi/Drivers/DummyDriver.php b/src/Dibi/Drivers/Dummy/Connection.php similarity index 94% rename from src/Dibi/Drivers/DummyDriver.php rename to src/Dibi/Drivers/Dummy/Connection.php index 74501d3ad..e4c630c43 100644 --- a/src/Dibi/Drivers/DummyDriver.php +++ b/src/Dibi/Drivers/Dummy/Connection.php @@ -7,15 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Dummy; use Dibi; +use Dibi\Drivers; /** * The dummy driver for testing purposes. */ -class DummyDriver implements Connection, Result, Engine +class Connection implements Drivers\Connection, Drivers\Result, Drivers\Engine { public function disconnect(): void { @@ -64,7 +65,7 @@ public function getResource(): mixed /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { return $this; } diff --git a/src/Dibi/Drivers/NoDataResult.php b/src/Dibi/Drivers/Dummy/Result.php similarity index 90% rename from src/Dibi/Drivers/NoDataResult.php rename to src/Dibi/Drivers/Dummy/Result.php index a8fbea9fd..8e590f964 100644 --- a/src/Dibi/Drivers/NoDataResult.php +++ b/src/Dibi/Drivers/Dummy/Result.php @@ -7,14 +7,15 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Dummy; +use Dibi\Drivers; /** * The driver for no result set. */ -class NoDataResult implements Result +class Result implements Drivers\Result { public function __construct( private int $rows, diff --git a/src/Dibi/Drivers/FirebirdReflector.php b/src/Dibi/Drivers/Engines/FirebirdEngine.php similarity index 98% rename from src/Dibi/Drivers/FirebirdReflector.php rename to src/Dibi/Drivers/Engines/FirebirdEngine.php index 1051d4f4a..ce02fa770 100644 --- a/src/Dibi/Drivers/FirebirdReflector.php +++ b/src/Dibi/Drivers/Engines/FirebirdEngine.php @@ -7,14 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Engines; +use Dibi\Drivers\Connection; +use Dibi\Drivers\Engine; /** * The reflector for Firebird/InterBase database. */ -class FirebirdReflector implements Engine +class FirebirdEngine implements Engine { public function __construct( private Connection $driver, diff --git a/src/Dibi/Drivers/MySqlReflector.php b/src/Dibi/Drivers/Engines/MySQLEngine.php similarity index 96% rename from src/Dibi/Drivers/MySqlReflector.php rename to src/Dibi/Drivers/Engines/MySQLEngine.php index a922e4826..f69cc081b 100644 --- a/src/Dibi/Drivers/MySqlReflector.php +++ b/src/Dibi/Drivers/Engines/MySQLEngine.php @@ -7,16 +7,18 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Engines; use Dibi; +use Dibi\Drivers\Connection; +use Dibi\Drivers\Engine; /** * The reflector for MySQL databases. * @internal */ -class MySqlReflector implements Engine +class MySQLEngine implements Engine { public function __construct( private Connection $driver, diff --git a/src/Dibi/Drivers/OdbcReflector.php b/src/Dibi/Drivers/Engines/ODBCEngine.php similarity index 93% rename from src/Dibi/Drivers/OdbcReflector.php rename to src/Dibi/Drivers/Engines/ODBCEngine.php index 5e7afbc88..3dfd7594f 100644 --- a/src/Dibi/Drivers/OdbcReflector.php +++ b/src/Dibi/Drivers/Engines/ODBCEngine.php @@ -7,15 +7,17 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Engines; use Dibi; +use Dibi\Drivers\Connection; +use Dibi\Drivers\Engine; /** * The reflector for ODBC connections. */ -class OdbcReflector implements Engine +class ODBCEngine implements Engine { public function __construct( private Connection $driver, diff --git a/src/Dibi/Drivers/OracleReflector.php b/src/Dibi/Drivers/Engines/OracleEngine.php similarity index 92% rename from src/Dibi/Drivers/OracleReflector.php rename to src/Dibi/Drivers/Engines/OracleEngine.php index bdfc4788b..db05b0b3c 100644 --- a/src/Dibi/Drivers/OracleReflector.php +++ b/src/Dibi/Drivers/Engines/OracleEngine.php @@ -7,15 +7,17 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Engines; use Dibi; +use Dibi\Drivers\Connection; +use Dibi\Drivers\Engine; /** * The reflector for Oracle database. */ -class OracleReflector implements Engine +class OracleEngine implements Engine { public function __construct( private Connection $driver, diff --git a/src/Dibi/Drivers/PostgreReflector.php b/src/Dibi/Drivers/Engines/PostgreSQLEngine.php similarity index 98% rename from src/Dibi/Drivers/PostgreReflector.php rename to src/Dibi/Drivers/Engines/PostgreSQLEngine.php index ba0531de6..14975cda6 100644 --- a/src/Dibi/Drivers/PostgreReflector.php +++ b/src/Dibi/Drivers/Engines/PostgreSQLEngine.php @@ -7,14 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Engines; +use Dibi\Drivers\Connection; +use Dibi\Drivers\Engine; /** * The reflector for PostgreSQL database. */ -class PostgreReflector implements Engine +class PostgreSQLEngine implements Engine { public function __construct( private Connection $driver, diff --git a/src/Dibi/Drivers/SqlsrvReflector.php b/src/Dibi/Drivers/Engines/SQLServerEngine.php similarity index 96% rename from src/Dibi/Drivers/SqlsrvReflector.php rename to src/Dibi/Drivers/Engines/SQLServerEngine.php index c932568d4..9a9984922 100644 --- a/src/Dibi/Drivers/SqlsrvReflector.php +++ b/src/Dibi/Drivers/Engines/SQLServerEngine.php @@ -7,15 +7,17 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Engines; use Dibi; +use Dibi\Drivers\Connection; +use Dibi\Drivers\Engine; /** * The reflector for Microsoft SQL Server and SQL Azure databases. */ -class SqlsrvReflector implements Engine +class SQLServerEngine implements Engine { public function __construct( private Connection $driver, diff --git a/src/Dibi/Drivers/SqliteReflector.php b/src/Dibi/Drivers/Engines/SQLiteEngine.php similarity index 96% rename from src/Dibi/Drivers/SqliteReflector.php rename to src/Dibi/Drivers/Engines/SQLiteEngine.php index 13c9aff32..8488f1159 100644 --- a/src/Dibi/Drivers/SqliteReflector.php +++ b/src/Dibi/Drivers/Engines/SQLiteEngine.php @@ -7,14 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Engines; +use Dibi\Drivers\Connection; +use Dibi\Drivers\Engine; /** * The reflector for SQLite database. */ -class SqliteReflector implements Engine +class SQLiteEngine implements Engine { public function __construct( private Connection $driver, diff --git a/src/Dibi/Drivers/FirebirdDriver.php b/src/Dibi/Drivers/Firebird/Connection.php similarity index 95% rename from src/Dibi/Drivers/FirebirdDriver.php rename to src/Dibi/Drivers/Firebird/Connection.php index ba7f86dc2..82dae6c00 100644 --- a/src/Dibi/Drivers/FirebirdDriver.php +++ b/src/Dibi/Drivers/Firebird/Connection.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Ibase; use Dibi; +use Dibi\Drivers; use Dibi\Helpers; @@ -24,7 +25,7 @@ * - buffers (int) => buffers is the number of database buffers to allocate for the server-side cache. If 0 or omitted, server chooses its own default. * - resource (resource) => existing connection resource */ -class FirebirdDriver implements Connection +class Connection implements Drivers\Connection { public const ErrorExceptionThrown = -836; @@ -199,9 +200,9 @@ public function getResource(): mixed /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { - return new FirebirdReflector($this); + return new Drivers\Engines\FirebirdEngine($this); } @@ -209,9 +210,9 @@ public function getReflector(): Engine * Result set driver factory. * @param resource $resource */ - public function createResultDriver($resource): FirebirdResult + public function createResultDriver($resource): Result { - return new FirebirdResult($resource); + return new Result($resource); } diff --git a/src/Dibi/Drivers/FirebirdResult.php b/src/Dibi/Drivers/Firebird/Result.php similarity index 94% rename from src/Dibi/Drivers/FirebirdResult.php rename to src/Dibi/Drivers/Firebird/Result.php index f3bf39665..c6f537c26 100644 --- a/src/Dibi/Drivers/FirebirdResult.php +++ b/src/Dibi/Drivers/Firebird/Result.php @@ -7,16 +7,17 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\Ibase; use Dibi; +use Dibi\Drivers; use Dibi\Helpers; /** * The driver for Firebird/InterBase result set. */ -class FirebirdResult implements Result +class Result implements Drivers\Result { public function __construct( /** @var resource */ @@ -45,7 +46,7 @@ public function fetch(bool $assoc): ?array : @ibase_fetch_row($this->resultSet, IBASE_TEXT); // intentionally @ if (ibase_errcode()) { - if (ibase_errcode() === FirebirdDriver::ERROR_EXCEPTION_THROWN) { + if (ibase_errcode() === Connection::ERROR_EXCEPTION_THROWN) { preg_match('/exception (\d+) (\w+) (.*)/is', ibase_errmsg(), $match); throw new Dibi\ProcedureException($match[3], $match[1], $match[2]); diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySQLi/Connection.php similarity index 96% rename from src/Dibi/Drivers/MySqliDriver.php rename to src/Dibi/Drivers/MySQLi/Connection.php index 3bf130df8..35afac930 100644 --- a/src/Dibi/Drivers/MySqliDriver.php +++ b/src/Dibi/Drivers/MySQLi/Connection.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\MySQLi; use Dibi; +use Dibi\Drivers; /** @@ -30,7 +31,7 @@ * - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html * - resource (mysqli) => existing connection resource */ -class MySqliDriver implements Connection +class Connection implements Drivers\Connection { public const ErrorAccessDenied = 1045; public const ErrorDuplicateEntry = 1062; @@ -263,18 +264,18 @@ public function getResource(): ?\mysqli /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { - return new MySqlReflector($this); + return new Drivers\Engines\MySQLEngine($this); } /** * Result set driver factory. */ - public function createResultDriver(\mysqli_result $result): MySqliResult + public function createResultDriver(\mysqli_result $result): Result { - return new MySqliResult($result, $this->buffered); + return new Result($result, $this->buffered); } diff --git a/src/Dibi/Drivers/MySqliResult.php b/src/Dibi/Drivers/MySQLi/Result.php similarity index 96% rename from src/Dibi/Drivers/MySqliResult.php rename to src/Dibi/Drivers/MySQLi/Result.php index 4ad97cfea..a60eeeaf6 100644 --- a/src/Dibi/Drivers/MySqliResult.php +++ b/src/Dibi/Drivers/MySQLi/Result.php @@ -7,15 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\MySQLi; use Dibi; +use Dibi\Drivers; /** * The driver for MySQL result set. */ -class MySqliResult implements Result +class Result implements Drivers\Result { public function __construct( private \mysqli_result $resultSet, diff --git a/src/Dibi/Drivers/OracleDriver.php b/src/Dibi/Drivers/OCI8/Connection.php similarity index 96% rename from src/Dibi/Drivers/OracleDriver.php rename to src/Dibi/Drivers/OCI8/Connection.php index 17ebbabc6..3422d4ac8 100644 --- a/src/Dibi/Drivers/OracleDriver.php +++ b/src/Dibi/Drivers/OCI8/Connection.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\OCI8; use Dibi; +use Dibi\Drivers; /** @@ -25,7 +26,7 @@ * - resource (resource) => existing connection resource * - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect */ -class OracleDriver implements Connection +class Connection implements Drivers\Connection { /** @var resource */ private $connection; @@ -189,9 +190,9 @@ public function getResource(): mixed /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { - return new OracleReflector($this); + return new Drivers\Engines\OracleEngine($this); } @@ -199,9 +200,9 @@ public function getReflector(): Engine * Result set driver factory. * @param resource $resource */ - public function createResultDriver($resource): OracleResult + public function createResultDriver($resource): Result { - return new OracleResult($resource); + return new Result($resource); } diff --git a/src/Dibi/Drivers/OracleResult.php b/src/Dibi/Drivers/OCI8/Result.php similarity index 96% rename from src/Dibi/Drivers/OracleResult.php rename to src/Dibi/Drivers/OCI8/Result.php index 8a96cbca2..5281f3335 100644 --- a/src/Dibi/Drivers/OracleResult.php +++ b/src/Dibi/Drivers/OCI8/Result.php @@ -7,15 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\OCI8; use Dibi; +use Dibi\Drivers; /** * The driver for Oracle result set. */ -class OracleResult implements Result +class Result implements Drivers\Result { public function __construct( /** @var resource */ diff --git a/src/Dibi/Drivers/OdbcDriver.php b/src/Dibi/Drivers/ODBC/Connection.php similarity index 95% rename from src/Dibi/Drivers/OdbcDriver.php rename to src/Dibi/Drivers/ODBC/Connection.php index f1e216e32..65e3c5acd 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/ODBC/Connection.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\ODBC; use Dibi; +use Dibi\Drivers; /** @@ -23,7 +24,7 @@ * - resource (resource) => existing connection resource * - microseconds (bool) => use microseconds in datetime format? */ -class OdbcDriver implements Connection +class Connection implements Drivers\Connection { /** @var resource */ private $connection; @@ -175,9 +176,9 @@ public function getResource(): mixed /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { - return new OdbcReflector($this); + return new Drivers\Engines\ODBCEngine($this); } @@ -185,9 +186,9 @@ public function getReflector(): Engine * Result set driver factory. * @param resource $resource */ - public function createResultDriver($resource): OdbcResult + public function createResultDriver($resource): Result { - return new OdbcResult($resource); + return new Result($resource); } diff --git a/src/Dibi/Drivers/OdbcResult.php b/src/Dibi/Drivers/ODBC/Result.php similarity index 96% rename from src/Dibi/Drivers/OdbcResult.php rename to src/Dibi/Drivers/ODBC/Result.php index 9417272d1..4ec23f7be 100644 --- a/src/Dibi/Drivers/OdbcResult.php +++ b/src/Dibi/Drivers/ODBC/Result.php @@ -7,15 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\ODBC; use Dibi; +use Dibi\Drivers; /** * The driver interacting with result set via ODBC connections. */ -class OdbcResult implements Result +class Result implements Drivers\Result { private int $row = 0; diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PDO/Connection.php similarity index 91% rename from src/Dibi/Drivers/PdoDriver.php rename to src/Dibi/Drivers/PDO/Connection.php index 73c927762..55a790978 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PDO/Connection.php @@ -7,9 +7,11 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\PDO; use Dibi; +use Dibi\Drivers; +use Dibi\Drivers\Engines; use Dibi\Helpers; use PDO; @@ -25,7 +27,7 @@ * - resource (PDO) => existing connection * - version */ -class PdoDriver implements Connection +class Connection implements Drivers\Connection { private ?PDO $connection; private ?int $affectedRows; @@ -96,10 +98,10 @@ public function query(string $sql): ?Result $code ??= 0; $message = "SQLSTATE[$sqlState]: $message"; throw match ($this->driverName) { - 'mysql' => MySqliDriver::createException($message, $code, $sql), - 'oci' => OracleDriver::createException($message, $code, $sql), - 'pgsql' => PostgreDriver::createException($message, $sqlState, $sql), - 'sqlite' => SqliteDriver::createException($message, $code, $sql), + 'mysql' => Drivers\MySQLi\Connection::createException($message, $code, $sql), + 'oci' => Drivers\OCI8\Connection::createException($message, $code, $sql), + 'pgsql' => Drivers\PgSQL\Connection::createException($message, $sqlState, $sql), + 'sqlite' => Drivers\SQLite3\Connection::createException($message, $code, $sql), default => new Dibi\DriverException($message, $code, $sql), }; } @@ -174,14 +176,14 @@ public function getResource(): ?PDO /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { return match ($this->driverName) { - 'mysql' => new MySqlReflector($this), - 'oci' => new OracleReflector($this), - 'pgsql' => new PostgreReflector($this, $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION)), - 'sqlite' => new SqliteReflector($this), - 'mssql', 'dblib', 'sqlsrv' => new SqlsrvReflector($this), + 'mysql' => new Engines\MySQLEngine($this), + 'oci' => new Engines\OracleEngine($this), + 'pgsql' => new Engines\PostgreSQLEngine($this, $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION)), + 'sqlite' => new Engines\SQLiteEngine($this), + 'mssql', 'dblib', 'sqlsrv' => new Engines\SQLServerEngine($this), default => throw new Dibi\NotSupportedException, }; } @@ -190,9 +192,9 @@ public function getReflector(): Engine /** * Result set driver factory. */ - public function createResultDriver(\PDOStatement $result): PdoResult + public function createResultDriver(\PDOStatement $result): Result { - return new PdoResult($result, $this->driverName); + return new Result($result, $this->driverName); } diff --git a/src/Dibi/Drivers/PdoResult.php b/src/Dibi/Drivers/PDO/Result.php similarity index 96% rename from src/Dibi/Drivers/PdoResult.php rename to src/Dibi/Drivers/PDO/Result.php index 2e7fa8410..df758fbfa 100644 --- a/src/Dibi/Drivers/PdoResult.php +++ b/src/Dibi/Drivers/PDO/Result.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\PDO; use Dibi; +use Dibi\Drivers; use Dibi\Helpers; use PDO; @@ -17,7 +18,7 @@ /** * The driver for PDO result set. */ -class PdoResult implements Result +class Result implements Drivers\Result { public function __construct( private ?\PDOStatement $resultSet, diff --git a/src/Dibi/Drivers/PostgreDriver.php b/src/Dibi/Drivers/PgSQL/Connection.php similarity index 95% rename from src/Dibi/Drivers/PostgreDriver.php rename to src/Dibi/Drivers/PgSQL/Connection.php index 9748f8d16..22e7e3b95 100644 --- a/src/Dibi/Drivers/PostgreDriver.php +++ b/src/Dibi/Drivers/PgSQL/Connection.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\PgSQL; use Dibi; +use Dibi\Drivers; use Dibi\Helpers; use PgSql; @@ -26,7 +27,7 @@ * - resource (PgSql\Connection) => existing connection resource * - connect_type (int) => see pg_connect() */ -class PostgreDriver implements Connection +class Connection implements Drivers\Connection { private PgSql\Connection $connection; private ?int $affectedRows; @@ -231,18 +232,18 @@ public function getResource(): PgSql\Connection /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { - return new PostgreReflector($this, pg_parameter_status($this->connection, 'server_version')); + return new Drivers\Engines\PostgreSQLEngine($this, pg_parameter_status($this->connection, 'server_version')); } /** * Result set driver factory. */ - public function createResultDriver(PgSql\Result $resource): PostgreResult + public function createResultDriver(PgSql\Result $resource): Result { - return new PostgreResult($resource); + return new Result($resource); } diff --git a/src/Dibi/Drivers/PostgreResult.php b/src/Dibi/Drivers/PgSQL/Result.php similarity index 95% rename from src/Dibi/Drivers/PostgreResult.php rename to src/Dibi/Drivers/PgSQL/Result.php index 328cdd484..f013a6be8 100644 --- a/src/Dibi/Drivers/PostgreResult.php +++ b/src/Dibi/Drivers/PgSQL/Result.php @@ -7,8 +7,9 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\PgSQL; +use Dibi\Drivers; use Dibi\Helpers; use PgSql; @@ -16,7 +17,7 @@ /** * The driver for PostgreSQL result set. */ -class PostgreResult implements Result +class Result implements Drivers\Result { public function __construct( private PgSql\Result $resultSet, diff --git a/src/Dibi/Drivers/SqlsrvDriver.php b/src/Dibi/Drivers/SQLSrv/Connection.php similarity index 95% rename from src/Dibi/Drivers/SqlsrvDriver.php rename to src/Dibi/Drivers/SQLSrv/Connection.php index efbbd81f0..1bbb6e534 100644 --- a/src/Dibi/Drivers/SqlsrvDriver.php +++ b/src/Dibi/Drivers/SQLSrv/Connection.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\SQLSrv; use Dibi; +use Dibi\Drivers; use Dibi\Helpers; @@ -25,7 +26,7 @@ * - charset => character encoding to set (default is UTF-8) * - resource (resource) => existing connection resource */ -class SqlsrvDriver implements Connection +class Connection implements Drivers\Connection { /** @var resource */ private $connection; @@ -173,9 +174,9 @@ public function getResource(): mixed /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { - return new SqlsrvReflector($this); + return new Drivers\Engines\SQLServerEngine($this); } @@ -183,9 +184,9 @@ public function getReflector(): Engine * Result set driver factory. * @param resource $resource */ - public function createResultDriver($resource): SqlsrvResult + public function createResultDriver($resource): Result { - return new SqlsrvResult($resource); + return new Result($resource); } diff --git a/src/Dibi/Drivers/SqlsrvResult.php b/src/Dibi/Drivers/SQLSrv/Result.php similarity index 95% rename from src/Dibi/Drivers/SqlsrvResult.php rename to src/Dibi/Drivers/SQLSrv/Result.php index 1f692ab01..c69488be5 100644 --- a/src/Dibi/Drivers/SqlsrvResult.php +++ b/src/Dibi/Drivers/SQLSrv/Result.php @@ -7,15 +7,16 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\SQLSrv; use Dibi; +use Dibi\Drivers; /** * The driver for Microsoft SQL Server and SQL Azure result set. */ -class SqlsrvResult implements Result +class Result implements Drivers\Result { public function __construct( /** @var resource */ diff --git a/src/Dibi/Drivers/SqliteDriver.php b/src/Dibi/Drivers/SQLite3/Connection.php similarity index 95% rename from src/Dibi/Drivers/SqliteDriver.php rename to src/Dibi/Drivers/SQLite3/Connection.php index 804ed2569..617564f50 100644 --- a/src/Dibi/Drivers/SqliteDriver.php +++ b/src/Dibi/Drivers/SQLite3/Connection.php @@ -7,9 +7,10 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\SQLite3; use Dibi; +use Dibi\Drivers; use Dibi\Helpers; use SQLite3; @@ -23,7 +24,7 @@ * - formatDateTime => how to format datetime in SQL (@see date) * - resource (SQLite3) => existing connection resource */ -class SqliteDriver implements Connection +class Connection implements Drivers\Connection { private SQLite3 $connection; private string $fmtDate; @@ -177,18 +178,18 @@ public function getResource(): ?SQLite3 /** * Returns the connection reflector. */ - public function getReflector(): Engine + public function getReflector(): Drivers\Engine { - return new SqliteReflector($this); + return new Drivers\Engines\SQLiteEngine($this); } /** * Result set driver factory. */ - public function createResultDriver(\SQLite3Result $result): SqliteResult + public function createResultDriver(\SQLite3Result $result): Result { - return new SqliteResult($result); + return new Result($result); } diff --git a/src/Dibi/Drivers/SqliteResult.php b/src/Dibi/Drivers/SQLite3/Result.php similarity index 96% rename from src/Dibi/Drivers/SqliteResult.php rename to src/Dibi/Drivers/SQLite3/Result.php index ccc324481..ad57b6927 100644 --- a/src/Dibi/Drivers/SqliteResult.php +++ b/src/Dibi/Drivers/SQLite3/Result.php @@ -7,16 +7,17 @@ declare(strict_types=1); -namespace Dibi\Drivers; +namespace Dibi\Drivers\SQLite3; use Dibi; +use Dibi\Drivers; use Dibi\Helpers; /** * The driver for SQLite result set. */ -class SqliteResult implements Result +class Result implements Drivers\Result { public function __construct( private \SQLite3Result $resultSet, diff --git a/src/Dibi/Drivers/Sqlite3Driver.php b/src/Dibi/Drivers/Sqlite3Driver.php deleted file mode 100644 index f3dfa9ede..000000000 --- a/src/Dibi/Drivers/Sqlite3Driver.php +++ /dev/null @@ -1,18 +0,0 @@ -setAttribute(PDO::ATTR_ERRMODE, $errorMode); } - new Dibi\Drivers\PdoDriver(['resource' => $pdo]); + new Dibi\Drivers\PDO\Connection(['resource' => $pdo]); }