Skip to content

Commit d2d19d5

Browse files
committed
PascalCase constants
1 parent 9908f6f commit d2d19d5

16 files changed

+119
-70
lines changed

examples/result-set-data-types.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
// using manual hints
2828
$res = $dibi->query('SELECT * FROM [customers]');
2929

30-
$res->setType('customer_id', Type::INTEGER)
31-
->setType('added', Type::DATETIME)
32-
->setFormat(Type::DATETIME, 'Y-m-d H:i:s');
30+
$res->setType('customer_id', Type::Integer)
31+
->setType('added', Type::DateTime)
32+
->setFormat(Type::DateTime, 'Y-m-d H:i:s');
3333

3434

3535
Tracy\Dumper::dump($res->fetch());

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ $database->query("UPDATE [:blog:items] SET [text]='Hello World'");
608608
Dibi automatically detects the types of query columns and converts fields them to native PHP types. We can also specify the type manually. You can find the possible types in the `Dibi\Type` class.
609609

610610
```php
611-
$result->setType('id', Dibi\Type::INTEGER); // id will be integer
611+
$result->setType('id', Dibi\Type::Integer); // id will be integer
612612
$row = $result->fetch();
613613

614614
is_int($row->id) // true

src/Dibi/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public function __construct(array $config, ?string $name = null)
7474
$this->config = $config;
7575

7676
$this->formats = [
77-
Type::DATE => $this->config['result']['formatDate'],
78-
Type::DATETIME => $this->config['result']['formatDateTime'],
77+
Type::Date => $this->config['result']['formatDate'],
78+
Type::DateTime => $this->config['result']['formatDateTime'],
7979
Type::JSON => $this->config['result']['formatJson'] ?? 'array',
80-
Type::TIME_INTERVAL => $this->config['result']['formatTimeInterval'] ?? null,
80+
Type::TimeInterval => $this->config['result']['formatTimeInterval'] ?? null,
8181
];
8282

8383
// profiler

src/Dibi/Drivers/FirebirdDriver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
*/
2727
class FirebirdDriver implements Dibi\Driver
2828
{
29-
public const ERROR_EXCEPTION_THROWN = -836;
29+
public const ErrorExceptionThrown = -836;
30+
31+
/** @deprecated use FirebirdDriver::ErrorExceptionThrown */
32+
public const ERROR_EXCEPTION_THROWN = self::ErrorExceptionThrown;
3033

3134
/** @var resource */
3235
private $connection;

src/Dibi/Drivers/MySqliDriver.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@
3232
*/
3333
class MySqliDriver implements Dibi\Driver
3434
{
35-
public const ERROR_ACCESS_DENIED = 1045;
36-
public const ERROR_DUPLICATE_ENTRY = 1062;
37-
public const ERROR_DATA_TRUNCATED = 1265;
35+
public const ErrorAccessDenied = 1045;
36+
public const ErrorDuplicateEntry = 1062;
37+
public const ErrorDataTruncated = 1265;
38+
39+
/** @deprecated use MySqliDriver::ErrorAccessDenied */
40+
public const ERROR_ACCESS_DENIED = self::ErrorAccessDenied;
41+
42+
/** @deprecated use MySqliDriver::ErrorDuplicateEntry */
43+
public const ERROR_DUPLICATE_ENTRY = self::ErrorDuplicateEntry;
44+
45+
/** @deprecated use MySqliDriver::ErrorDataTruncated */
46+
public const ERROR_DATA_TRUNCATED = self::ErrorDataTruncated;
3847

3948
private \mysqli $connection;
4049
private bool $buffered = false;

src/Dibi/Drivers/MySqliResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getResultColumns(): array
103103
'table' => $row['orgtable'],
104104
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
105105
'nativetype' => $types[$row['type']] ?? $row['type'],
106-
'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TIME_INTERVAL : null,
106+
'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TimeInterval : null,
107107
'vendor' => $row,
108108
];
109109
}

src/Dibi/Drivers/OracleResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getResultColumns(): array
8080
'name' => oci_field_name($this->resultSet, $i),
8181
'table' => null,
8282
'fullname' => oci_field_name($this->resultSet, $i),
83-
'type' => $type === 'LONG' ? Dibi\Type::TEXT : null,
83+
'type' => $type === 'LONG' ? Dibi\Type::Text : null,
8484
'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type,
8585
];
8686
}

src/Dibi/Drivers/PdoResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getResultColumns(): array
9090
'name' => $row['name'],
9191
'table' => $row['table'],
9292
'nativetype' => $row['native_type'],
93-
'type' => $row['native_type'] === 'TIME' && $this->driverName === 'mysql' ? Dibi\Type::TIME_INTERVAL : null,
93+
'type' => $row['native_type'] === 'TIME' && $this->driverName === 'mysql' ? Dibi\Type::TimeInterval : null,
9494
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
9595
'vendor' => $row,
9696
];

src/Dibi/Fluent.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@
4545
*/
4646
class Fluent implements IDataSource
4747
{
48-
public const REMOVE = false;
48+
public const
49+
AffectedRows = 'a',
50+
Identifier = 'n',
51+
Remove = false;
52+
53+
/** @deprecated use Fluent::Remove */
54+
public const REMOVE = self::Remove;
4955

5056
public static array $masks = [
5157
'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
@@ -140,7 +146,7 @@ public function __call(string $clause, array $args): static
140146
$this->cursor = &$this->clauses[$clause];
141147

142148
// TODO: really delete?
143-
if ($args === [self::REMOVE]) {
149+
if ($args === [self::Remove]) {
144150
$this->cursor = null;
145151
return $this;
146152
}
@@ -156,7 +162,7 @@ public function __call(string $clause, array $args): static
156162
}
157163
} else {
158164
// append to currect flow
159-
if ($args === [self::REMOVE]) {
165+
if ($args === [self::Remove]) {
160166
return $this;
161167
}
162168

@@ -279,15 +285,15 @@ public function setupResult(string $method): static
279285
/**
280286
* Generates and executes SQL query.
281287
* Returns result set or number of affected rows
282-
* @return ($return is \dibi::IDENTIFIER|\dibi::AFFECTED_ROWS ? int : Result)
288+
* @return ($return is self::Identifier|self::AffectedRows ? int : Result)
283289
* @throws Exception
284290
*/
285291
public function execute(?string $return = null): Result|int|null
286292
{
287293
$res = $this->query($this->_export());
288294
return match ($return) {
289-
\dibi::IDENTIFIER => $this->connection->getInsertId(),
290-
\dibi::AFFECTED_ROWS => $this->connection->getAffectedRows(),
295+
self::Identifier => $this->connection->getInsertId(),
296+
self::AffectedRows => $this->connection->getAffectedRows(),
291297
default => $res,
292298
};
293299
}

src/Dibi/Helpers.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ public static function getSuggestion(array $items, string $value): ?string
159159
public static function escape(Driver $driver, $value, string $type): string
160160
{
161161
$types = [
162-
Type::TEXT => 'text',
163-
Type::BINARY => 'binary',
164-
Type::BOOL => 'bool',
165-
Type::DATE => 'date',
166-
Type::DATETIME => 'datetime',
167-
\dibi::IDENTIFIER => 'identifier',
162+
Type::Text => 'text',
163+
Type::Binary => 'binary',
164+
Type::Bool => 'bool',
165+
Type::Date => 'date',
166+
Type::DateTime => 'datetime',
167+
Fluent::Identifier => 'identifier',
168168
];
169169
if (isset($types[$type])) {
170170
return $driver->{'escape' . $types[$type]}($value);
@@ -181,16 +181,16 @@ public static function escape(Driver $driver, $value, string $type): string
181181
public static function detectType(string $type): ?string
182182
{
183183
$patterns = [
184-
'^_' => Type::TEXT, // PostgreSQL arrays
185-
'RANGE$' => Type::TEXT, // PostgreSQL range types
186-
'BYTEA|BLOB|BIN' => Type::BINARY,
187-
'TEXT|CHAR|POINT|INTERVAL|STRING' => Type::TEXT,
188-
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT|^TINY$' => Type::INTEGER,
189-
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => Type::FLOAT,
190-
'^TIME$' => Type::TIME,
191-
'TIME' => Type::DATETIME, // DATETIME, TIMESTAMP
192-
'DATE' => Type::DATE,
193-
'BOOL' => Type::BOOL,
184+
'^_' => Type::Text, // PostgreSQL arrays
185+
'RANGE$' => Type::Text, // PostgreSQL range types
186+
'BYTEA|BLOB|BIN' => Type::Binary,
187+
'TEXT|CHAR|POINT|INTERVAL|STRING' => Type::Text,
188+
'YEAR|BYTE|COUNTER|SERIAL|INT|LONG|SHORT|^TINY$' => Type::Integer,
189+
'CURRENCY|REAL|MONEY|FLOAT|DOUBLE|DECIMAL|NUMERIC|NUMBER' => Type::Float,
190+
'^TIME$' => Type::Time,
191+
'TIME' => Type::DateTime, // DATETIME, TIMESTAMP
192+
'DATE' => Type::Date,
193+
'BOOL' => Type::Bool,
194194
'JSON' => Type::JSON,
195195
];
196196

0 commit comments

Comments
 (0)