mirror of
https://github.com/dg/dibi.git
synced 2025-08-12 00:54:11 +02:00
uses PHP 8.2 features
This commit is contained in:
@@ -45,7 +45,7 @@ function substFallBack($expr)
|
|||||||
|
|
||||||
|
|
||||||
// define callback
|
// define callback
|
||||||
$dibi->getSubstitutes()->setCallback('substFallBack');
|
$dibi->getSubstitutes()->setCallback(substFallBack(...));
|
||||||
|
|
||||||
// define substitutes as constants
|
// define substitutes as constants
|
||||||
define('SUBST_ACCOUNT', 'eshop_');
|
define('SUBST_ACCOUNT', 'eshop_');
|
||||||
|
@@ -35,8 +35,8 @@ class Panel implements Tracy\IBarPanel
|
|||||||
public function register(Dibi\Connection $connection): void
|
public function register(Dibi\Connection $connection): void
|
||||||
{
|
{
|
||||||
Tracy\Debugger::getBar()->addPanel($this);
|
Tracy\Debugger::getBar()->addPanel($this);
|
||||||
Tracy\Debugger::getBlueScreen()->addPanel([self::class, 'renderException']);
|
Tracy\Debugger::getBlueScreen()->addPanel(self::renderException(...));
|
||||||
$connection->onEvent[] = [$this, 'logEvent'];
|
$connection->onEvent[] = $this->logEvent(...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -23,13 +23,12 @@ use PgSql;
|
|||||||
* - schema => the schema search path
|
* - schema => the schema search path
|
||||||
* - charset => character encoding to set (default is utf8)
|
* - charset => character encoding to set (default is utf8)
|
||||||
* - persistent (bool) => try to find a persistent link?
|
* - persistent (bool) => try to find a persistent link?
|
||||||
* - resource (resource) => existing connection resource
|
* - resource (PgSql\Connection) => existing connection resource
|
||||||
* - connect_type (int) => see pg_connect()
|
* - connect_type (int) => see pg_connect()
|
||||||
*/
|
*/
|
||||||
class PostgreDriver implements Dibi\Driver
|
class PostgreDriver implements Dibi\Driver
|
||||||
{
|
{
|
||||||
/** @var resource|PgSql\Connection */
|
private PgSql\Connection $connection;
|
||||||
private $connection;
|
|
||||||
private ?int $affectedRows;
|
private ?int $affectedRows;
|
||||||
|
|
||||||
|
|
||||||
@@ -72,7 +71,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_resource($this->connection) && !$this->connection instanceof PgSql\Connection) {
|
if (!$this->connection instanceof PgSql\Connection) {
|
||||||
throw new Dibi\DriverException($error ?: 'Connecting error.');
|
throw new Dibi\DriverException($error ?: 'Connecting error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +117,7 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
throw static::createException(pg_last_error($this->connection), null, $sql);
|
throw static::createException(pg_last_error($this->connection), null, $sql);
|
||||||
|
|
||||||
} elseif (is_resource($res) || $res instanceof PgSql\Result) {
|
} elseif ($res instanceof PgSql\Result) {
|
||||||
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
|
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
|
||||||
if (pg_num_fields($res)) {
|
if (pg_num_fields($res)) {
|
||||||
return $this->createResultDriver($res);
|
return $this->createResultDriver($res);
|
||||||
@@ -222,13 +221,10 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the connection resource.
|
* Returns the connection resource.
|
||||||
* @return resource|null
|
|
||||||
*/
|
*/
|
||||||
public function getResource(): mixed
|
public function getResource(): PgSql\Connection
|
||||||
{
|
{
|
||||||
return is_resource($this->connection) || $this->connection instanceof PgSql\Connection
|
return $this->connection;
|
||||||
? $this->connection
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -243,9 +239,8 @@ class PostgreDriver implements Dibi\Driver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Result set driver factory.
|
* Result set driver factory.
|
||||||
* @param resource $resource
|
|
||||||
*/
|
*/
|
||||||
public function createResultDriver($resource): PostgreResult
|
public function createResultDriver(PgSql\Result $resource): PostgreResult
|
||||||
{
|
{
|
||||||
return new PostgreResult($resource);
|
return new PostgreResult($resource);
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,7 @@ use PgSql;
|
|||||||
class PostgreResult implements Dibi\ResultDriver
|
class PostgreResult implements Dibi\ResultDriver
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/** @var resource|PgSql\Result */
|
private PgSql\Result $resultSet,
|
||||||
private $resultSet,
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,13 +87,10 @@ class PostgreResult implements Dibi\ResultDriver
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result set resource.
|
* Returns the result set resource.
|
||||||
* @return resource|PgSql\Result|null
|
|
||||||
*/
|
*/
|
||||||
public function getResultResource(): mixed
|
public function getResultResource(): PgSql\Result
|
||||||
{
|
{
|
||||||
return is_resource($this->resultSet) || $this->resultSet instanceof PgSql\Result
|
return $this->resultSet;
|
||||||
? $this->resultSet
|
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -113,7 +113,7 @@ class Fluent implements IDataSource
|
|||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
|
|
||||||
if (!isset(self::$normalizer)) {
|
if (!isset(self::$normalizer)) {
|
||||||
self::$normalizer = new HashMap([self::class, '_formatClause']);
|
self::$normalizer = new HashMap(self::_formatClause(...));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -208,7 +208,7 @@ class Helpers
|
|||||||
public static function getTypeCache(): HashMap
|
public static function getTypeCache(): HashMap
|
||||||
{
|
{
|
||||||
if (!isset(self::$types)) {
|
if (!isset(self::$types)) {
|
||||||
self::$types = new HashMap([self::class, 'detectType']);
|
self::$types = new HashMap(self::detectType(...));
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$types;
|
return self::$types;
|
||||||
|
@@ -34,7 +34,7 @@ final class Translator
|
|||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->driver = $connection->getDriver();
|
$this->driver = $connection->getDriver();
|
||||||
$this->identifiers = new HashMap([$this, 'delimite']);
|
$this->identifiers = new HashMap($this->delimite(...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ final class Translator
|
|||||||
(\?) ## 11) placeholder
|
(\?) ## 11) placeholder
|
||||||
)/xs
|
)/xs
|
||||||
XX,
|
XX,
|
||||||
[$this, 'cb'],
|
$this->cb(...),
|
||||||
substr($arg, $toSkip),
|
substr($arg, $toSkip),
|
||||||
);
|
);
|
||||||
if (preg_last_error()) {
|
if (preg_last_error()) {
|
||||||
@@ -434,7 +434,7 @@ final class Translator
|
|||||||
:(\S*?:)([a-zA-Z0-9._]?)
|
:(\S*?:)([a-zA-Z0-9._]?)
|
||||||
)/sx
|
)/sx
|
||||||
XX,
|
XX,
|
||||||
[$this, 'cb'],
|
$this->cb(...),
|
||||||
substr($value, $toSkip),
|
substr($value, $toSkip),
|
||||||
);
|
);
|
||||||
if (preg_last_error()) {
|
if (preg_last_error()) {
|
||||||
|
Reference in New Issue
Block a user