From fdd23f6c67c96e01d7823b92310e83122add5bc8 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Mon, 6 Dec 2021 14:26:04 +0100 Subject: [PATCH] feat: php8.1 upgrade --- .github/workflows/ci.yml | 16 ++++------------ composer.json | 5 +++-- src/Doctrine/DoctrineDataStore.php | 8 +++++++- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8702804..f694360 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,15 +37,11 @@ jobs: name: Unit tests strategy: matrix: - php: [ 7.4, 8.0 ] + php: [ 8.0, 8.1 ] os: [ ubuntu-latest ] include: - os: [ ubuntu-latest ] - php: 8.1 - composer-flag: "'--ignore-platform-reqs'" - - - os: [ ubuntu-latest ] - php: 7.3 + php: 7.4 composer-flag: "'--prefer-lowest'" runs-on: ${{ matrix.os }} @@ -76,15 +72,11 @@ jobs: name: Functionnal tests strategy: matrix: - php: [ 7.4, 8.0 ] + php: [ 8.0, 8.1 ] os: [ ubuntu-latest ] include: - os: [ ubuntu-latest ] - php: 8.1 - composer-flag: "'--ignore-platform-reqs'" - - - os: [ ubuntu-latest ] - php: 7.3 + php: 7.4 composer-flag: "'--prefer-lowest'" runs-on: ${{ matrix.os }} diff --git a/composer.json b/composer.json index 9a395e8..cc2db48 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,10 @@ "php": ">=7.3", "nekland/tools": "^2.5.1", "symfony/event-dispatcher": "^4.3 || ^5.0", - "pagerfanta/pagerfanta": "^2.0.1", + "pagerfanta/pagerfanta": "^2.0.1 || ^3.0.0", "symfony/yaml": "^4.3 || ^5.0", - "symfony/serializer": "^4.3 || ^5.0" + "symfony/serializer": "^4.3 || ^5.0", + "pagerfanta/doctrine-orm-adapter": "^3.5" }, "require-dev": { "phpunit/phpunit": "^8.5", diff --git a/src/Doctrine/DoctrineDataStore.php b/src/Doctrine/DoctrineDataStore.php index 9ce8edc..687fa6b 100644 --- a/src/Doctrine/DoctrineDataStore.php +++ b/src/Doctrine/DoctrineDataStore.php @@ -7,6 +7,7 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ManagerRegistry; use Pagerfanta\Adapter\DoctrineORMAdapter; +use Pagerfanta\Doctrine\ORM\QueryAdapter; use Pagerfanta\Pagerfanta; use SwagIndustries\Melodiia\Crud\FilterCollectionInterface; use SwagIndustries\Melodiia\Crud\Persistence\DataStoreInterface; @@ -44,7 +45,12 @@ public function getPaginated(string $type, int $page, FilterCollectionInterface $qb = $doctrineRepository->createQueryBuilder('item'); $filters->filter($qb); - $pager = new Pagerfanta(new DoctrineORMAdapter($qb)); + // Keep compatibility with pager fanta 2.X + if (class_exists(QueryAdapter::class)) { + $pager = new Pagerfanta(new QueryAdapter($qb)); + } else { + $pager = new Pagerfanta(new DoctrineORMAdapter($qb)); + } $pager->setCurrentPage($page); $pager->setMaxPerPage($maxPerPage);