Skip to content

Commit e08a651

Browse files
committed
renamed interfaces (BC break)
Dibi\Driver => Dibi\Drivers\Connection Dibi\ResultDriver => Dibi\Drivers\Result Dibi\Reflector => Dibi\Drivers\Engine
1 parent b3f604e commit e08a651

40 files changed

+284
-254
lines changed

src/Dibi/Connection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Connection
2727

2828
/** @var string[] resultset formats */
2929
private array $formats;
30-
private ?Driver $driver = null;
30+
private ?Drivers\Connection $driver = null;
3131
private ?Translator $translator = null;
3232

3333
/** @var array<string, callable(object): Expression | null> */
@@ -120,12 +120,12 @@ public function __destruct()
120120
*/
121121
final public function connect(): void
122122
{
123-
if ($this->config['driver'] instanceof Driver) {
123+
if ($this->config['driver'] instanceof Drivers\Connection) {
124124
$this->driver = $this->config['driver'];
125125
$this->translator = new Translator($this);
126126
return;
127127

128-
} elseif (is_subclass_of($this->config['driver'], Driver::class)) {
128+
} elseif (is_subclass_of($this->config['driver'], Drivers\Connection::class)) {
129129
$class = $this->config['driver'];
130130

131131
} else {
@@ -196,7 +196,7 @@ final public function getConfig(?string $key = null, $default = null): mixed
196196
/**
197197
* Returns the driver and connects to a database in lazy mode.
198198
*/
199-
final public function getDriver(): Driver
199+
final public function getDriver(): Drivers\Connection
200200
{
201201
if (!$this->driver) {
202202
$this->connect();
@@ -448,7 +448,7 @@ public function transaction(callable $callback): mixed
448448
/**
449449
* Result set factory.
450450
*/
451-
public function createResultSet(ResultDriver $resultDriver): Result
451+
public function createResultSet(Drivers\Result $resultDriver): Result
452452
{
453453
return (new Result($resultDriver, $this->config['result']['normalize'] ?? true))
454454
->setFormats($this->formats);

src/Dibi/Drivers/Connection.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
5+
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Dibi\Drivers;
11+
12+
use Dibi\DriverException;
13+
use Dibi\Exception;
14+
15+
16+
/**
17+
* Database connection driver.
18+
*/
19+
interface Connection
20+
{
21+
/**
22+
* Disconnects from a database.
23+
* @throws Exception
24+
*/
25+
function disconnect(): void;
26+
27+
/**
28+
* Internal: Executes the SQL query.
29+
* @throws DriverException
30+
*/
31+
function query(string $sql): ?Result;
32+
33+
/**
34+
* Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
35+
*/
36+
function getAffectedRows(): ?int;
37+
38+
/**
39+
* Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
40+
*/
41+
function getInsertId(?string $sequence): ?int;
42+
43+
/**
44+
* Begins a transaction (if supported).
45+
* @throws DriverException
46+
*/
47+
function begin(?string $savepoint = null): void;
48+
49+
/**
50+
* Commits statements in a transaction.
51+
* @throws DriverException
52+
*/
53+
function commit(?string $savepoint = null): void;
54+
55+
/**
56+
* Rollback changes in a transaction.
57+
* @throws DriverException
58+
*/
59+
function rollback(?string $savepoint = null): void;
60+
61+
/**
62+
* Returns the connection resource.
63+
*/
64+
function getResource(): mixed;
65+
66+
/**
67+
* Returns the connection reflector.
68+
*/
69+
function getReflector(): Engine;
70+
71+
/**
72+
* Encodes data for use in a SQL statement.
73+
*/
74+
function escapeText(string $value): string;
75+
76+
function escapeBinary(string $value): string;
77+
78+
function escapeIdentifier(string $value): string;
79+
80+
function escapeBool(bool $value): string;
81+
82+
function escapeDate(\DateTimeInterface $value): string;
83+
84+
function escapeDateTime(\DateTimeInterface $value): string;
85+
86+
function escapeDateInterval(\DateInterval $value): string;
87+
88+
/**
89+
* Encodes string for use in a LIKE statement.
90+
*/
91+
function escapeLike(string $value, int $pos): string;
92+
93+
/**
94+
* Injects LIMIT/OFFSET to the SQL query.
95+
*/
96+
function applyLimit(string &$sql, ?int $limit, ?int $offset): void;
97+
}

src/Dibi/Drivers/DummyDriver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
/**
1616
* The dummy driver for testing purposes.
1717
*/
18-
class DummyDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
18+
class DummyDriver implements Connection, Result, Engine
1919
{
2020
public function disconnect(): void
2121
{
2222
}
2323

2424

25-
public function query(string $sql): ?Dibi\ResultDriver
25+
public function query(string $sql): ?Result
2626
{
2727
return null;
2828
}
@@ -64,7 +64,7 @@ public function getResource(): mixed
6464
/**
6565
* Returns the connection reflector.
6666
*/
67-
public function getReflector(): Dibi\Reflector
67+
public function getReflector(): Engine
6868
{
6969
return $this;
7070
}

src/Dibi/Drivers/Engine.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
5+
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Dibi\Drivers;
11+
12+
13+
/**
14+
* Engine-specific behaviors.
15+
*/
16+
interface Engine
17+
{
18+
/**
19+
* Returns list of tables.
20+
* @return array of {name [, (bool) view ]}
21+
*/
22+
function getTables(): array;
23+
24+
/**
25+
* Returns metadata for all columns in a table.
26+
* @return array of {name, nativetype [, table, fullname, (int) size, (bool) nullable, (mixed) default, (bool) autoincrement, (array) vendor ]}
27+
*/
28+
function getColumns(string $table): array;
29+
30+
/**
31+
* Returns metadata for all indexes in a table.
32+
* @return array of {name, (array of names) columns [, (bool) unique, (bool) primary ]}
33+
*/
34+
function getIndexes(string $table): array;
35+
36+
/**
37+
* Returns metadata for all foreign keys in a table.
38+
*/
39+
function getForeignKeys(string $table): array;
40+
}

src/Dibi/Drivers/FirebirdDriver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* - 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.
2525
* - resource (resource) => existing connection resource
2626
*/
27-
class FirebirdDriver implements Dibi\Driver
27+
class FirebirdDriver implements Connection
2828
{
2929
public const ErrorExceptionThrown = -836;
3030

@@ -85,7 +85,7 @@ public function disconnect(): void
8585
* Executes the SQL query.
8686
* @throws Dibi\DriverException|Dibi\Exception
8787
*/
88-
public function query(string $sql): ?Dibi\ResultDriver
88+
public function query(string $sql): ?Result
8989
{
9090
$resource = $this->inTransaction
9191
? $this->transaction
@@ -199,7 +199,7 @@ public function getResource(): mixed
199199
/**
200200
* Returns the connection reflector.
201201
*/
202-
public function getReflector(): Dibi\Reflector
202+
public function getReflector(): Engine
203203
{
204204
return new FirebirdReflector($this);
205205
}

src/Dibi/Drivers/FirebirdReflector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99

1010
namespace Dibi\Drivers;
1111

12-
use Dibi;
1312

1413

1514
/**
1615
* The reflector for Firebird/InterBase database.
1716
*/
18-
class FirebirdReflector implements Dibi\Reflector
17+
class FirebirdReflector implements Engine
1918
{
2019
public function __construct(
21-
private readonly Dibi\Driver $driver,
20+
private readonly Connection $driver,
2221
) {
2322
}
2423

src/Dibi/Drivers/FirebirdResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* The driver for Firebird/InterBase result set.
1818
*/
19-
class FirebirdResult implements Dibi\ResultDriver
19+
class FirebirdResult implements Result
2020
{
2121
public function __construct(
2222
/** @var resource */

src/Dibi/Drivers/MySqlReflector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* The reflector for MySQL databases.
1717
* @internal
1818
*/
19-
class MySqlReflector implements Dibi\Reflector
19+
class MySqlReflector implements Engine
2020
{
2121
public function __construct(
22-
private readonly Dibi\Driver $driver,
22+
private readonly Connection $driver,
2323
) {
2424
}
2525

src/Dibi/Drivers/MySqliDriver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
3131
* - resource (mysqli) => existing connection resource
3232
*/
33-
class MySqliDriver implements Dibi\Driver
33+
class MySqliDriver implements Connection
3434
{
3535
public const ErrorAccessDenied = 1045;
3636
public const ErrorDuplicateEntry = 1062;
@@ -146,7 +146,7 @@ public function ping(): bool
146146
* Executes the SQL query.
147147
* @throws Dibi\DriverException
148148
*/
149-
public function query(string $sql): ?Dibi\ResultDriver
149+
public function query(string $sql): ?Result
150150
{
151151
$res = @$this->connection->query($sql, $this->buffered ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT); // intentionally @
152152

@@ -263,7 +263,7 @@ public function getResource(): ?\mysqli
263263
/**
264264
* Returns the connection reflector.
265265
*/
266-
public function getReflector(): Dibi\Reflector
266+
public function getReflector(): Engine
267267
{
268268
return new MySqlReflector($this);
269269
}

src/Dibi/Drivers/MySqliResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* The driver for MySQL result set.
1717
*/
18-
class MySqliResult implements Dibi\ResultDriver
18+
class MySqliResult implements Result
1919
{
2020
public function __construct(
2121
private readonly \mysqli_result $resultSet,

0 commit comments

Comments
 (0)