├── .editorconfig ├── .github └── workflows │ └── ci.yml ├── CHANGELOG.md ├── CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpcs.xml.dist └── src └── Controller └── Component └── ApiPaginationComponent.php /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "*" ] 8 | schedule: 9 | - cron: "0 0 * * 0" # Runs at 00:00 UTC on Sun. 10 | 11 | permissions: 12 | contents: read 13 | 14 | jobs: 15 | ######################### 16 | # Run PHPUnit testsuite # 17 | ######################### 18 | testsuite: 19 | 20 | runs-on: ubuntu-latest 21 | 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3'] 26 | db-type: [mysql] 27 | prefer-lowest: ['', 'prefer-lowest'] 28 | 29 | steps: 30 | - uses: actions/checkout@v3 31 | 32 | - name: Setup MySQL 8 33 | if: matrix.db-type == 'mysql' 34 | run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:8 --default-authentication-plugin=mysql_native_password --disable-log-bin 35 | 36 | - name: Validate composer.json and composer.lock 37 | run: composer validate --strict 38 | 39 | - name: Get composer cache directory 40 | id: composer-cache 41 | run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT 42 | 43 | - name: Get date part for cache key 44 | id: key-date 45 | run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT 46 | 47 | - name: Cache composer dependencies 48 | uses: actions/cache@v3 49 | with: 50 | path: ${{ steps.composer-cache.outputs.dir }} 51 | key: test-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} 52 | 53 | - name: Setup PHP 54 | uses: shivammathur/setup-php@v2 55 | with: 56 | php-version: ${{ matrix.php-versions }} 57 | extensions: mbstring, intl 58 | 59 | - name: Install composer dependencies 60 | run: | 61 | if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then 62 | composer update --prefer-lowest --prefer-stable 63 | elif ${{ matrix.php-version == '8.2' }}; then 64 | composer update --ignore-platform-req=php 65 | else 66 | composer update 67 | fi 68 | 69 | - name: Wait for MySQL 70 | if: matrix.db-type == 'mysql' 71 | run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done; 72 | 73 | - name: Run PHPUnit testsuite 74 | run: | 75 | if [[ ${{ matrix.db-type }} == 'mysql' ]]; then 76 | export DB_URL='mysql://root:root@127.0.0.1/cakephp'; 77 | mysql -h 127.0.0.1 -u root -proot cakephp < ./tests/Schema/articles.sql 78 | fi 79 | vendor/bin/phpunit --stderr; 80 | 81 | ############## 82 | # Code style # 83 | ############## 84 | cs: 85 | 86 | runs-on: ubuntu-latest 87 | 88 | strategy: 89 | matrix: 90 | php-versions: ['7.4'] 91 | 92 | steps: 93 | - name: Checkout 94 | uses: actions/checkout@v3 95 | 96 | - name: Validate composer.json and composer.lock 97 | run: composer validate --strict 98 | 99 | - name: Get composer cache directory 100 | id: composer-cache 101 | run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT 102 | 103 | - name: Get date part for cache key 104 | id: key-date 105 | run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT 106 | 107 | - name: Cache composer dependencies 108 | uses: actions/cache@v3 109 | with: 110 | path: ${{ steps.composer-cache.outputs.dir }} 111 | key: cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} 112 | restore-keys: | 113 | cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} 114 | 115 | - name: Setup PHP 116 | uses: shivammathur/setup-php@v2 117 | with: 118 | php-version: ${{ matrix.php-versions }} 119 | extensions: mbstring, intl 120 | 121 | - name: Install composer dependencies 122 | run: composer update --no-interaction 123 | 124 | - name: Run CS check 125 | run: composer cs-check 126 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `cakephp-api-pagination` will be documented in this file. 4 | 5 | ## 1.0.1 - 2016-03-10 6 | 7 | - General code clean up. 8 | - Updated docblocks. 9 | - Set composer versions with tildes. 10 | - Clean up tests. 11 | 12 | ## 1.0.0 - 2015-12-06 13 | 14 | ### Added 15 | - Release stable! 16 | 17 | ### Fixed 18 | - Use an already available local config var. 19 | 20 | ## 0.0.9 - 2015-11-22 21 | 22 | ### Added 23 | - Added implementedEvents method to component. 24 | 25 | ### Fixed 26 | - Clean up markdown files. 27 | 28 | ## 0.0.8 - 2015-10-28 29 | 30 | ### Fixed 31 | - Better property name for paging info. 32 | - Fixed up formatting in changelog. 33 | 34 | ## 0.0.7 - 2015-10-18 35 | 36 | ### Added 37 | - Add some additional docs. 38 | - Added CONDUCT.md 39 | 40 | ### Fixed 41 | - Clean up tests a bit. 42 | 43 | ### Removed 44 | - Remove running tests in CS build. 45 | 46 | ## 0.0.6 - 2015-09-01 47 | 48 | ### Added 49 | - 100% coverage in tests. 50 | - Added an example of setting view variables to be explicit on beforeRender's 51 | expectations. 52 | 53 | ## 0.0.5 - 2015-08-28 54 | 55 | ### Added 56 | - Actual tests for ApiPaginationComponent's beforeRender of appropriate 57 | view var setting. 58 | 59 | ### Fixed 60 | - Updated link to have nice name in README. 61 | 62 | ### Removed 63 | - Removed an unused class that was being used in the test case. 64 | - Old bogus test code. 65 | 66 | ## 0.0.4 - 2015-08-15 67 | 68 | ### Added 69 | - More updates to the README/docs. 70 | - Renamed the `setVisible` method to` setVisibility`. 71 | - Started testing. 72 | - Filled in the changelog. 73 | 74 | ### Fixed 75 | - Fixed write/turn fatal error in PHP 5.4. 76 | 77 | ## 0.0.3 - 2015-07-27 78 | 79 | ### Added 80 | - More usage docs. 81 | 82 | ### Fixed 83 | - Fix operator precedence for checking for ApiPagination-able requests. 84 | 85 | ## 0.0.2 - 2015-07-27 86 | 87 | ### Added 88 | - A couple README updates. 89 | 90 | ### Fixed 91 | - Add "cakephp-plugin" type to composer.json so it actually installs as a CakePHP plugin. 92 | 93 | ## 0.0.1 - 2015-07-25 94 | 95 | ### Added 96 | - Project skeleton and initial version of the ApiPagination component. 97 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of 4 | fostering an open and welcoming community, we pledge to respect all people who 5 | contribute through reporting issues, posting feature requests, updating 6 | documentation, submitting pull requests or patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free 9 | experience for everyone, regardless of level of experience, gender, gender 10 | identity and expression, sexual orientation, disability, personal appearance, 11 | body size, race, ethnicity, age, religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic 20 | addresses, without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or 24 | reject comments, commits, code, wiki edits, issues, and other contributions 25 | that are not aligned to this Code of Conduct, or to ban temporarily or 26 | permanently any contributor for other behaviors that they deem inappropriate, 27 | threatening, offensive, or harmful. 28 | 29 | By adopting this Code of Conduct, project maintainers commit themselves to 30 | fairly and consistently applying these principles to every aspect of managing 31 | this project. Project maintainers who do not follow or enforce the Code of 32 | Conduct may be permanently removed from the project team. 33 | 34 | This code of conduct applies both within project spaces and in public spaces 35 | when an individual is representing the project or its community. 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 38 | reported by contacting a project maintainer at bryan@bryan-crowe.com. All 39 | complaints will be reviewed and investigated and will result in a response that 40 | is deemed necessary and appropriate to the circumstances. Maintainers are 41 | obligated to maintain confidentiality with regard to the reporter of an 42 | incident. 43 | 44 | 45 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 46 | version 1.3.0, available at 47 | [http://contributor-covenant.org/version/1/3/0/][version] 48 | 49 | [homepage]: http://contributor-covenant.org 50 | [version]: http://contributor-covenant.org/version/1/3/0/ 51 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/bcrowe/cakephp-api-pagination). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ composer test 29 | ``` 30 | 31 | 32 | **Happy coding**! 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Bryan Crowe 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CakePHP API Pagination 2 | 3 | [![Latest Version on Packagist][ico-version]][link-packagist] 4 | [![Software License][ico-license]](LICENSE.md) 5 | [![Build Status][ico-github]][link-github] 6 | [![Coverage Status][ico-scrutinizer]][link-scrutinizer] 7 | [![Quality Score][ico-code-quality]][link-code-quality] 8 | [![Total Downloads][ico-downloads]][link-downloads] 9 | 10 | This is a simple component for CakePHP 4.2+ which injects pagination information 11 | from CakePHP's Paginator into serialized JsonView and XmlView responses. 12 | 13 | See `1.x` and `2.x` releases and branches of this plugin for support of previous versions of CakePHP before `4.2`. 14 | 15 | ## Install 16 | 17 | Via Composer 18 | 19 | ``` bash 20 | $ composer require bcrowe/cakephp-api-pagination 21 | ``` 22 | 23 | Load the plugin by adding `$this->addPlugin('BryanCrowe/ApiPagination');` to the `bootsrap` method in your project’s `src/Application.php`: 24 | 25 | ``` php 26 | public function bootstrap(): void 27 | { 28 | parent::bootstrap(); 29 | 30 | // ... bootstrap code ... 31 | 32 | // load more plugins here 33 | 34 | $this->addPlugin('BryanCrowe/ApiPagination'); 35 | } 36 | ``` 37 | 38 | ## Usage 39 | 40 | Make sure your application has been set up to use data views; see the 41 | [Enabling Data Views in Your Application][link-dataviews] section of the CakePHP 42 | documentation. 43 | 44 | Then, load `ApiPaginationComponent`: 45 | 46 | ``` php 47 | $this->loadComponent('BryanCrowe/ApiPagination.ApiPagination'); 48 | ``` 49 | 50 | Then, go ahead and set your paginated view variable like so: 51 | 52 | ``` php 53 | $this->set('articles', $this->paginate($this->Articles)); 54 | $this->viewBuilder()->setOption('serialize', ['articles']); 55 | ``` 56 | **Note:** It is important that your `serialize` option is an array, e.g. 57 | `['articles']`, so that your pagination information can be set under its own 58 | pagination key. 59 | 60 | Your JsonView and XmlView responses will now contain the pagination information, 61 | and will look something like this: 62 | 63 | ``` json 64 | { 65 | "articles": ["...", "...", "..."], 66 | "pagination": { 67 | "finder": "all", 68 | "page": 1, 69 | "current": 20, 70 | "count": 5000, 71 | "perPage": 20, 72 | "prevPage": false, 73 | "nextPage": true, 74 | "pageCount": 250, 75 | "sort": null, 76 | "direction": false, 77 | "limit": null, 78 | "sortDefault": false, 79 | "directionDefault": false 80 | } 81 | } 82 | ``` 83 | 84 | ### Configuring the Pagination Output 85 | 86 | ApiPagination has four keys for configuration: `key`, `aliases`, `visible` and `model`. 87 | 88 | * `key` allows you to change the name of the pagination key. 89 | 90 | * `aliases` allows you to change names of the pagination detail keys. 91 | 92 | * `visible` allows you to set which pagination keys will be exposed in the 93 | response. **Note:** Whenever setting a key's visibility, make sure to use the 94 | aliased name if you've given it one. 95 | 96 | * `model` allows you to set the name of the model the pagination is applied on 97 | if the controller does not follow CakePHP conventions, e.g. `ArticlesIndexController`. 98 | Per default the model is the name of the controller, e.g. `Articles` for `ArticlesController`. 99 | 100 | An example using all these configuration keys: 101 | 102 | ``` php 103 | $this->loadComponent('BryanCrowe/ApiPagination.ApiPagination', [ 104 | 'key' => 'paging', 105 | 'aliases' => [ 106 | 'page' => 'currentPage', 107 | 'current' => 'resultCount' 108 | ], 109 | 'visible' => [ 110 | 'currentPage', 111 | 'resultCount', 112 | 'prevPage', 113 | 'nextPage' 114 | ], 115 | 'model' => 'Articles', 116 | ]); 117 | ``` 118 | 119 | This configuration would yield: 120 | 121 | ``` json 122 | { 123 | "articles": ["...", "...", "..."], 124 | "paging": { 125 | "prevPage": false, 126 | "nextPage": true, 127 | "currentPage": 1, 128 | "resultCount": 20 129 | } 130 | } 131 | ``` 132 | 133 | ## Changelog 134 | 135 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed 136 | recently. 137 | 138 | ## Testing 139 | 140 | ``` bash 141 | $ composer test 142 | ``` 143 | 144 | ## Contributing 145 | 146 | Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for 147 | details. 148 | 149 | ## Security 150 | 151 | If you discover any security related issues, please email bryan@bryan-crowe.com 152 | instead of using the issue tracker. 153 | 154 | ## Credits 155 | 156 | - [Bryan Crowe][link-author] 157 | - [All Contributors][link-contributors] 158 | 159 | ## License 160 | 161 | The MIT License (MIT). Please see [License File](LICENSE.md) for more 162 | information. 163 | 164 | [ico-version]: https://img.shields.io/packagist/v/bcrowe/cakephp-api-pagination.svg?style=flat-square 165 | [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square 166 | [ico-github]: https://github.com/bcrowe/cakephp-api-pagination/workflows/CI/badge.svg 167 | [ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/bcrowe/cakephp-api-pagination.svg?style=flat-square 168 | [ico-code-quality]: https://img.shields.io/scrutinizer/g/bcrowe/cakephp-api-pagination.svg?style=flat-square 169 | [ico-downloads]: https://img.shields.io/packagist/dt/bcrowe/cakephp-api-pagination.svg?style=flat-square 170 | 171 | [link-packagist]: https://packagist.org/packages/bcrowe/cakephp-api-pagination 172 | [link-github]: https://github.com/bcrowe/cakephp-api-pagination/actions 173 | [link-scrutinizer]: https://scrutinizer-ci.com/g/bcrowe/cakephp-api-pagination/code-structure 174 | [link-code-quality]: https://scrutinizer-ci.com/g/bcrowe/cakephp-api-pagination 175 | [link-downloads]: https://packagist.org/packages/bcrowe/cakephp-api-pagination 176 | [link-author]: https://github.com/bcrowe 177 | [link-contributors]: ../../contributors 178 | [link-dataviews]: https://book.cakephp.org/4/en/views/json-and-xml-views.html#enabling-data-views-in-your-application 179 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bcrowe/cakephp-api-pagination", 3 | "description": "CakePHP 4 plugin that injects pagination information into API responses.", 4 | "type": "cakephp-plugin", 5 | "keywords": [ 6 | "cakephp", "api", "pagination", "cakephp3", "cakephp4" 7 | ], 8 | "homepage": "https://github.com/bcrowe/cakephp-api-pagination", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Bryan Crowe", 13 | "email": "bryan@bryan-crowe.com", 14 | "homepage": "http://bryan-crowe.com", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=7.2", 20 | "cakephp/cakephp": "^4.2" 21 | }, 22 | "require-dev": { 23 | "phpunit/phpunit" : "^8.5.23", 24 | "scrutinizer/ocular": "1.7", 25 | "cakephp/cakephp-codesniffer": "^4.7" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "BryanCrowe\\ApiPagination\\": "src" 30 | } 31 | }, 32 | "autoload-dev": { 33 | "psr-4": { 34 | "BryanCrowe\\ApiPagination\\": "src", 35 | "BryanCrowe\\ApiPagination\\Test\\": "tests", 36 | "BryanCrowe\\ApiPagination\\TestApp\\": "tests/test_app/TestApp" 37 | } 38 | }, 39 | "scripts": { 40 | "test": "phpunit", 41 | "cs-check": "phpcs src/ tests/", 42 | "cs-fix": "phpcbf src/ tests/" 43 | }, 44 | "extra": { 45 | "branch-alias": { 46 | "dev-master": "1.0-dev" 47 | } 48 | }, 49 | "config": { 50 | "allow-plugins": { 51 | "dealerdirect/phpcodesniffer-composer-installer": true 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /phpcs.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests/bootstrap.php 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Controller/Component/ApiPaginationComponent.php: -------------------------------------------------------------------------------- 1 | 'pagination', 23 | 'aliases' => [], 24 | 'visible' => [], 25 | ]; 26 | 27 | /** 28 | * Holds the paging information array from the request. 29 | * 30 | * @var array 31 | */ 32 | protected $pagingInfo = []; 33 | 34 | /** 35 | * Injects the pagination info into the response if the current request is a 36 | * JSON or XML request with pagination. 37 | * 38 | * @param \Cake\Event\Event $event The Controller.beforeRender event. 39 | * @return void 40 | */ 41 | public function beforeRender(Event $event) 42 | { 43 | if (!$this->isPaginatedApiRequest()) { 44 | return; 45 | } 46 | 47 | $subject = $event->getSubject(); 48 | $modelName = ucfirst($this->getConfig('model', $subject->getName())); 49 | if (isset($this->getController()->getRequest()->getAttribute('paging')[$modelName])) { 50 | $this->pagingInfo = $this->getController()->getRequest()->getAttribute('paging')[$modelName]; 51 | } 52 | 53 | $config = $this->getConfig(); 54 | 55 | if (!empty($config['aliases'])) { 56 | $this->setAliases(); 57 | } 58 | 59 | if (!empty($config['visible'])) { 60 | $this->setVisibility(); 61 | } 62 | 63 | $subject->set($config['key'], $this->pagingInfo); 64 | $data = $subject->viewBuilder()->getOption('serialize') ?? []; 65 | 66 | if (is_array($data)) { 67 | $data[] = $config['key']; 68 | $subject->viewBuilder()->setOption('serialize', $data); 69 | } 70 | } 71 | 72 | /** 73 | * Aliases the default pagination keys to the new keys that the user defines 74 | * in the config. 75 | * 76 | * @return void 77 | */ 78 | protected function setAliases() 79 | { 80 | foreach ($this->getConfig('aliases') as $key => $value) { 81 | $this->pagingInfo[$value] = $this->pagingInfo[$key]; 82 | unset($this->pagingInfo[$key]); 83 | } 84 | } 85 | 86 | /** 87 | * Removes any pagination keys that haven't been defined as visible in the 88 | * config. 89 | * 90 | * @return void 91 | */ 92 | protected function setVisibility() 93 | { 94 | $visible = $this->getConfig('visible'); 95 | foreach ($this->pagingInfo as $key => $value) { 96 | if (!in_array($key, $visible)) { 97 | unset($this->pagingInfo[$key]); 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * Checks whether the current request is a JSON or XML request with 104 | * pagination. 105 | * 106 | * @return bool True if JSON or XML with paging, otherwise false. 107 | */ 108 | protected function isPaginatedApiRequest() 109 | { 110 | if ( 111 | $this->getController()->getRequest()->getAttribute('paging') 112 | && $this->getController()->getRequest()->is(['json', 'xml']) 113 | ) { 114 | return true; 115 | } 116 | 117 | return false; 118 | } 119 | } 120 | --------------------------------------------------------------------------------