Replace dependency to Zend\Paginator to dependency to Pagerfanta (optional)
This commit is contained in:
parent
47caa92cb4
commit
d10fff12d4
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FOQ\ElasticaBundle\Finder;
|
||||
|
||||
use Zend\Paginator\Paginator;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
|
||||
interface PaginatedFinderInterface
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ interface PaginatedFinderInterface
|
|||
* Searches for query results and returns them wrapped in a paginator
|
||||
*
|
||||
* @param mixed $query Can be a string, an array or an Elastica_Query object
|
||||
* @return Paginator paginated results
|
||||
* @return Pagerfanta paginated results
|
||||
*/
|
||||
function findPaginated($query);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FOQ\ElasticaBundle\Finder;
|
||||
|
||||
use FOQ\ElasticaBundle\Paginator\RawPaginatorAdapter;
|
||||
use Zend\Paginator\Paginator;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Elastica_Searchable;
|
||||
use Elastica_Query;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use FOQ\ElasticaBundle\Finder\FinderInterface;
|
|||
use FOQ\ElasticaBundle\Finder\PaginatedFinderInterface;
|
||||
use FOQ\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface;
|
||||
use FOQ\ElasticaBundle\Paginator\TransformedPaginatorAdapter;
|
||||
use Zend\Paginator\Paginator;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use Elastica_Searchable;
|
||||
use Elastica_Query;
|
||||
|
||||
|
@ -45,7 +45,7 @@ class TransformedFinder implements FinderInterface, PaginatedFinderInterface
|
|||
/**
|
||||
* Gets a paginator wrapping the result of a search
|
||||
*
|
||||
* @return Paginator
|
||||
* @return Pagerfanta
|
||||
**/
|
||||
public function findPaginated($query)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ class TransformedFinder implements FinderInterface, PaginatedFinderInterface
|
|||
$results = $this->searchable->search($queryObject)->getResults();
|
||||
$paginatorAdapter = $this->createPaginatorAdapter($queryObject);
|
||||
|
||||
return new Paginator($paginatorAdapter);
|
||||
return new Pagerfanta($paginatorAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
namespace FOQ\ElasticaBundle\Paginator;
|
||||
|
||||
use Zend\Paginator\Adapter;
|
||||
use Pagerfanta\Adapter\AdapterInterface;
|
||||
use Elastica_Searchable;
|
||||
use Elastica_Query;
|
||||
|
||||
/**
|
||||
* Implements the Zend\Paginator\Adapter Interface for use with Zend\Paginator\Paginator
|
||||
* Implements the Pagerfanta\Adapter\AdapterInterface for use with Pagerfanta\Pagerfanta
|
||||
*
|
||||
* Allows pagination of Elastica_Query. Does not map results
|
||||
*/
|
||||
abstract class AbstractPaginatorAdapter implements Adapter
|
||||
abstract class AbstractPaginatorAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var Elastica_SearchableInterface the object to search in
|
||||
|
@ -45,9 +45,9 @@ abstract class AbstractPaginatorAdapter implements Adapter
|
|||
}
|
||||
|
||||
/**
|
||||
* @see Zend\Paginator\Adapter::count
|
||||
* @see Pagerfanta\Adapter\AdapterInterface::getNbResults
|
||||
*/
|
||||
public function count()
|
||||
public function getNbResults()
|
||||
{
|
||||
return $this->searchable->count($this->query);
|
||||
}
|
||||
|
|
|
@ -3,18 +3,18 @@
|
|||
namespace FOQ\ElasticaBundle\Paginator;
|
||||
|
||||
/**
|
||||
* Implements the Zend\Paginator\Adapter Interface for use with Zend\Paginator\Paginator
|
||||
* Implements the Pagerfanta\Adapter\AdapterInterface for use with Zend\Paginator\Paginator
|
||||
*
|
||||
* Allows pagination of Elastica_Query. Does not map results
|
||||
*/
|
||||
class RawPaginatorAdapter extends AbstractPaginatorAdapter
|
||||
{
|
||||
/**
|
||||
* @see Zend\Paginator\Adapter::getItems
|
||||
* @see Pagerfanta\Adapter\AdapterInterface::getSlice
|
||||
*/
|
||||
public function getItems($offset, $itemCountPerPage)
|
||||
public function getSlice($offset, $length)
|
||||
{
|
||||
$results = $this->getElasticaResults($offset, $itemCountPerPage);
|
||||
$results = $this->getElasticaResults($offset, $length);
|
||||
|
||||
return array_map(function($result) { return $result->getSource(); }, $results);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use Elastica_Searchable;
|
|||
use Elastica_Query;
|
||||
|
||||
/**
|
||||
* Implements the Zend\Paginator\Adapter Interface for use with Zend\Paginator\Paginator
|
||||
* Implements the Pagerfanta\Adapter\AdapterInterface Interface for use with Zend\Paginator\Paginator
|
||||
*
|
||||
* Allows pagination of Elastica_Query
|
||||
*/
|
||||
|
@ -28,11 +28,11 @@ class TransformedPaginatorAdapter extends AbstractPaginatorAdapter
|
|||
}
|
||||
|
||||
/**
|
||||
* @see Zend\Paginator\Adapter::getItems
|
||||
* @see Pagerfanta\Adapter\AdapterInterface::getSlice
|
||||
*/
|
||||
public function getItems($offset, $itemCountPerPage)
|
||||
public function getSlice($offset, $length)
|
||||
{
|
||||
$results = $this->getElasticaResults($offset, $itemCountPerPage);
|
||||
$results = $this->getElasticaResults($offset, $length);
|
||||
|
||||
return $this->transformer->transform($results);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue