mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 13:17:58 +02:00
uses PHP 5.2 features
This commit is contained in:
@@ -45,7 +45,7 @@ function substFallBack($expr)
|
||||
|
||||
|
||||
// define callback
|
||||
$dibi->getSubstitutes()->setCallback('substFallBack');
|
||||
$dibi->getSubstitutes()->setCallback(substFallBack(...));
|
||||
|
||||
// define substitutes as constants
|
||||
define('SUBST_ACCOUNT', 'eshop_');
|
||||
|
@@ -36,8 +36,8 @@ class Panel implements Tracy\IBarPanel
|
||||
public function register(Dibi\Connection $connection): void
|
||||
{
|
||||
Tracy\Debugger::getBar()->addPanel($this);
|
||||
Tracy\Debugger::getBlueScreen()->addPanel([self::class, 'renderException']);
|
||||
$connection->onEvent[] = [$this, 'logEvent'];
|
||||
Tracy\Debugger::getBlueScreen()->addPanel(self::renderException(...));
|
||||
$connection->onEvent[] = $this->logEvent(...);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -24,13 +24,12 @@ use function in_array, is_array, is_resource, strlen;
|
||||
* - schema => the schema search path
|
||||
* - charset => character encoding to set (default is utf8)
|
||||
* - 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()
|
||||
*/
|
||||
class PostgreDriver implements Dibi\Driver
|
||||
{
|
||||
/** @var resource|PgSql\Connection */
|
||||
private $connection;
|
||||
private PgSql\Connection $connection;
|
||||
private ?int $affectedRows;
|
||||
|
||||
|
||||
@@ -73,7 +72,7 @@ class PostgreDriver implements Dibi\Driver
|
||||
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.');
|
||||
}
|
||||
|
||||
@@ -119,7 +118,7 @@ class PostgreDriver implements Dibi\Driver
|
||||
if ($res === false) {
|
||||
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));
|
||||
if (pg_num_fields($res)) {
|
||||
return $this->createResultDriver($res);
|
||||
@@ -223,13 +222,10 @@ class PostgreDriver implements Dibi\Driver
|
||||
|
||||
/**
|
||||
* 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
|
||||
? $this->connection
|
||||
: null;
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
|
||||
@@ -244,9 +240,8 @@ class PostgreDriver implements Dibi\Driver
|
||||
|
||||
/**
|
||||
* Result set driver factory.
|
||||
* @param resource $resource
|
||||
*/
|
||||
public function createResultDriver($resource): PostgreResult
|
||||
public function createResultDriver(PgSql\Result $resource): PostgreResult
|
||||
{
|
||||
return new PostgreResult($resource);
|
||||
}
|
||||
|
@@ -21,8 +21,7 @@ use function is_resource;
|
||||
class PostgreResult implements Dibi\ResultDriver
|
||||
{
|
||||
public function __construct(
|
||||
/** @var resource|PgSql\Result */
|
||||
private $resultSet,
|
||||
private PgSql\Result $resultSet,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -89,13 +88,10 @@ class PostgreResult implements Dibi\ResultDriver
|
||||
|
||||
/**
|
||||
* 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
|
||||
? $this->resultSet
|
||||
: null;
|
||||
return $this->resultSet;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -115,7 +115,7 @@ class Fluent implements IDataSource
|
||||
$this->connection = $connection;
|
||||
|
||||
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
|
||||
{
|
||||
if (!isset(self::$types)) {
|
||||
self::$types = new HashMap([self::class, 'detectType']);
|
||||
self::$types = new HashMap(self::detectType(...));
|
||||
}
|
||||
|
||||
return self::$types;
|
||||
|
@@ -36,7 +36,7 @@ final class Translator
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$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
|
||||
)/xs
|
||||
XX,
|
||||
[$this, 'cb'],
|
||||
$this->cb(...),
|
||||
substr($arg, $toSkip),
|
||||
);
|
||||
if (preg_last_error()) {
|
||||
@@ -436,7 +436,7 @@ final class Translator
|
||||
:(\S*?:)([a-zA-Z0-9._]?)
|
||||
)/sx
|
||||
XX,
|
||||
[$this, 'cb'],
|
||||
$this->cb(...),
|
||||
substr($value, $toSkip),
|
||||
);
|
||||
if (preg_last_error()) {
|
||||
|
Reference in New Issue
Block a user