Skip to content

Commit

Permalink
chore: support dbal 4, orm 3, phpcr-odm 2
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Jan 7, 2025
1 parent 393d1b8 commit 9886496
Show file tree
Hide file tree
Showing 41 changed files with 768 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cscheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "8.1"
php-version: "8.3"
tools: cs2pr

- name: Install dependencies with composer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "8.2"
php-version: "8.3"
tools: cs2pr

- name: Install dependencies with composer
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ jobs:
php_version:
- '8.1'
- '8.2'
- '8.3'
- '8.4'

name: PHP ${{ matrix.php_version }}
dbal_version:
- 3.0
- 4.0

name: PHP ${{ matrix.php_version }} - DBAL ${{ matrix.dbal_version }}
steps:
- uses: actions/checkout@v2

Expand All @@ -28,6 +34,7 @@ jobs:
extensions: :opcache, mongodb

- run: composer remove --no-update --dev roave/security-advisories solido/php-coding-standards
- run: composer require --no-update doctrine/dbal:^${{ matrix.dbal_version }}
- run: composer update --with-all-dependencies ${{ matrix.composer_flags }}

- run: vendor/bin/phpunit --coverage-clover coverage.xml
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
},
"require-dev": {
"composer-runtime-api": "^2",
"doctrine/dbal": "^3.2",
"doctrine/mongodb-odm": ">=2.0,<2.5",
"doctrine/orm": "^2.7",
"doctrine/phpcr-odm": "^1.5",
"doctrine/dbal": "^2.6 || ^3.0 || ^4.0",
"doctrine/mongodb-odm": "^2.7",
"doctrine/orm": "^2.7 || ^3.0",
"doctrine/phpcr-odm": "^1.5 || ^2.0",
"giggsey/libphonenumber-for-php": "^8.10",
"jackalope/jackalope-doctrine-dbal": "*",
"moneyphp/money": "^3.2",
Expand All @@ -53,7 +53,7 @@
}
},
"conflict": {
"doctrine/dbal": "<3.0 || >=4.0",
"doctrine/dbal": "<3.0 || >=5.0",
"doctrine/orm": "<2.9"
},
"config": {
Expand Down
58 changes: 17 additions & 41 deletions src/DBAL/DummyResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,31 @@
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;

use function array_values;
use function array_keys;
use function count;
use function reset;

/** @internal The class is internal to the caching layer implementation. */
final class DummyResult implements Result
{
use DummyResultCompatTrait;

private int $columnCount = 0;
/** @var string[] */
private array $columnNames = [];
private int $num = 0;

/** @param mixed[] $data */
public function __construct(private array $data, int|null $columnCount = null)
/**
* @param mixed[] $data
* @param string[]|null $columnNames
*/
public function __construct(private array $data, int|null $columnCount = null, array|null $columnNames = null)
{
if (count($data) === 0) {
return;
}

$this->columnCount = $columnCount ?? count($data[0]);
}

/**
* {@inheritDoc}
*/
public function fetchNumeric()
{
$row = $this->fetch();

if ($row === false) {
return false;
}

return array_values($row);
}

/**
* {@inheritDoc}
*/
public function fetchAssociative()
{
return $this->fetch();
}

/**
* {@inheritDoc}
*/
public function fetchOne()
{
$row = $this->fetch();

if ($row === false) {
return false;
}

return reset($row);
$this->columnNames = $columnNames ?? array_keys($data[0]); /** @phpstan-ignore-line */
}

/**
Expand Down Expand Up @@ -97,12 +68,17 @@ public function columnCount(): int
return $this->columnCount;
}

public function getColumnName(int $index): string
{
return $this->columnNames[$index] ?? '';
}

public function free(): void
{
$this->data = [];
}

private function fetch(): mixed
private function doFetch(): mixed
{
if (! isset($this->data[$this->num])) {
return false;
Expand Down
21 changes: 21 additions & 0 deletions src/DBAL/DummyResultCompatTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Refugis\DoctrineExtra\DBAL;

use Composer\InstalledVersions;

use function version_compare;

if (version_compare((string) InstalledVersions::getVersion('doctrine/dbal'), '4.0.0', '>=')) {
trait DummyResultCompatTrait
{
use DummyResultCompatTraitV4;
}
} else {
trait DummyResultCompatTrait // phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
{
use DummyResultCompatTraitV2;
}
}
47 changes: 47 additions & 0 deletions src/DBAL/DummyResultCompatTraitV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Refugis\DoctrineExtra\DBAL;

use function array_values;
use function reset;

trait DummyResultCompatTraitV2
{
/**
* {@inheritDoc}
*/
public function fetchNumeric()
{
$row = $this->doFetch();

if ($row === false) {
return false;
}

return array_values($row);
}

/**
* {@inheritDoc}
*/
public function fetchAssociative()
{
return $this->doFetch();
}

/**
* {@inheritDoc}
*/
public function fetchOne()
{
$row = $this->doFetch();

if ($row === false) {
return false;
}

return reset($row);
}
}
38 changes: 38 additions & 0 deletions src/DBAL/DummyResultCompatTraitV4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Refugis\DoctrineExtra\DBAL;

use function array_values;
use function reset;

trait DummyResultCompatTraitV4
{
public function fetchNumeric(): array|false
{
$row = $this->doFetch();

if ($row === false) {
return false;
}

return array_values($row);
}

public function fetchAssociative(): array|false
{
return $this->doFetch();
}

public function fetchOne(): mixed
{
$row = $this->doFetch();

if ($row === false) {
return false;
}

return reset($row);
}
}
66 changes: 3 additions & 63 deletions src/DBAL/DummyStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
use Doctrine\DBAL\Driver\FetchUtils;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;

use function array_values;
use function count;
use function reset;

/**
* Dummy statement serves a static result statement
Expand All @@ -23,6 +20,8 @@
*/
class DummyStatement implements IteratorAggregate, Statement, Result
{
use DummyStatementCompatTrait;

private int $columnCount;
private int $num;

Expand Down Expand Up @@ -52,42 +51,6 @@ public function getIterator(): ArrayIterator
return new ArrayIterator($data);
}

/**
* {@inheritDoc}
*/
public function fetchNumeric()
{
$row = $this->doFetch();

if ($row === false) {
return false;
}

return array_values($row);
}

/**
* {@inheritDoc}
*/
public function fetchAssociative()
{
return $this->doFetch();
}

/**
* {@inheritDoc}
*/
public function fetchOne()
{
$row = $this->doFetch();

if ($row === false) {
return false;
}

return reset($row);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -117,30 +80,7 @@ public function free(): void
$this->data = [];
}

/**
* {@inheritDoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING): bool
{
// TODO

return true;
}

/**
* {@inheritDoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null): bool
{
// TODO

return true;
}

/**
* {@inheritDoc}
*/
public function execute($params = null): Result
public function execute(mixed $params = null): Result
{
return new DummyResult($this->data);
}
Expand Down
23 changes: 23 additions & 0 deletions src/DBAL/DummyStatementCompatTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Refugis\DoctrineExtra\DBAL;

use Composer\InstalledVersions;

use function version_compare;

if (version_compare((string) InstalledVersions::getVersion('doctrine/dbal'), '4.0.0', '>=')) {
trait DummyStatementCompatTrait
{
use DummyResultCompatTraitV4;
use DummyStatementCompatTraitV4;
}
} else {
trait DummyStatementCompatTrait // phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
{
use DummyResultCompatTraitV2;
use DummyStatementCompatTraitV2;
}
}
Loading

0 comments on commit 9886496

Please sign in to comment.