mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
added property typehints
This commit is contained in:
@@ -19,11 +19,8 @@ use Tracy;
|
|||||||
*/
|
*/
|
||||||
class DibiExtension22 extends Nette\DI\CompilerExtension
|
class DibiExtension22 extends Nette\DI\CompilerExtension
|
||||||
{
|
{
|
||||||
/** @var bool|null */
|
private ?bool $debugMode;
|
||||||
private $debugMode;
|
private ?bool $cliMode;
|
||||||
|
|
||||||
/** @var bool|null */
|
|
||||||
private $cliMode;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(?bool $debugMode = null, ?bool $cliMode = null)
|
public function __construct(?bool $debugMode = null, ?bool $cliMode = null)
|
||||||
|
@@ -20,17 +20,10 @@ use Tracy;
|
|||||||
*/
|
*/
|
||||||
class Panel implements Tracy\IBarPanel
|
class Panel implements Tracy\IBarPanel
|
||||||
{
|
{
|
||||||
/** @var int maximum SQL length */
|
public static int $maxLength = 1000;
|
||||||
public static $maxLength = 1000;
|
public bool|string $explain;
|
||||||
|
public int $filter;
|
||||||
/** @var bool|string explain queries? */
|
private array $events = [];
|
||||||
public $explain;
|
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
public $filter;
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $events = [];
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct($explain = true, ?int $filter = null)
|
public function __construct($explain = true, ?int $filter = null)
|
||||||
|
@@ -20,25 +20,16 @@ use Traversable;
|
|||||||
*/
|
*/
|
||||||
class Connection implements IConnection
|
class Connection implements IConnection
|
||||||
{
|
{
|
||||||
/** @var array of function (Event $event); Occurs after query is executed */
|
/** function (Event $event); Occurs after query is executed */
|
||||||
public $onEvent = [];
|
public ?array $onEvent = [];
|
||||||
|
private array $config;
|
||||||
/** @var array Current connection configuration */
|
|
||||||
private $config;
|
|
||||||
|
|
||||||
/** @var string[] resultset formats */
|
/** @var string[] resultset formats */
|
||||||
private $formats;
|
private array $formats;
|
||||||
|
private ?Driver $driver = null;
|
||||||
/** @var Driver|null */
|
private ?Translator $translator = null;
|
||||||
private $driver;
|
private HashMap $substitutes;
|
||||||
|
private int $transactionDepth = 0;
|
||||||
/** @var Translator|null */
|
|
||||||
private $translator;
|
|
||||||
|
|
||||||
/** @var HashMap Substitutes for identifiers */
|
|
||||||
private $substitutes;
|
|
||||||
|
|
||||||
private $transactionDepth = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -15,35 +15,16 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
class DataSource implements IDataSource
|
class DataSource implements IDataSource
|
||||||
{
|
{
|
||||||
/** @var Connection */
|
private Connection $connection;
|
||||||
private $connection;
|
private string $sql;
|
||||||
|
private ?Result $result = null;
|
||||||
/** @var string */
|
private ?int $count = null;
|
||||||
private $sql;
|
private ?int $totalCount = null;
|
||||||
|
private array $cols = [];
|
||||||
/** @var Result|null */
|
private array $sorting = [];
|
||||||
private $result;
|
private array $conds = [];
|
||||||
|
private ?int $offset = null;
|
||||||
/** @var int|null */
|
private ?int $limit = null;
|
||||||
private $count;
|
|
||||||
|
|
||||||
/** @var int|null */
|
|
||||||
private $totalCount;
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $cols = [];
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $sorting = [];
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $conds = [];
|
|
||||||
|
|
||||||
/** @var int|null */
|
|
||||||
private $offset;
|
|
||||||
|
|
||||||
/** @var int|null */
|
|
||||||
private $limit;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -31,11 +31,9 @@ class FirebirdDriver implements Dibi\Driver
|
|||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
|
||||||
/** @var resource|null */
|
/** @var ?resource */
|
||||||
private $transaction;
|
private $transaction;
|
||||||
|
private bool $inTransaction = false;
|
||||||
/** @var bool */
|
|
||||||
private $inTransaction = false;
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
|
@@ -17,8 +17,7 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class FirebirdReflector implements Dibi\Reflector
|
class FirebirdReflector implements Dibi\Reflector
|
||||||
{
|
{
|
||||||
/** @var Dibi\Driver */
|
private Dibi\Driver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Driver $driver)
|
public function __construct(Dibi\Driver $driver)
|
||||||
|
@@ -18,8 +18,7 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class MySqlReflector implements Dibi\Reflector
|
class MySqlReflector implements Dibi\Reflector
|
||||||
{
|
{
|
||||||
/** @var Dibi\Driver */
|
private Dibi\Driver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Driver $driver)
|
public function __construct(Dibi\Driver $driver)
|
||||||
|
@@ -33,16 +33,11 @@ use Dibi;
|
|||||||
class MySqliDriver implements Dibi\Driver
|
class MySqliDriver implements Dibi\Driver
|
||||||
{
|
{
|
||||||
public const ERROR_ACCESS_DENIED = 1045;
|
public const ERROR_ACCESS_DENIED = 1045;
|
||||||
|
|
||||||
public const ERROR_DUPLICATE_ENTRY = 1062;
|
public const ERROR_DUPLICATE_ENTRY = 1062;
|
||||||
|
|
||||||
public const ERROR_DATA_TRUNCATED = 1265;
|
public const ERROR_DATA_TRUNCATED = 1265;
|
||||||
|
|
||||||
/** @var \mysqli */
|
private \mysqli $connection;
|
||||||
private $connection;
|
private bool $buffered = false;
|
||||||
|
|
||||||
/** @var bool Is buffered (seekable and countable)? */
|
|
||||||
private $buffered;
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
|
@@ -17,11 +17,8 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class MySqliResult implements Dibi\ResultDriver
|
class MySqliResult implements Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
/** @var \mysqli_result */
|
private \mysqli_result $resultSet;
|
||||||
private $resultSet;
|
private bool $buffered;
|
||||||
|
|
||||||
/** @var bool Is buffered (seekable and countable)? */
|
|
||||||
private $buffered;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(\mysqli_result $resultSet, bool $buffered)
|
public function __construct(\mysqli_result $resultSet, bool $buffered)
|
||||||
|
@@ -17,8 +17,7 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class NoDataResult implements Dibi\ResultDriver
|
class NoDataResult implements Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
/** @var int */
|
private int $rows;
|
||||||
private $rows;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(int $rows)
|
public function __construct(int $rows)
|
||||||
|
@@ -27,12 +27,8 @@ class OdbcDriver implements Dibi\Driver
|
|||||||
{
|
{
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
private ?int $affectedRows;
|
||||||
/** @var int|null Affected rows */
|
private bool $microseconds = true;
|
||||||
private $affectedRows;
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
private $microseconds = true;
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
|
@@ -17,8 +17,7 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class OdbcReflector implements Dibi\Reflector
|
class OdbcReflector implements Dibi\Reflector
|
||||||
{
|
{
|
||||||
/** @var Dibi\Driver */
|
private Dibi\Driver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Driver $driver)
|
public function __construct(Dibi\Driver $driver)
|
||||||
|
@@ -19,9 +19,7 @@ class OdbcResult implements Dibi\ResultDriver
|
|||||||
{
|
{
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $resultSet;
|
private $resultSet;
|
||||||
|
private int $row = 0;
|
||||||
/** @var int Cursor */
|
|
||||||
private $row = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -29,15 +29,9 @@ class OracleDriver implements Dibi\Driver
|
|||||||
{
|
{
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
private bool $autocommit = true;
|
||||||
/** @var bool */
|
private bool $nativeDate;
|
||||||
private $autocommit = true;
|
private ?int $affectedRows;
|
||||||
|
|
||||||
/** @var bool use native datetime format */
|
|
||||||
private $nativeDate;
|
|
||||||
|
|
||||||
/** @var int|null Number of affected rows */
|
|
||||||
private $affectedRows;
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
|
@@ -17,8 +17,7 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class OracleReflector implements Dibi\Reflector
|
class OracleReflector implements Dibi\Reflector
|
||||||
{
|
{
|
||||||
/** @var Dibi\Driver */
|
private Dibi\Driver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Driver $driver)
|
public function __construct(Dibi\Driver $driver)
|
||||||
|
@@ -27,17 +27,10 @@ use PDO;
|
|||||||
*/
|
*/
|
||||||
class PdoDriver implements Dibi\Driver
|
class PdoDriver implements Dibi\Driver
|
||||||
{
|
{
|
||||||
/** @var PDO|null Connection resource */
|
private ?PDO $connection;
|
||||||
private $connection;
|
private ?int $affectedRows;
|
||||||
|
private string $driverName;
|
||||||
/** @var int|null Affected rows */
|
private string $serverVersion = '';
|
||||||
private $affectedRows;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $driverName;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $serverVersion = '';
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
|
@@ -19,11 +19,8 @@ use PDO;
|
|||||||
*/
|
*/
|
||||||
class PdoResult implements Dibi\ResultDriver
|
class PdoResult implements Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
/** @var \PDOStatement|null */
|
private ?\PDOStatement $resultSet;
|
||||||
private $resultSet;
|
private string $driverName;
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $driverName;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(\PDOStatement $resultSet, string $driverName)
|
public function __construct(\PDOStatement $resultSet, string $driverName)
|
||||||
|
@@ -30,9 +30,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
{
|
{
|
||||||
/** @var resource|PgSql\Connection */
|
/** @var resource|PgSql\Connection */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
private ?int $affectedRows;
|
||||||
/** @var int|null Affected rows */
|
|
||||||
private $affectedRows;
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
@@ -138,7 +136,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
$message = substr($message, strlen($m[0]));
|
$message = substr($message, strlen($m[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($code === '0A000' && strpos($message, 'truncate') !== false) {
|
if ($code === '0A000' && str_contains($message, 'truncate')) {
|
||||||
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif ($code === '23502') {
|
} elseif ($code === '23502') {
|
||||||
|
@@ -17,11 +17,8 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class PostgreReflector implements Dibi\Reflector
|
class PostgreReflector implements Dibi\Reflector
|
||||||
{
|
{
|
||||||
/** @var Dibi\Driver */
|
private Dibi\Driver $driver;
|
||||||
private $driver;
|
private string $version;
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $version;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Driver $driver, string $version)
|
public function __construct(Dibi\Driver $driver, string $version)
|
||||||
|
@@ -25,14 +25,9 @@ use SQLite3;
|
|||||||
*/
|
*/
|
||||||
class SqliteDriver implements Dibi\Driver
|
class SqliteDriver implements Dibi\Driver
|
||||||
{
|
{
|
||||||
/** @var SQLite3 */
|
private SQLite3 $connection;
|
||||||
private $connection;
|
private string $fmtDate;
|
||||||
|
private string $fmtDateTime;
|
||||||
/** @var string Date format */
|
|
||||||
private $fmtDate;
|
|
||||||
|
|
||||||
/** @var string Datetime format */
|
|
||||||
private $fmtDateTime;
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
@@ -100,19 +95,19 @@ class SqliteDriver implements Dibi\Driver
|
|||||||
if ($code !== 19) {
|
if ($code !== 19) {
|
||||||
return new Dibi\DriverException($message, $code, $sql);
|
return new Dibi\DriverException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (strpos($message, 'must be unique') !== false
|
} elseif (str_contains($message, 'must be unique')
|
||||||
|| strpos($message, 'is not unique') !== false
|
|| str_contains($message, 'is not unique')
|
||||||
|| strpos($message, 'UNIQUE constraint failed') !== false
|
|| str_contains($message, 'UNIQUE constraint failed')
|
||||||
) {
|
) {
|
||||||
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
return new Dibi\UniqueConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (strpos($message, 'may not be null') !== false
|
} elseif (str_contains($message, 'may not be null')
|
||||||
|| strpos($message, 'NOT NULL constraint failed') !== false
|
|| str_contains($message, 'NOT NULL constraint failed')
|
||||||
) {
|
) {
|
||||||
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
return new Dibi\NotNullConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
} elseif (strpos($message, 'foreign key constraint failed') !== false
|
} elseif (str_contains($message, 'foreign key constraint failed')
|
||||||
|| strpos($message, 'FOREIGN KEY constraint failed') !== false
|
|| str_contains($message, 'FOREIGN KEY constraint failed')
|
||||||
) {
|
) {
|
||||||
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
|
||||||
|
|
||||||
|
@@ -17,8 +17,7 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class SqliteReflector implements Dibi\Reflector
|
class SqliteReflector implements Dibi\Reflector
|
||||||
{
|
{
|
||||||
/** @var Dibi\Driver */
|
private Dibi\Driver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Driver $driver)
|
public function __construct(Dibi\Driver $driver)
|
||||||
|
@@ -18,8 +18,7 @@ use Dibi\Helpers;
|
|||||||
*/
|
*/
|
||||||
class SqliteResult implements Dibi\ResultDriver
|
class SqliteResult implements Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
/** @var \SQLite3Result */
|
private \SQLite3Result $resultSet;
|
||||||
private $resultSet;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(\SQLite3Result $resultSet)
|
public function __construct(\SQLite3Result $resultSet)
|
||||||
|
@@ -29,12 +29,8 @@ class SqlsrvDriver implements Dibi\Driver
|
|||||||
{
|
{
|
||||||
/** @var resource */
|
/** @var resource */
|
||||||
private $connection;
|
private $connection;
|
||||||
|
private ?int $affectedRows;
|
||||||
/** @var int|null Affected rows */
|
private string $version = '';
|
||||||
private $affectedRows;
|
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $version = '';
|
|
||||||
|
|
||||||
|
|
||||||
/** @throws Dibi\NotSupportedException */
|
/** @throws Dibi\NotSupportedException */
|
||||||
|
@@ -17,8 +17,7 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class SqlsrvReflector implements Dibi\Reflector
|
class SqlsrvReflector implements Dibi\Reflector
|
||||||
{
|
{
|
||||||
/** @var Dibi\Driver */
|
private Dibi\Driver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Driver $driver)
|
public function __construct(Dibi\Driver $driver)
|
||||||
|
@@ -29,26 +29,13 @@ class Event
|
|||||||
TRANSACTION = 448, // BEGIN | COMMIT | ROLLBACK
|
TRANSACTION = 448, // BEGIN | COMMIT | ROLLBACK
|
||||||
ALL = 1023;
|
ALL = 1023;
|
||||||
|
|
||||||
/** @var Connection */
|
public Connection $connection;
|
||||||
public $connection;
|
public int $type;
|
||||||
|
public string $sql;
|
||||||
/** @var int */
|
public Result|DriverException|null $result;
|
||||||
public $type;
|
public float $time;
|
||||||
|
public ?int $count = null;
|
||||||
/** @var string */
|
public ?array $source = null;
|
||||||
public $sql;
|
|
||||||
|
|
||||||
/** @var Result|DriverException|null */
|
|
||||||
public $result;
|
|
||||||
|
|
||||||
/** @var float */
|
|
||||||
public $time;
|
|
||||||
|
|
||||||
/** @var int|null */
|
|
||||||
public $count;
|
|
||||||
|
|
||||||
/** @var array|null */
|
|
||||||
public $source;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Connection $connection, int $type, ?string $sql = null)
|
public function __construct(Connection $connection, int $type, ?string $sql = null)
|
||||||
|
@@ -15,8 +15,7 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
class Expression
|
class Expression
|
||||||
{
|
{
|
||||||
/** @var array */
|
private array $values;
|
||||||
private $values;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(...$values)
|
public function __construct(...$values)
|
||||||
|
@@ -47,8 +47,7 @@ class Fluent implements IDataSource
|
|||||||
{
|
{
|
||||||
public const REMOVE = false;
|
public const REMOVE = false;
|
||||||
|
|
||||||
/** @var array */
|
public static array $masks = [
|
||||||
public static $masks = [
|
|
||||||
'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
|
'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
|
||||||
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', ],
|
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', ],
|
||||||
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
|
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
|
||||||
@@ -56,8 +55,8 @@ class Fluent implements IDataSource
|
|||||||
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
|
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array default modifiers for arrays */
|
/** default modifiers for arrays */
|
||||||
public static $modifiers = [
|
public static array $modifiers = [
|
||||||
'SELECT' => '%n',
|
'SELECT' => '%n',
|
||||||
'FROM' => '%n',
|
'FROM' => '%n',
|
||||||
'IN' => '%in',
|
'IN' => '%in',
|
||||||
@@ -69,8 +68,8 @@ class Fluent implements IDataSource
|
|||||||
'GROUP BY' => '%by',
|
'GROUP BY' => '%by',
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array clauses separators */
|
/** clauses separators */
|
||||||
public static $separators = [
|
public static array $separators = [
|
||||||
'SELECT' => ',',
|
'SELECT' => ',',
|
||||||
'FROM' => ',',
|
'FROM' => ',',
|
||||||
'WHERE' => 'AND',
|
'WHERE' => 'AND',
|
||||||
@@ -84,41 +83,30 @@ class Fluent implements IDataSource
|
|||||||
'INTO' => false,
|
'INTO' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var array clauses */
|
/** clauses */
|
||||||
public static $clauseSwitches = [
|
public static array $clauseSwitches = [
|
||||||
'JOIN' => 'FROM',
|
'JOIN' => 'FROM',
|
||||||
'INNER JOIN' => 'FROM',
|
'INNER JOIN' => 'FROM',
|
||||||
'LEFT JOIN' => 'FROM',
|
'LEFT JOIN' => 'FROM',
|
||||||
'RIGHT JOIN' => 'FROM',
|
'RIGHT JOIN' => 'FROM',
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var Connection */
|
private Connection $connection;
|
||||||
private $connection;
|
private array $setups = [];
|
||||||
|
private ?string $command = null;
|
||||||
/** @var array */
|
private array $clauses = [];
|
||||||
private $setups = [];
|
private array $flags = [];
|
||||||
|
|
||||||
/** @var string|null */
|
|
||||||
private $command;
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $clauses = [];
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $flags = [];
|
|
||||||
|
|
||||||
/** @var array|null */
|
|
||||||
private $cursor;
|
private $cursor;
|
||||||
|
|
||||||
/** @var HashMap normalized clauses */
|
/** normalized clauses */
|
||||||
private static $normalizer;
|
private static HashMap $normalizer;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Connection $connection)
|
public function __construct(Connection $connection)
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
|
|
||||||
if (self::$normalizer === null) {
|
if (!isset(self::$normalizer)) {
|
||||||
self::$normalizer = new HashMap([self::class, '_formatClause']);
|
self::$normalizer = new HashMap([self::class, '_formatClause']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,8 +12,7 @@ namespace Dibi;
|
|||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
/** @var HashMap */
|
private static HashMap $types;
|
||||||
private static $types;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,7 +208,7 @@ class Helpers
|
|||||||
/** @internal */
|
/** @internal */
|
||||||
public static function getTypeCache(): HashMap
|
public static function getTypeCache(): HashMap
|
||||||
{
|
{
|
||||||
if (self::$types === null) {
|
if (!isset(self::$types)) {
|
||||||
self::$types = new HashMap([self::class, 'detectType']);
|
self::$types = new HashMap([self::class, 'detectType']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,8 +15,7 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
class Literal
|
class Literal
|
||||||
{
|
{
|
||||||
/** @var string */
|
private string $value;
|
||||||
private $value;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct($value)
|
public function __construct($value)
|
||||||
|
@@ -17,14 +17,10 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class FileLogger
|
class FileLogger
|
||||||
{
|
{
|
||||||
/** @var string Name of the file where SQL errors should be logged */
|
/** Name of the file where SQL errors should be logged */
|
||||||
public $file;
|
public string $file;
|
||||||
|
public int $filter;
|
||||||
/** @var int */
|
private bool $errorsOnly;
|
||||||
public $filter;
|
|
||||||
|
|
||||||
/** @var bool */
|
|
||||||
private $errorsOnly;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $file, ?int $filter = null, bool $errorsOnly = false)
|
public function __construct(string $file, ?int $filter = null, bool $errorsOnly = false)
|
||||||
|
@@ -27,11 +27,11 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class Column
|
class Column
|
||||||
{
|
{
|
||||||
/** @var Dibi\Reflector|null when created by Result */
|
/** when created by Result */
|
||||||
private $reflector;
|
private ?Dibi\Reflector $reflector;
|
||||||
|
|
||||||
/** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */
|
/** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */
|
||||||
private $info;
|
private array $info;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(?Dibi\Reflector $reflector, array $info)
|
public function __construct(?Dibi\Reflector $reflector, array $info)
|
||||||
|
@@ -21,14 +21,11 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
/** @var Dibi\Reflector */
|
private Dibi\Reflector $reflector;
|
||||||
private $reflector;
|
private ?string $name;
|
||||||
|
|
||||||
/** @var string|null */
|
/** @var Table[] */
|
||||||
private $name;
|
private array $tables;
|
||||||
|
|
||||||
/** @var Table[]|null */
|
|
||||||
private $tables;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Reflector $reflector, ?string $name = null)
|
public function __construct(Dibi\Reflector $reflector, ?string $name = null)
|
||||||
@@ -87,7 +84,7 @@ class Database
|
|||||||
|
|
||||||
protected function init(): void
|
protected function init(): void
|
||||||
{
|
{
|
||||||
if ($this->tables === null) {
|
if (!isset($this->tables)) {
|
||||||
$this->tables = [];
|
$this->tables = [];
|
||||||
foreach ($this->reflector->getTables() as $info) {
|
foreach ($this->reflector->getTables() as $info) {
|
||||||
$this->tables[strtolower($info['name'])] = new Table($this->reflector, $info);
|
$this->tables[strtolower($info['name'])] = new Table($this->reflector, $info);
|
||||||
|
@@ -19,11 +19,10 @@ namespace Dibi\Reflection;
|
|||||||
*/
|
*/
|
||||||
class ForeignKey
|
class ForeignKey
|
||||||
{
|
{
|
||||||
/** @var string */
|
private string $name;
|
||||||
private $name;
|
|
||||||
|
|
||||||
/** @var array of [local, foreign, onDelete, onUpdate] */
|
/** @var array of [local, foreign, onDelete, onUpdate] */
|
||||||
private $references;
|
private array $references;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(string $name, array $references)
|
public function __construct(string $name, array $references)
|
||||||
|
@@ -22,7 +22,7 @@ namespace Dibi\Reflection;
|
|||||||
class Index
|
class Index
|
||||||
{
|
{
|
||||||
/** @var array (name, columns, [unique], [primary]) */
|
/** @var array (name, columns, [unique], [primary]) */
|
||||||
private $info;
|
private array $info;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(array $info)
|
public function __construct(array $info)
|
||||||
|
@@ -20,14 +20,13 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class Result
|
class Result
|
||||||
{
|
{
|
||||||
/** @var Dibi\ResultDriver */
|
private Dibi\ResultDriver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
/** @var Column[]|null */
|
/** @var Column[]|null */
|
||||||
private $columns;
|
private ?array $columns;
|
||||||
|
|
||||||
/** @var Column[]|null */
|
/** @var Column[]|null */
|
||||||
private $names;
|
private ?array $names;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\ResultDriver $driver)
|
public function __construct(Dibi\ResultDriver $driver)
|
||||||
@@ -79,7 +78,7 @@ class Result
|
|||||||
|
|
||||||
protected function initColumns(): void
|
protected function initColumns(): void
|
||||||
{
|
{
|
||||||
if ($this->columns === null) {
|
if (!isset($this->columns)) {
|
||||||
$this->columns = [];
|
$this->columns = [];
|
||||||
$reflector = $this->driver instanceof Dibi\Reflector
|
$reflector = $this->driver instanceof Dibi\Reflector
|
||||||
? $this->driver
|
? $this->driver
|
||||||
|
@@ -25,26 +25,19 @@ use Dibi;
|
|||||||
*/
|
*/
|
||||||
class Table
|
class Table
|
||||||
{
|
{
|
||||||
/** @var Dibi\Reflector */
|
private Dibi\Reflector $reflector;
|
||||||
private $reflector;
|
private string $name;
|
||||||
|
private bool $view;
|
||||||
|
|
||||||
/** @var string */
|
/** @var Column[] */
|
||||||
private $name;
|
private array $columns;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var ForeignKey[] */
|
||||||
private $view;
|
private array $foreignKeys;
|
||||||
|
|
||||||
/** @var Column[]|null */
|
/** @var Index[] */
|
||||||
private $columns;
|
private array $indexes;
|
||||||
|
private ?Index $primaryKey;
|
||||||
/** @var ForeignKey[]|null */
|
|
||||||
private $foreignKeys;
|
|
||||||
|
|
||||||
/** @var Index[]|null */
|
|
||||||
private $indexes;
|
|
||||||
|
|
||||||
/** @var Index|null */
|
|
||||||
private $primaryKey;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Dibi\Reflector $reflector, array $info)
|
public function __construct(Dibi\Reflector $reflector, array $info)
|
||||||
@@ -133,7 +126,7 @@ class Table
|
|||||||
|
|
||||||
protected function initColumns(): void
|
protected function initColumns(): void
|
||||||
{
|
{
|
||||||
if ($this->columns === null) {
|
if (!isset($this->columns)) {
|
||||||
$this->columns = [];
|
$this->columns = [];
|
||||||
foreach ($this->reflector->getColumns($this->name) as $info) {
|
foreach ($this->reflector->getColumns($this->name) as $info) {
|
||||||
$this->columns[strtolower($info['name'])] = new Column($this->reflector, $info);
|
$this->columns[strtolower($info['name'])] = new Column($this->reflector, $info);
|
||||||
@@ -144,7 +137,7 @@ class Table
|
|||||||
|
|
||||||
protected function initIndexes(): void
|
protected function initIndexes(): void
|
||||||
{
|
{
|
||||||
if ($this->indexes === null) {
|
if (!isset($this->indexes)) {
|
||||||
$this->initColumns();
|
$this->initColumns();
|
||||||
$this->indexes = [];
|
$this->indexes = [];
|
||||||
foreach ($this->reflector->getIndexes($this->name) as $info) {
|
foreach ($this->reflector->getIndexes($this->name) as $info) {
|
||||||
|
@@ -17,26 +17,21 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
class Result implements IDataSource
|
class Result implements IDataSource
|
||||||
{
|
{
|
||||||
/** @var ResultDriver|null */
|
private ?ResultDriver $driver;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
/** @var array Translate table */
|
/** Translate table */
|
||||||
private $types = [];
|
private array $types = [];
|
||||||
|
private ?Reflection\Result $meta;
|
||||||
|
|
||||||
/** @var Reflection\Result|null */
|
/** Already fetched? Used for allowance for first seek(0) */
|
||||||
private $meta;
|
private bool $fetched = false;
|
||||||
|
|
||||||
/** @var bool Already fetched? Used for allowance for first seek(0) */
|
/** returned object class */
|
||||||
private $fetched = false;
|
private ?string $rowClass = Row::class;
|
||||||
|
|
||||||
/** @var string|null returned object class */
|
|
||||||
private $rowClass = Row::class;
|
|
||||||
|
|
||||||
/** @var callable|null returned object factory */
|
/** @var callable|null returned object factory */
|
||||||
private $rowFactory;
|
private $rowFactory;
|
||||||
|
private array $formats = [];
|
||||||
/** @var array format */
|
|
||||||
private $formats = [];
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(ResultDriver $driver, bool $normalize = true)
|
public function __construct(ResultDriver $driver, bool $normalize = true)
|
||||||
@@ -589,7 +584,7 @@ class Result implements IDataSource
|
|||||||
*/
|
*/
|
||||||
public function getInfo(): Reflection\Result
|
public function getInfo(): Reflection\Result
|
||||||
{
|
{
|
||||||
if ($this->meta === null) {
|
if (!isset($this->meta)) {
|
||||||
$this->meta = new Reflection\Result($this->getResultDriver());
|
$this->meta = new Reflection\Result($this->getResultDriver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,14 +15,9 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
class ResultIterator implements \Iterator, \Countable
|
class ResultIterator implements \Iterator, \Countable
|
||||||
{
|
{
|
||||||
/** @var Result */
|
private Result $result;
|
||||||
private $result;
|
private mixed $row;
|
||||||
|
private int $pointer = 0;
|
||||||
/** @var mixed */
|
|
||||||
private $row;
|
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $pointer = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Result $result)
|
public function __construct(Result $result)
|
||||||
|
@@ -15,38 +15,19 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
final class Translator
|
final class Translator
|
||||||
{
|
{
|
||||||
/** @var Connection */
|
private Connection $connection;
|
||||||
private $connection;
|
private Driver $driver;
|
||||||
|
private int $cursor = 0;
|
||||||
/** @var Driver */
|
private array $args;
|
||||||
private $driver;
|
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $cursor = 0;
|
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
private $args;
|
|
||||||
|
|
||||||
/** @var string[] */
|
/** @var string[] */
|
||||||
private $errors;
|
private array $errors;
|
||||||
|
private bool $comment = false;
|
||||||
/** @var bool */
|
private int $ifLevel = 0;
|
||||||
private $comment = false;
|
private int $ifLevelStart = 0;
|
||||||
|
private ?int $limit = null;
|
||||||
/** @var int */
|
private ?int $offset = null;
|
||||||
private $ifLevel = 0;
|
private HashMap $identifiers;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $ifLevelStart = 0;
|
|
||||||
|
|
||||||
/** @var int|null */
|
|
||||||
private $limit;
|
|
||||||
|
|
||||||
/** @var int|null */
|
|
||||||
private $offset;
|
|
||||||
|
|
||||||
/** @var HashMap */
|
|
||||||
private $identifiers;
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(Connection $connection)
|
public function __construct(Connection $connection)
|
||||||
|
@@ -49,23 +49,23 @@ class dibi
|
|||||||
ASC = 'ASC',
|
ASC = 'ASC',
|
||||||
DESC = 'DESC';
|
DESC = 'DESC';
|
||||||
|
|
||||||
/** @var string|null Last SQL command @see dibi::query() */
|
/** Last SQL command @see dibi::query() */
|
||||||
public static $sql;
|
public static ?string $sql = null;
|
||||||
|
|
||||||
/** @var float|null Elapsed time for last query */
|
/** Elapsed time for last query */
|
||||||
public static $elapsedTime;
|
public static ?float $elapsedTime = null;
|
||||||
|
|
||||||
/** @var float Elapsed time for all queries */
|
/** Elapsed time for all queries */
|
||||||
public static $totalTime;
|
public static float $totalTime = 0;
|
||||||
|
|
||||||
/** @var int Number or queries */
|
/** Number or queries */
|
||||||
public static $numOfQueries = 0;
|
public static int $numOfQueries = 0;
|
||||||
|
|
||||||
/** @var Dibi\Connection[] Connection registry storage for Dibi\Connection objects */
|
/** @var Dibi\Connection[] Connection registry storage for Dibi\Connection objects */
|
||||||
private static $registry = [];
|
private static array $registry = [];
|
||||||
|
|
||||||
/** @var Dibi\Connection Current connection */
|
/** Current connection */
|
||||||
private static $connection;
|
private static Dibi\Connection $connection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -15,8 +15,7 @@ namespace Dibi;
|
|||||||
*/
|
*/
|
||||||
class Exception extends \Exception
|
class Exception extends \Exception
|
||||||
{
|
{
|
||||||
/** @var string|null */
|
private ?string $sql;
|
||||||
private $sql;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,8 +85,7 @@ class NotSupportedException extends Exception
|
|||||||
*/
|
*/
|
||||||
class ProcedureException extends Exception
|
class ProcedureException extends Exception
|
||||||
{
|
{
|
||||||
/** @var string */
|
protected string $severity;
|
||||||
protected $severity;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user