Skip to content

Commit

Permalink
Avoid calling getDefaults() twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 10, 2017
1 parent a764a34 commit 969c219
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/Controller/Component/PaginatorComponent.php
Expand Up @@ -228,9 +228,8 @@ public function mergeOptions($alias, $settings)
$request = $this->_registry->getController()->request;

return $this->_paginator->mergeOptions(
$alias,
$request->getQueryParams(),
$settings
$this->_paginator->getDefaults($alias, $settings)
);
}

Expand Down
14 changes: 4 additions & 10 deletions src/ORM/Paginator.php
Expand Up @@ -170,7 +170,8 @@ public function paginate($object, array $params = [], array $settings = [])
}

$alias = $object->alias();
$options = $this->mergeOptions($alias, $params, $settings);
$defaults = $this->getDefaults($alias, $settings);
$options = $this->mergeOptions($params, $defaults);
$options = $this->validateSort($object, $options);
$options = $this->checkLimit($options);

Expand All @@ -188,9 +189,6 @@ public function paginate($object, array $params = [], array $settings = [])
$numResults = count($results);
$count = $numResults ? $query->count() : 0;

$defaults = $this->getDefaults($alias, $settings);
unset($defaults[0]);

$page = $options['page'];
$limit = $options['limit'];
$pageCount = (int)ceil($count / $limit);
Expand Down Expand Up @@ -272,23 +270,19 @@ public function getPagingParams()
* combined together. You can change config value `whitelist` to modify
* which options/values can be set using request parameters.
*
* @param string $alias Model alias being paginated, if the general settings
* has a key with this value that key's settings will be used for
* pagination instead of the general ones.
* @param array $params Request params.
* @param array $settings The settings to merge with the request data.
* @return array Array of merged options.
*/
public function mergeOptions($alias, $params, $settings)
public function mergeOptions($params, $settings)
{
$defaults = $this->getDefaults($alias, $settings);
$scope = Hash::get($settings, 'scope', null);
if ($scope) {
$params = Hash::get($params, $scope, []);
}
$params = array_intersect_key($params, array_flip($this->config('whitelist')));

return array_merge($defaults, $params);
return array_merge($settings, $params);
}

/**
Expand Down

0 comments on commit 969c219

Please sign in to comment.