Skip to content
Permalink
Browse files

Rename 'prefix' => 'scope'.

I am concerned that 'prefix' will be easily confused with routing
prefixes, as both this prefix and routing prefixes affect URL
generation. scope is a slightly less confusing term to me.
  • Loading branch information...
markstory committed Jul 5, 2016
1 parent f5164aa commit 2a4995e4e24e93a00437d87862aeb890b33d07b3
@@ -159,7 +159,7 @@ public function paginate($object, array $settings = [])
$options = $this->validateSort($object, $options);
$options = $this->checkLimit($options);
$options += ['page' => 1, 'prefix' => null];
$options += ['page' => 1, 'scope' => null];
$options['page'] = (int)$options['page'] < 1 ? 1 : (int)$options['page'];
list($finder, $options) = $this->_extractFinder($options);
@@ -204,7 +204,7 @@ public function paginate($object, array $settings = [])
'limit' => $defaults['limit'] != $limit ? $limit : null,
'sortDefault' => $sortDefault,
'directionDefault' => $directionDefault,
'prefix' => $options['prefix'],
'scope' => $options['scope'],
];
if (!isset($request['paging'])) {
@@ -259,10 +259,10 @@ public function mergeOptions($alias, $settings)
{
$defaults = $this->getDefaults($alias, $settings);
$request = $this->_registry->getController()->request;
$prefix = Hash::get($settings, 'prefix', null);
$scope = Hash::get($settings, 'scope', null);
$query = $request->query;
if ($prefix) {
$query = Hash::get($request->query, $prefix, []);
if ($scope) {
$query = Hash::get($request->query, $scope, []);
}
$request = array_intersect_key($query, array_flip($this->_config['whitelist']));
return array_merge($defaults, $request);
@@ -478,7 +478,7 @@ public function generateUrl(array $options = [], $model = null, $full = false)
];
if (!empty($this->_config['options']['url'])) {
$key = implode('.', array_filter(['options.url', Hash::get($paging, 'prefix', null)]));
$key = implode('.', array_filter(['options.url', Hash::get($paging, 'scope', null)]));
$url = array_merge($url, Hash::get($this->_config, $key, []));
}
@@ -496,10 +496,10 @@ public function generateUrl(array $options = [], $model = null, $full = false)
) {
$url['sort'] = $url['direction'] = null;
}
if (!empty($paging['prefix'])) {
$url = [$paging['prefix'] => $url] + $this->_config['options']['url'];
if (empty($url[$paging['prefix']]['page'])) {
unset($url[$paging['prefix']]['page']);
if (!empty($paging['scope'])) {
$url = [$paging['scope'] => $url] + $this->_config['options']['url'];
if (empty($url[$paging['scope']]['page'])) {
unset($url[$paging['scope']]['page']);
}
}
return $this->Url->build($url, $full);
@@ -144,7 +144,7 @@ public function testPaginateExtraParams()
'order' => ['PaginatorPosts.id' => 'ASC'],
'page' => 1,
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => null,
'scope' => null,
]);
$this->Paginator->paginate($table, $settings);
}
@@ -228,7 +228,7 @@ public function testDefaultPaginateParams()
'page' => 1,
'order' => ['PaginatorPosts.id' => 'DESC'],
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => null,
'scope' => null,
]);
$this->Paginator->paginate($table, $settings);
@@ -260,7 +260,7 @@ public function testDefaultPaginateParamsIntoRequest()
'page' => 1,
'order' => ['PaginatorPosts.id' => 'DESC'],
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => null,
'scope' => null,
]);
$this->Paginator->paginate($table, $settings);
@@ -295,16 +295,16 @@ public function testMergeOptionsModelSpecific()
}
/**
* test mergeOptions with custom prefix
* test mergeOptions with custom scope
*
* @return void
*/
public function testMergeOptionsCustomPrefix()
public function testMergeOptionsCustomScope()
{
$this->request->query = [
'page' => 10,
'limit' => 10,
'prefix' => [
'scope' => [
'page' => 2,
'limit' => 5,
]
@@ -331,7 +331,7 @@ public function testMergeOptionsCustomPrefix()
'limit' => 20,
'maxLimit' => 100,
'finder' => 'myCustomFind',
'prefix' => 'non-existent',
'scope' => 'non-existent',
];
$result = $this->Paginator->mergeOptions('Post', $settings);
$expected = [
@@ -340,7 +340,7 @@ public function testMergeOptionsCustomPrefix()
'maxLimit' => 100,
'finder' => 'myCustomFind',
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => 'non-existent',
'scope' => 'non-existent',
];
$this->assertEquals($expected, $result);
@@ -350,7 +350,7 @@ public function testMergeOptionsCustomPrefix()
'limit' => 20,
'maxLimit' => 100,
'finder' => 'myCustomFind',
'prefix' => 'prefix',
'scope' => 'scope',
];
$result = $this->Paginator->mergeOptions('Post', $settings);
$expected = [
@@ -359,7 +359,7 @@ public function testMergeOptionsCustomPrefix()
'maxLimit' => 100,
'finder' => 'myCustomFind',
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => 'prefix',
'scope' => 'scope',
];
$this->assertEquals($expected, $result);
}
@@ -522,7 +522,7 @@ public function testValidateSortInvalid()
'page' => 1,
'order' => ['PaginatorPosts.id' => 'asc'],
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => null,
'scope' => null,
]);
$this->request->query = [
@@ -1031,7 +1031,7 @@ public function testPaginateCustomFindCount()
'page' => 1,
'order' => [],
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => null,
'scope' => null,
]);
$this->Paginator->paginate($table, $settings);
}
@@ -1065,7 +1065,7 @@ public function testPaginateQuery()
'order' => ['PaginatorPosts.id' => 'ASC'],
'page' => 1,
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => null,
'scope' => null,
]);
$this->Paginator->paginate($query, $settings);
}
@@ -1125,7 +1125,7 @@ public function testPaginateQueryWithLimit()
'order' => ['PaginatorPosts.id' => 'ASC'],
'page' => 1,
'whitelist' => ['limit', 'sort', 'page', 'direction'],
'prefix' => null,
'scope' => null,
]);
$this->Paginator->paginate($query, $settings);
}
@@ -446,7 +446,7 @@ public function testSortLinksMultiplePagination()
'sort' => 'date',
'direction' => 'asc',
'page' => 1,
'prefix' => 'article',
'scope' => 'article',
]
];
@@ -784,7 +784,7 @@ public function testGenerateUrlMultiplePagination()
['base' => '', 'here' => 'posts/index', 'webroot' => '/']
]);
$this->Paginator->request->params['paging']['Article']['prefix'] = 'article';
$this->Paginator->request->params['paging']['Article']['scope'] = 'article';
$this->Paginator->request->params['paging']['Article']['page'] = 3;
$this->Paginator->request->params['paging']['Article']['prevPage'] = true;
$this->Paginator->options(['model' => 'Article']);

0 comments on commit 2a4995e

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