Skip to content

Commit 6c71b81

Browse files
committed
plugin version upgraded to support CakePHP 4.3
1 parent 082ccfb commit 6c71b81

30 files changed

+62
-191
lines changed

.semver

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
:major: 8
2+
:major: 9
33
:minor: 0
4-
:patch: 14
4+
:patch: 0
55
:special: ''

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
Releases for CakePHP 4.3
5+
-------------
6+
7+
* 9.0.0
8+
Initial version that support CakePHP 4.3
9+
10+
411
Releases for CakePHP 4.0
512
-------------
613

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Versions and branches
1515

1616
| CakePHP | CakeDC Api Plugin | Tag | Notes |
1717
| :-------------: | :------------------------: | :--: | :---- |
18+
| 4.3 | [9.x-cake4.3](https://github.com/cakedc/cakephp-api/tree/9.x-cake4.3) | 9.0.0 | unstable |
1819
| 4.0 | [8.x](https://github.com/cakedc/cakephp-api/tree/8.x) | 8.0.14 | unstable |
1920
| ^3.7 | [master](https://github.com/cakedc/cakephp-api/tree/master) | 7.0.0 | stable |
2021
| ^3.7 <4.0 | [7.x](https://github.com/cakedc/cakephp-api/tree/7.x) | 7.1.0 | stable |
@@ -43,6 +44,6 @@ This repository follows the [CakeDC Plugin Standard](http://cakedc.com/plugin-st
4344
License
4445
-------
4546

46-
Copyright 2016-2018 Cake Development Corporation (CakeDC). All rights reserved.
47+
Copyright 2016-2022 Cake Development Corporation (CakeDC). All rights reserved.
4748

4849
Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
"require": {
3030
"php": ">=7.4",
3131
"ext-json": "*",
32-
"cakephp/cakephp": "^4.2",
33-
"cakedc/users": "^9.1",
32+
"cakephp/cakephp": "^4.3",
33+
"cakedc/users": "dev-11.next-cake4",
3434
"lcobucci/jwt": "~4.0.0",
3535
"firebase/php-jwt": "^5.0"
3636
},
3737
"require-dev": {
3838
"brianium/paratest": "^6.3",
3939
"cakephp/cakephp-codesniffer": "^4.0",
4040
"league/flysystem-vfs": "^1.0",
41-
"phpunit/phpunit": "^9.4",
41+
"phpunit/phpunit": "^9.5",
4242
"vlucas/phpdotenv": "^3.3"
4343
},
4444
"autoload": {
@@ -56,7 +56,10 @@
5656
"prefer-stable": true,
5757
"minimum-stability": "dev",
5858
"config": {
59-
"sort-packages": true
59+
"sort-packages": true,
60+
"allow-plugins": {
61+
"dealerdirect/phpcodesniffer-composer-installer": true
62+
}
6063
},
6164
"scripts": {
6265
"check": [

config/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
$versionPrefix = 'v';
2626
}
2727
if ($useVersioning) {
28-
$routes->connect('/:version/describe/*', [
28+
$routes->connect('/{version}/describe/*', [
2929
'plugin' => 'CakeDC/Api',
3030
'controller' => 'Api',
3131
'action' => 'describe'
3232
], ['version' => $versionPrefix . '\d+', 'pass' => []]);
33-
$routes->connect('/:version/list/*', [
33+
$routes->connect('/{version}/list/*', [
3434
'plugin' => 'CakeDC/Api',
3535
'controller' => 'Api',
3636
'action' => 'listing'

phpunit.xml.dist

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<php>
99
<ini name="memory_limit" value="-1"/>
1010
<ini name="apc.enable_cli" value="1"/>
11+
<env name="FIXTURE_SCHEMA_METADATA" value="./tests/schema.php"/>
1112
</php>
1213

1314
<!-- Add any additional test suites you want to run here -->
@@ -18,15 +19,9 @@
1819
</testsuites>
1920

2021
<!-- Setup a listener for fixtures -->
21-
<listeners>
22-
<listener
23-
class="\Cake\TestSuite\Fixture\FixtureInjector"
24-
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
25-
<arguments>
26-
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
27-
</arguments>
28-
</listener>
29-
</listeners>
22+
<extensions>
23+
<extension class="\Cake\TestSuite\Fixture\PHPUnitExtension" />
24+
</extensions>
3025

3126
<!-- Prevent coverage reports from looking in tests and vendors -->
3227
<filter>

src/ApiInitializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getAuthenticationService(): AuthenticationService
5454
'header' => 'Authorization',
5555
'queryParam' => 'token',
5656
'tokenPrefix' => 'bearer',
57-
'algorithms' => ['HS256', 'HS512'],
57+
'algorithm' => 'HS512',
5858
'returnPayload' => false,
5959
'secretKey' => Configure::read('Api.Jwt.AccessToken.secret'),
6060
]);

src/Service/Action/Auth/JwtRefreshAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function validates(): bool
6363
'header' => 'Authorization',
6464
'queryParam' => 'token',
6565
'tokenPrefix' => 'bearer',
66-
'algorithms' => ['HS256', 'HS512'],
66+
'algorithm' => 'HS512',
6767
'returnPayload' => false,
6868
'secretKey' => Configure::read('Api.Jwt.RefreshToken.secret'),
6969
];

src/Service/Action/Auth/JwtTokenTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use DateInterval;
2121
use DateTimeImmutable;
2222
use Lcobucci\JWT\Configuration;
23-
use Lcobucci\JWT\Signer\Hmac\Sha256;
2423
use Lcobucci\JWT\Signer\Hmac\Sha512;
2524
use Lcobucci\JWT\Signer\Key\InMemory;
2625

@@ -60,7 +59,7 @@ public function generateAccessToken($user, $timestamp)
6059
$subject = $user['id'];
6160
$audience = Router::url('/', true);
6261
$issuer = Router::url('/', true);
63-
$signer = new Sha256();
62+
$signer = new Sha512();
6463
$secret = Configure::read('Api.Jwt.AccessToken.secret');
6564

6665
$config = Configuration::forSymmetricSigner($signer, InMemory::plainText($secret));

src/Service/Action/Auth/ResetPasswordAction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ protected function _changePassword($userId)
104104
$user->id = $userId;
105105
try {
106106
$validator = $this->getUsersTable()->validationPasswordConfirm(new Validator());
107-
$user = $this->getUsersTable()->patchEntity($user, $this->getData(), ['validate' => $validator]);
107+
$this->getUsersTable()->setValidator('changePassV', $validator);
108+
$user = $this->getUsersTable()->patchEntity($user, $this->getData(), ['validate' => 'changePassV']);
108109
if ($user->getErrors()) {
109110
$message = __d('CakeDC/Api', 'Password could not be changed');
110111
throw new ValidationException($message, 0, null, $user->getErrors());

src/Service/Action/Extension/CrudHateoasExtension.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,13 @@ protected function _buildViewLinks(Action $action): array
128128
$parentRoutes = $parent->routes();
129129
$currentRoute = $this->_reverseRouter->findRoute($viewRoute, $parentRoutes);
130130
if ($currentRoute !== null) {
131-
unset($viewRoute['id']);
132131
$path = $parent->routeReverse($viewRoute);
133132
array_pop($viewRoute['pass']);
134133

135134
$indexName = $service->getName() . ':index';
136135
$indexPath = $this->_reverseRouter->parentViewPath($indexName, $action, 'index');
137136
}
138137
} else {
139-
unset($viewRoute['id']);
140138
$path = $service->routeReverse($viewRoute);
141139
array_pop($viewRoute['pass']);
142140

src/Service/Auth/Authenticate/JwtAuthenticate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class JwtAuthenticate extends BaseAuthenticate
6666
* Its value should be of form "Bearer <token>". If empty this query string
6767
* paramater is checked.
6868
* - `allowedAlgs` - List of supported verification algorithms.
69-
* Defaults to ['HS256']. See API of JWT::decode() for more info.
69+
* Defaults to ['HS512']. See API of JWT::decode() for more info.
7070
* - `queryDatasource` - Boolean indicating whether the `sub` claim of JWT
7171
* token should be used to query the user model and get user record. If
7272
* set to `false` JWT's payload is directly retured. Defaults to `true`.
@@ -102,7 +102,7 @@ public function __construct(Action $action, array $config = [])
102102
$this->setConfig($config);
103103

104104
if (empty($config['allowedAlgs'])) {
105-
$config['allowedAlgs'] = ['HS256'];
105+
$config['allowedAlgs'] = ['HS512'];
106106
}
107107

108108
parent::__construct($action, $config);

src/Service/FallbackService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ public function loadRoutes(): void
5555
$table = TableRegistry::getTableLocator()->get($this->_table);
5656

5757
$defaultOptions = $this->routerDefaultOptions();
58-
ApiRouter::scope('/', $defaultOptions, function (RouteBuilder $routes) use ($table, $defaultOptions) {
58+
$builder = ApiRouter::createRouteBuilder('/', []);
59+
$builder->scope('/', $defaultOptions, function (RouteBuilder $routes) use ($table, $defaultOptions) {
5960
$routes->setExtensions($this->_routeExtensions);
6061
$options = $defaultOptions;
6162
$options['map'] = array_merge($options['map'], [
6263
'describe' => ['action' => 'describe', 'method' => 'OPTIONS', 'path' => ''],
63-
'describeId' => ['action' => 'describe', 'method' => 'OPTIONS', 'path' => ':id'],
64+
'describeId' => ['action' => 'describe', 'method' => 'OPTIONS', 'path' => '{id}'],
6465
]);
6566
$routes->resources($this->getName(), $options, function (RouteBuilder $routes) use ($table) {
6667
if (is_array($this->_routeExtensions)) {
@@ -84,7 +85,7 @@ public function loadRoutes(): void
8485
$options = [
8586
'map' => [
8687
'describe' => ['action' => 'describe', 'method' => 'OPTIONS', 'path' => ''],
87-
'describeId' => ['action' => 'describe', 'method' => 'OPTIONS', 'path' => ':id'],
88+
'describeId' => ['action' => 'describe', 'method' => 'OPTIONS', 'path' => '{id}'],
8889
],
8990
];
9091
$routes->resources($className, $options);

src/Service/ListingService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class ListingService extends Service
3434
*/
3535
public function loadRoutes(): void
3636
{
37-
ApiRouter::scope('/', function (RouteBuilder $routes) {
37+
$builder = ApiRouter::createRouteBuilder('/', []);
38+
$builder->scope('/', function (RouteBuilder $routes) {
3839
$routes->setExtensions($this->_routeExtensions);
3940
$routes->connect('/listing/', ['controller' => 'listing', 'action' => 'list']);
4041
});

src/Service/Service.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ public function resetRoutes(): void
345345
public function loadRoutes(): void
346346
{
347347
$defaultOptions = $this->routerDefaultOptions();
348-
ApiRouter::scope('/', $defaultOptions, function (RouteBuilder $routes) use ($defaultOptions) {
348+
$builder = ApiRouter::createRouteBuilder('/', []);
349+
$builder->scope('/', $defaultOptions, function (RouteBuilder $routes) use ($defaultOptions) {
349350
if (is_array($this->_routeExtensions)) {
350351
$routes->setExtensions($this->_routeExtensions);
351352
}

tests/App/Service/ArticlesService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class ArticlesService extends FallbackService
1919
{
2020
protected $_actions = [
21-
'tag' => ['method' => ['PUT', 'POST'], 'path' => 'tag/:id'],
22-
'untag' => ['method' => ['PUT', 'POST'], 'path' => 'untag/:id'],
21+
'tag' => ['method' => ['PUT', 'POST'], 'path' => 'tag/{id}'],
22+
'untag' => ['method' => ['PUT', 'POST'], 'path' => 'untag/{id}'],
2323
];
2424
}

tests/Fixture/ArticlesFixture.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@
2020
*/
2121
class ArticlesFixture extends TestFixture
2222
{
23-
/**
24-
* fields property
25-
*
26-
* @var array
27-
*/
28-
public $fields = [
29-
'id' => ['type' => 'integer'],
30-
'author_id' => ['type' => 'integer', 'null' => true],
31-
'title' => ['type' => 'string', 'null' => true],
32-
'body' => 'text',
33-
'published' => ['type' => 'string', 'length' => 1, 'default' => 'N'],
34-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
35-
];
36-
3723
/**
3824
* records property
3925
*

tests/Fixture/ArticlesTagsFixture.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@
1818
*/
1919
class ArticlesTagsFixture extends TestFixture
2020
{
21-
/**
22-
* fields property
23-
*
24-
* @var array
25-
*/
26-
public $fields = [
27-
'article_id' => ['type' => 'integer', 'null' => false],
28-
'tag_id' => ['type' => 'integer', 'null' => false],
29-
'_constraints' => [
30-
'unique_tag' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']],
31-
'tag_idx' => [
32-
'type' => 'foreign',
33-
'columns' => ['tag_id'],
34-
'references' => ['tags', 'id'],
35-
'update' => 'cascade',
36-
'delete' => 'cascade',
37-
],
38-
],
39-
];
40-
4121
/**
4222
* records property
4323
*

tests/Fixture/AuthorsFixture.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@
1818
*/
1919
class AuthorsFixture extends TestFixture
2020
{
21-
/**
22-
* fields property
23-
*
24-
* @var array
25-
*/
26-
public $fields = [
27-
'id' => ['type' => 'integer'],
28-
'first_name' => ['type' => 'string', 'default' => null],
29-
'last_name' => ['type' => 'string', 'default' => null],
30-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
31-
];
32-
3321
/**
3422
* records property
3523
*

tests/Fixture/JwtRefreshTokensFixture.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,6 @@
2020
*/
2121
class JwtRefreshTokensFixture extends TestFixture
2222
{
23-
/**
24-
* Fields
25-
*
26-
* @var array
27-
*/
28-
// @codingStandardsIgnoreStart
29-
public $fields = [
30-
'id' => ['type' => 'uuid', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
31-
'model' => ['type' => 'string', 'length' => 50, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
32-
'foreign_key' => ['type' => 'uuid', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
33-
'token' => ['type' => 'string', 'length' => 500, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
34-
'expired' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
35-
'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
36-
'modified' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
37-
'_constraints' => [
38-
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
39-
],
40-
'_options' => [
41-
'engine' => 'InnoDB',
42-
'collation' => 'utf8_general_ci',
43-
],
44-
];
45-
// @codingStandardsIgnoreEnd
46-
4723
/**
4824
* Records
4925
*

tests/Fixture/SocialAccountsFixture.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,6 @@
1818
*/
1919
class SocialAccountsFixture extends TestFixture
2020
{
21-
/**
22-
* Fields
23-
*
24-
* @var array
25-
*/
26-
// @codingStandardsIgnoreStart
27-
public $fields = [
28-
'id' => ['type' => 'uuid', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
29-
'user_id' => ['type' => 'uuid', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
30-
'provider' => ['type' => 'string', 'length' => 255, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null],
31-
'username' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
32-
'reference' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
33-
'avatar' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
34-
'description' => ['type' => 'text', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
35-
'token' => ['type' => 'string', 'length' => 500, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
36-
'token_secret' => ['type' => 'string', 'length' => 500, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null, 'fixed' => null],
37-
'token_expires' => ['type' => 'datetime', 'length' => null, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null],
38-
'active' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => true, 'comment' => '', 'precision' => null],
39-
'data' => ['type' => 'text', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
40-
'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
41-
'modified' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null],
42-
'_constraints' => [
43-
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
44-
],
45-
'_options' => [
46-
'engine' => 'InnoDB',
47-
'collation' => 'utf8_general_ci'
48-
],
49-
];
50-
// @codingStandardsIgnoreEnd
51-
5221
/**
5322
* Records
5423
*

tests/Fixture/TagsFixture.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@
1818
*/
1919
class TagsFixture extends TestFixture
2020
{
21-
/**
22-
* fields property
23-
*
24-
* @var array
25-
*/
26-
public $fields = [
27-
'id' => ['type' => 'integer', 'null' => false],
28-
'name' => ['type' => 'string', 'null' => false],
29-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
30-
];
31-
3221
/**
3322
* records property
3423
*

0 commit comments

Comments
 (0)