Skip to content

Commit b8f1af7

Browse files
authored
Merge pull request #4 from tyrellsys/cake-4.x
Update for Cake 4.x
2 parents c820cd6 + 79655f0 commit b8f1af7

File tree

9 files changed

+121
-70
lines changed

9 files changed

+121
-70
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
composer.lock
33
vendor
4+
.phpunit.result.cache

Diff for: .travis.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ env:
66
- RUN_TESTS=1
77

88
php:
9-
- 5.6
10-
- 7.0
11-
- hhvm
9+
- 7.3
1210

1311
sudo: false
1412

1513
matrix:
1614
include:
17-
- php: 5.6
15+
- php: 7.2
1816
env: PHPCS=1 RUN_TESTS=0
1917

2018
before_script:
@@ -23,7 +21,7 @@ before_script:
2321

2422
script:
2523
- sh -c "if [ '$RUN_TESTS' = '1' ]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi"
26-
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p -n --extensions=php --standard=psr2 ./src ./tests; fi"
24+
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p ./src ./tests; fi"
2725

2826
after_script:
2927
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi

Diff for: composer.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bcrowe/cakephp-api-pagination",
3-
"description": "CakePHP 3 plugin that injects pagination information into API responses.",
3+
"description": "CakePHP 4 plugin that injects pagination information into API responses.",
44
"type": "cakephp-plugin",
55
"keywords": [
66
"cakephp", "api", "pagination", "cakephp3"
@@ -16,13 +16,13 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.6",
20-
"cakephp/cakephp": "~3.6"
19+
"php": ">=7.2",
20+
"cakephp/cakephp": "^4.0"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit" : "~5.0",
24-
"scrutinizer/ocular": "1.1",
25-
"squizlabs/php_codesniffer": "~2.3.0"
23+
"phpunit/phpunit" : "^8.5",
24+
"scrutinizer/ocular": "1.7",
25+
"cakephp/cakephp-codesniffer": "~4.0.0"
2626
},
2727
"autoload": {
2828
"psr-4": {
@@ -37,7 +37,9 @@
3737
}
3838
},
3939
"scripts": {
40-
"test": "phpunit"
40+
"test": "phpunit",
41+
"cs-check": "phpcs src/ tests/",
42+
"cs-fix": "phpcbf src/ tests/"
4143
},
4244
"extra": {
4345
"branch-alias": {

Diff for: phpcs.xml.dist

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="CustomCakePHPCodeSniffer">
3+
4+
<exclude-pattern>tests/bootstrap.php</exclude-pattern>
5+
6+
<rule ref="vendor/cakephp/cakephp-codesniffer/CakePHP">
7+
<exclude name="CakePHP.Commenting"/>
8+
</rule>
9+
10+
</ruleset>
11+

Diff for: phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<logging>
3232
<log type="tap" target="build/report.tap"/>
3333
<log type="junit" target="build/report.junit.xml"/>
34-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
34+
<log type="coverage-html" target="build/coverage"/>
3535
<log type="coverage-text" target="build/coverage.txt"/>
3636
<log type="coverage-clover" target="build/logs/clover.xml"/>
3737
</logging>

Diff for: src/Controller/Component/ApiPaginationComponent.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace BryanCrowe\ApiPagination\Controller\Component;
35

46
use Cake\Controller\Component;
@@ -19,7 +21,7 @@ class ApiPaginationComponent extends Component
1921
protected $_defaultConfig = [
2022
'key' => 'pagination',
2123
'aliases' => [],
22-
'visible' => []
24+
'visible' => [],
2325
];
2426

2527
/**
@@ -33,7 +35,7 @@ class ApiPaginationComponent extends Component
3335
* Injects the pagination info into the response if the current request is a
3436
* JSON or XML request with pagination.
3537
*
36-
* @param \Cake\Event\Event $event The Controller.beforeRender event.
38+
* @param \Cake\Event\Event $event The Controller.beforeRender event.
3739
* @return void
3840
*/
3941
public function beforeRender(Event $event)
@@ -43,7 +45,7 @@ public function beforeRender(Event $event)
4345
}
4446

4547
$subject = $event->getSubject();
46-
$this->pagingInfo = $this->request->getParam('paging')[$subject->getName()];
48+
$this->pagingInfo = $this->getController()->getRequest()->getAttribute('paging')[$subject->getName()];
4749
$config = $this->getConfig();
4850

4951
if (!empty($config['aliases'])) {
@@ -55,7 +57,9 @@ public function beforeRender(Event $event)
5557
}
5658

5759
$subject->set($config['key'], $this->pagingInfo);
58-
$subject->viewVars['_serialize'][] = $config['key'];
60+
$data = $subject->viewBuilder()->getVar('_serialize') ?? [];
61+
$data[] = $config['key'];
62+
$subject->set('_serialize', $data);
5963
}
6064

6165
/**
@@ -96,8 +100,9 @@ protected function setVisibility()
96100
*/
97101
protected function isPaginatedApiRequest()
98102
{
99-
if ($this->request->getParam('paging') &&
100-
$this->request->is(['json', 'xml'])
103+
if (
104+
$this->getController()->getRequest()->getAttribute('paging')
105+
&& $this->getController()->getRequest()->is(['json', 'xml'])
101106
) {
102107
return true;
103108
}

Diff for: tests/Fixture/ArticlesFixture.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ArticlesFixture extends TestFixture
1111
'id' => ['type' => 'integer'],
1212
'title' => ['type' => 'string', 'null' => false],
1313
'body' => 'text',
14-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
14+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
1515
];
1616

1717
public $records = [
@@ -37,6 +37,6 @@ class ArticlesFixture extends TestFixture
3737
['title' => 'Post #20', 'body' => 'This is the article body.'],
3838
['title' => 'Post #21', 'body' => 'This is the article body.'],
3939
['title' => 'Post #22', 'body' => 'This is the article body.'],
40-
['title' => 'Post #23', 'body' => 'This is the article body.']
40+
['title' => 'Post #23', 'body' => 'This is the article body.'],
4141
];
4242
}

0 commit comments

Comments
 (0)