From bea51de1d5156968657a26b7ef9d2e2b34fc06a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=C3=A1nchez?= Date: Thu, 5 Sep 2024 10:53:41 +0200 Subject: [PATCH] fixes --- composer.json | 4 +-- src/Paginator/FantaPaginatorAdapter.php | 20 +++++-------- src/Paginator/FantaPaginatorAdapterTrait.php | 29 +++++++++++++++++++ .../LegacyFantaPaginatorAdapterTrait.php | 29 +++++++++++++++++++ 4 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 src/Paginator/FantaPaginatorAdapterTrait.php create mode 100644 src/Paginator/LegacyFantaPaginatorAdapterTrait.php diff --git a/composer.json b/composer.json index e4761ba61..f895180d0 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ "symfony/console": "^4.4|^5.4", "symfony/dependency-injection": "^4.4|^5.4", "symfony/property-access": "^4.4|^5.4", - "pagerfanta/pagerfanta": "^3.0|^4.0", + "pagerfanta/pagerfanta": "^2.4|^3.0|^4.0", "psr/log": "^1.0", - "ruflin/elastica": "^5.3.5|^6.1.1" + "ruflin/elastica": "^5.3.5|^6.1.2" }, "require-dev": { "doctrine/orm": "^2.5", diff --git a/src/Paginator/FantaPaginatorAdapter.php b/src/Paginator/FantaPaginatorAdapter.php index e5ceb7819..739973e6a 100644 --- a/src/Paginator/FantaPaginatorAdapter.php +++ b/src/Paginator/FantaPaginatorAdapter.php @@ -12,10 +12,17 @@ namespace FOS\ElasticaBundle\Paginator; use Pagerfanta\Adapter\AdapterInterface; +use Pagerfanta\PagerfantaInterface; use Traversable; +if (!method_exists(PagerfantaInterface::class, 'getAdapter')) { + class_alias(LegacyFantaPaginatorAdapterTrait::class, FantaPaginatorAdapterTrait::class); +} + class FantaPaginatorAdapter implements AdapterInterface { + use FantaPaginatorAdapterTrait; + private $adapter; /** @@ -60,19 +67,6 @@ public function getSuggests() return $this->adapter->getSuggests(); } - /** - * Returns a slice of the results. - * - * @param int $offset The offset - * @param int $length The length - * - * @return iterable The slice - */ - public function getSlice(int $offset, int $length): iterable - { - return $this->adapter->getResults($offset, $length)->toArray(); - } - /** * {@inheritdoc} */ diff --git a/src/Paginator/FantaPaginatorAdapterTrait.php b/src/Paginator/FantaPaginatorAdapterTrait.php new file mode 100644 index 000000000..96dd3ac9f --- /dev/null +++ b/src/Paginator/FantaPaginatorAdapterTrait.php @@ -0,0 +1,29 @@ +adapter->getResults($offset, $length)->toArray(); + } + + /** + * Returns the number of results. + * + * @return int The number of results + */ + public function getNbResults(): int + { + return $this->adapter->getTotalHits(); + } +} diff --git a/src/Paginator/LegacyFantaPaginatorAdapterTrait.php b/src/Paginator/LegacyFantaPaginatorAdapterTrait.php new file mode 100644 index 000000000..ea8b296de --- /dev/null +++ b/src/Paginator/LegacyFantaPaginatorAdapterTrait.php @@ -0,0 +1,29 @@ +adapter->getResults($offset, $length)->toArray(); + } + + /** + * Returns the number of results. + * + * @return int The number of results + */ + public function getNbResults() + { + return $this->adapter->getTotalHits(); + } +}