Browse Source

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.
Mark Story 9 years ago
parent
commit
2a4995e4e2

+ 5 - 5
src/Controller/Component/PaginatorComponent.php

@@ -159,7 +159,7 @@ class PaginatorComponent extends Component
         $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 @@ class PaginatorComponent extends Component
             'limit' => $defaults['limit'] != $limit ? $limit : null,
             'sortDefault' => $sortDefault,
             'directionDefault' => $directionDefault,
-            'prefix' => $options['prefix'],
+            'scope' => $options['scope'],
         ];
 
         if (!isset($request['paging'])) {
@@ -259,10 +259,10 @@ class PaginatorComponent extends Component
     {
         $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);

+ 5 - 5
src/View/Helper/PaginatorHelper.php

@@ -478,7 +478,7 @@ class PaginatorHelper extends Helper
         ];
 
         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 @@ class PaginatorHelper extends Helper
         ) {
             $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);

+ 14 - 14
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -144,7 +144,7 @@ class PaginatorComponentTest extends TestCase
                 'order' => ['PaginatorPosts.id' => 'ASC'],
                 'page' => 1,
                 'whitelist' => ['limit', 'sort', 'page', 'direction'],
-                'prefix' => null,
+                'scope' => null,
             ]);
         $this->Paginator->paginate($table, $settings);
     }
@@ -228,7 +228,7 @@ class PaginatorComponentTest extends TestCase
                 'page' => 1,
                 'order' => ['PaginatorPosts.id' => 'DESC'],
                 'whitelist' => ['limit', 'sort', 'page', 'direction'],
-                'prefix' => null,
+                'scope' => null,
             ]);
 
         $this->Paginator->paginate($table, $settings);
@@ -260,7 +260,7 @@ class PaginatorComponentTest extends TestCase
                 'page' => 1,
                 'order' => ['PaginatorPosts.id' => 'DESC'],
                 'whitelist' => ['limit', 'sort', 'page', 'direction'],
-                'prefix' => null,
+                'scope' => null,
             ]);
 
         $this->Paginator->paginate($table, $settings);
@@ -295,16 +295,16 @@ class PaginatorComponentTest extends TestCase
     }
 
     /**
-     * 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 @@ class PaginatorComponentTest extends TestCase
             'limit' => 20,
             'maxLimit' => 100,
             'finder' => 'myCustomFind',
-            'prefix' => 'non-existent',
+            'scope' => 'non-existent',
         ];
         $result = $this->Paginator->mergeOptions('Post', $settings);
         $expected = [
@@ -340,7 +340,7 @@ class PaginatorComponentTest extends TestCase
             'maxLimit' => 100,
             'finder' => 'myCustomFind',
             'whitelist' => ['limit', 'sort', 'page', 'direction'],
-            'prefix' => 'non-existent',
+            'scope' => 'non-existent',
         ];
         $this->assertEquals($expected, $result);
 
@@ -350,7 +350,7 @@ class PaginatorComponentTest extends TestCase
             'limit' => 20,
             'maxLimit' => 100,
             'finder' => 'myCustomFind',
-            'prefix' => 'prefix',
+            'scope' => 'scope',
         ];
         $result = $this->Paginator->mergeOptions('Post', $settings);
         $expected = [
@@ -359,7 +359,7 @@ class PaginatorComponentTest extends TestCase
             'maxLimit' => 100,
             'finder' => 'myCustomFind',
             'whitelist' => ['limit', 'sort', 'page', 'direction'],
-            'prefix' => 'prefix',
+            'scope' => 'scope',
         ];
         $this->assertEquals($expected, $result);
     }
@@ -522,7 +522,7 @@ class PaginatorComponentTest extends TestCase
                 'page' => 1,
                 'order' => ['PaginatorPosts.id' => 'asc'],
                 'whitelist' => ['limit', 'sort', 'page', 'direction'],
-                'prefix' => null,
+                'scope' => null,
             ]);
 
         $this->request->query = [
@@ -1031,7 +1031,7 @@ class PaginatorComponentTest extends TestCase
                 'page' => 1,
                 'order' => [],
                 'whitelist' => ['limit', 'sort', 'page', 'direction'],
-                'prefix' => null,
+                'scope' => null,
             ]);
         $this->Paginator->paginate($table, $settings);
     }
@@ -1065,7 +1065,7 @@ class PaginatorComponentTest extends TestCase
                 'order' => ['PaginatorPosts.id' => 'ASC'],
                 'page' => 1,
                 'whitelist' => ['limit', 'sort', 'page', 'direction'],
-                'prefix' => null,
+                'scope' => null,
             ]);
         $this->Paginator->paginate($query, $settings);
     }
@@ -1125,7 +1125,7 @@ class PaginatorComponentTest extends TestCase
                 'order' => ['PaginatorPosts.id' => 'ASC'],
                 'page' => 1,
                 'whitelist' => ['limit', 'sort', 'page', 'direction'],
-                'prefix' => null,
+                'scope' => null,
             ]);
         $this->Paginator->paginate($query, $settings);
     }

+ 2 - 2
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -446,7 +446,7 @@ class PaginatorHelperTest extends TestCase
                 'sort' => 'date',
                 'direction' => 'asc',
                 'page' => 1,
-                'prefix' => 'article',
+                'scope' => 'article',
             ]
         ];
 
@@ -784,7 +784,7 @@ class PaginatorHelperTest extends TestCase
             ['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']);