Skip to content
Permalink
Browse files

Use the RepositoryInterface in the Paginator.

We half did this correctly, but there were a few typehints that hinted
against Table instead of RepositoryInterface. Changing these, and
broadening the interface to contain the methods that PaginatorComponent
relies on as well. This makes it possible for the ElasticSearch plugin
to be compatible with PaginatorComponent.
  • Loading branch information...
markstory committed Jun 24, 2015
1 parent 1422d39 commit 4ea5306f421832716412c9e280b2590e9a14b418
Showing with 22 additions and 9 deletions.
  1. +5 −5 src/Controller/Component/PaginatorComponent.php
  2. +16 −0 src/Datasource/RepositoryInterface.php
  3. +1 −4 src/ORM/Table.php
@@ -15,6 +15,7 @@
namespace Cake\Controller\Component;
use Cake\Controller\Component;
use Cake\Datasource\RepositoryInterface;
use Cake\Network\Exception\NotFoundException;
use Cake\ORM\Query;
use Cake\ORM\Table;
@@ -295,11 +296,11 @@ public function getDefaults($alias, $defaults)
* Any columns listed in the sort whitelist will be implicitly trusted. You can use this to sort
* on synthetic columns, or columns added in custom find operations that may not exist in the schema.
*
* @param Table $object The model being paginated.
* @param \Cake\Datasource\RepositoryInterface $object Repository object.
* @param array $options The pagination options being used for this request.
* @return array An array of options with sort + direction removed and replaced with order if possible.
*/
public function validateSort(Table $object, array $options)
public function validateSort(RepositoryInterface $object, array $options)
{
if (isset($options['sort'])) {
$direction = null;
@@ -331,19 +332,18 @@ public function validateSort(Table $object, array $options)
}
$options['order'] = $this->_prefix($object, $options['order'], $inWhitelist);
return $options;
}
/**
* Prefixes the field with the table alias if possible.
*
* @param \Cake\ORM\Table $object Table object.
* @param \Cake\Datasource\RepositoryInterface $object Repository object.
* @param array $order Order array.
* @param bool $whitelisted Whether or not the field was whitelisted
* @return array Final order array.
*/
protected function _prefix(Table $object, $order, $whitelisted = false)
protected function _prefix(RepositoryInterface $object, $order, $whitelisted = false)
{
$tableAlias = $object->alias();
$tableOrder = [];
@@ -23,6 +23,22 @@
interface RepositoryInterface
{
/**
* Returns the table alias or sets a new one
*
* @param string|null $alias the new table alias
* @return string
*/
public function alias($alias = null);
/**
* Test to see if a Repository has a specific field/column.
*
* @param string $field The field to check for.
* @return bool True if the field exists, false if it does not.
*/
public function hasField($field);
/**
* Creates a new Query for this repository and applies some defaults based on the
* type of search that was selected.
@@ -346,10 +346,7 @@ public function table($table = null)
}
/**
* Returns the table alias or sets a new one
*
* @param string|null $alias the new table alias
* @return string
* {@inheritDoc}
*/
public function alias($alias = null)
{

0 comments on commit 4ea5306

Please sign in to comment.
You can’t perform that action at this time.