1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 22:26:43 +02:00

support for PHP 8.1

This commit is contained in:
David Grudl
2021-08-25 03:12:58 +02:00
parent 73e16eb1a3
commit 8270b7c1c3
7 changed files with 26 additions and 19 deletions

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
fail-fast: false

View File

@@ -34,7 +34,7 @@ Install Dibi via Composer:
composer require dibi/dibi
```
The Dibi 4.2 requires PHP version 7.2 and supports PHP up to 8.0.
The Dibi 4.2 requires PHP version 7.2 and supports PHP up to 8.1.
Usage

View File

@@ -11,6 +11,7 @@ namespace Dibi\Drivers;
use Dibi;
use Dibi\Helpers;
use PgSql;
/**
@@ -29,7 +30,7 @@ class PostgreDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var resource */
/** @var resource|PgSql\Connection */
private $connection;
/** @var int|null Affected rows */
@@ -74,7 +75,7 @@ class PostgreDriver implements Dibi\Driver
restore_error_handler();
}
if (!is_resource($this->connection)) {
if (!is_resource($this->connection) && !$this->connection instanceof PgSql\Connection) {
throw new Dibi\DriverException($error ?: 'Connecting error.');
}
@@ -120,7 +121,7 @@ class PostgreDriver implements Dibi\Driver
if ($res === false) {
throw static::createException(pg_last_error($this->connection), null, $sql);
} elseif (is_resource($res)) {
} elseif (is_resource($res) || $res instanceof PgSql\Result) {
$this->affectedRows = Helpers::false2Null(pg_affected_rows($res));
if (pg_num_fields($res)) {
return $this->createResultDriver($res);
@@ -227,7 +228,9 @@ class PostgreDriver implements Dibi\Driver
*/
public function getResource()
{
return is_resource($this->connection) ? $this->connection : null;
return is_resource($this->connection) || $this->connection instanceof PgSql\Connection
? $this->connection
: null;
}
@@ -258,7 +261,7 @@ class PostgreDriver implements Dibi\Driver
*/
public function escapeText(string $value): string
{
if (!is_resource($this->connection)) {
if (!$this->getResource()) {
throw new Dibi\Exception('Lost connection to server.');
}
return "'" . pg_escape_string($this->connection, $value) . "'";
@@ -267,7 +270,7 @@ class PostgreDriver implements Dibi\Driver
public function escapeBinary(string $value): string
{
if (!is_resource($this->connection)) {
if (!$this->getResource()) {
throw new Dibi\Exception('Lost connection to server.');
}
return "'" . pg_escape_bytea($this->connection, $value) . "'";

View File

@@ -11,6 +11,7 @@ namespace Dibi\Drivers;
use Dibi;
use Dibi\Helpers;
use PgSql;
/**
@@ -20,7 +21,7 @@ class PostgreResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var resource */
/** @var resource|PgSql\Result */
private $resultSet;
/** @var bool */
@@ -28,7 +29,7 @@ class PostgreResult implements Dibi\ResultDriver
/**
* @param resource $resultSet
* @param resource|PgSql\Result $resultSet
*/
public function __construct($resultSet)
{
@@ -108,12 +109,14 @@ class PostgreResult implements Dibi\ResultDriver
/**
* Returns the result set resource.
* @return resource|null
* @return resource|PgSql\Result|null
*/
public function getResultResource()
{
$this->autoFree = false;
return is_resource($this->resultSet) ? $this->resultSet : null;
return is_resource($this->resultSet) || $this->resultSet instanceof PgSql\Result
? $this->resultSet
: null;
}

View File

@@ -44,6 +44,7 @@ class ResultIterator implements \Iterator, \Countable
}
#[\ReturnTypeWillChange]
/**
* Returns the key of the current element.
* @return mixed
@@ -54,6 +55,7 @@ class ResultIterator implements \Iterator, \Countable
}
#[\ReturnTypeWillChange]
/**
* Returns the current element.
* @return mixed

View File

@@ -62,37 +62,38 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
/********************* interfaces ArrayAccess, Countable & IteratorAggregate ****************d*g**/
final public function count()
final public function count(): int
{
return count((array) $this);
}
final public function getIterator()
final public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this);
}
final public function offsetSet($nm, $val)
final public function offsetSet($nm, $val): void
{
$this->$nm = $val;
}
#[\ReturnTypeWillChange]
final public function offsetGet($nm)
{
return $this->$nm;
}
final public function offsetExists($nm)
final public function offsetExists($nm): bool
{
return isset($this->$nm);
}
final public function offsetUnset($nm)
final public function offsetUnset($nm): void
{
unset($this->$nm);
}

View File

@@ -14,8 +14,6 @@ Assert::same('1978-01-23 11:40:00.000000', (string) new DateTime(254400000));
Assert::same('1978-01-23 11:40:00.000000', (string) (new DateTime)->setTimestamp(254400000));
Assert::same(254400000, (new DateTime(254400000))->getTimestamp());
Assert::same('2050-08-13 11:40:00.000000', (string) new DateTime(2544000000));
Assert::same('2050-08-13 11:40:00.000000', (string) (new DateTime)->setTimestamp(2544000000));
Assert::same(is_int(2544000000) ? 2544000000 : '2544000000', (new DateTime(2544000000))->getTimestamp()); // 64 bit
Assert::same('1978-05-05 00:00:00.000000', (string) new DateTime('1978-05-05'));