Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Sep 5, 2024
1 parent b3b2305 commit bea51de
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 7 additions & 13 deletions src/Paginator/FantaPaginatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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}
*/
Expand Down
29 changes: 29 additions & 0 deletions src/Paginator/FantaPaginatorAdapterTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace FOS\ElasticaBundle\Paginator;

trait FantaPaginatorAdapterTrait
{
/**
* 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();
}

/**
* Returns the number of results.
*
* @return int The number of results
*/
public function getNbResults(): int
{
return $this->adapter->getTotalHits();
}
}
29 changes: 29 additions & 0 deletions src/Paginator/LegacyFantaPaginatorAdapterTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace FOS\ElasticaBundle\Paginator;

trait LegacyFantaPaginatorAdapterTrait
{
/**
* Returns a slice of the results.
*
* @param int $offset The offset
* @param int $length The length
*
* @return iterable The slice
*/
public function getSlice($offset, $length)
{
return $this->adapter->getResults($offset, $length)->toArray();
}

/**
* Returns the number of results.
*
* @return int The number of results
*/
public function getNbResults()
{
return $this->adapter->getTotalHits();
}
}

0 comments on commit bea51de

Please sign in to comment.