mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 21:58:10 +02:00
uses PHP 5.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_');
|
||||||
|
@@ -36,8 +36,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(...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -24,13 +24,12 @@ use function in_array, is_array, is_resource, strlen;
|
|||||||
* - 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;
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +72,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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +118,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);
|
||||||
@@ -223,13 +222,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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -244,9 +240,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);
|
||||||
}
|
}
|
||||||
|
@@ -21,8 +21,7 @@ use function is_resource;
|
|||||||
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,
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,13 +88,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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -115,7 +115,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(...));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -211,7 +211,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;
|
||||||
|
@@ -36,7 +36,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(...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,7 +90,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()) {
|
||||||
@@ -436,7 +436,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