Skip to content

Commit 8e5ae16

Browse files
committed
Upgrade to cakephp 5.3 / cakephp migrations 5.x / users 16
1 parent 958fc5d commit 8e5ae16

36 files changed

Lines changed: 112 additions & 76 deletions

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-version: ['8.1', '8.2', '8.3']
16+
php-version: ['8.2', '8.3', '8.4']
1717
db-type: [sqlite, mysql, pgsql]
1818
prefer-lowest: ['']
1919

@@ -59,22 +59,22 @@ jobs:
5959
fi
6060
6161
- name: Setup problem matchers for PHPUnit
62-
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
62+
if: matrix.php-version == '8.2' && matrix.db-type == 'mysql'
6363
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
6464

6565
- name: Run PHPUnit
6666
run: |
6767
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
6868
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?encoding=utf8'; fi
6969
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
70-
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
70+
if [[ ${{ matrix.php-version }} == '8.2' ]]; then
7171
export CODECOVERAGE=1 && vendor/bin/phpunit --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
7272
else
7373
vendor/bin/phpunit
7474
fi
7575
7676
- name: Submit code coverage
77-
if: matrix.php-version == '8.1'
77+
if: matrix.php-version == '8.2'
7878
uses: codecov/codecov-action@v5
7979

8080
cs-stan:
@@ -87,7 +87,7 @@ jobs:
8787
- name: Setup PHP
8888
uses: shivammathur/setup-php@v2
8989
with:
90-
php-version: '8.1'
90+
php-version: '8.2'
9191
extensions: mbstring, intl, apcu
9292
coverage: none
9393

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
"source": "https://github.com/CakeDC/cakephp-api"
2828
},
2929
"require": {
30-
"php": ">=8.1",
30+
"php": ">=8.2",
3131
"ext-json": "*",
32-
"cakephp/cakephp": "^5.0",
33-
"cakedc/users": "^15.1",
32+
"cakephp/cakephp": "^5.1",
33+
"cakedc/users": "^16.0",
3434
"lcobucci/jwt": "^5.5.0",
35-
"firebase/php-jwt": "^6.3"
35+
"firebase/php-jwt": "^6.3 || ^7.0"
3636
},
3737
"require-dev": {
3838
"cakephp/cakephp-codesniffer": "^4.5",

config/Migrations/20180313201241_initial_jwt_auth.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* Copyright 2018 - 2020, Cake Development Corporation (https://www.cakedc.com)
46
*
@@ -9,11 +11,11 @@
911
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1012
*/
1113

12-
use Migrations\AbstractMigration;
14+
use Migrations\BaseMigration;
1315

14-
class InitialJwtAuth extends AbstractMigration
16+
class InitialJwtAuth extends BaseMigration
1517
{
16-
public function change()
18+
public function change(): void
1719
{
1820
$this->table('jwt_refresh_tokens', ['id' => false, 'primary_key' => ['id']])
1921
->addColumn('id', 'uuid', [

config/Migrations/20231003201241_auth_store.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* Copyright 2018 - 2020, Cake Development Corporation (https://www.cakedc.com)
46
*
@@ -9,11 +11,11 @@
911
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
1012
*/
1113

12-
use Migrations\AbstractMigration;
14+
use Migrations\BaseMigration;
1315

14-
class AuthStore extends AbstractMigration
16+
class AuthStore extends BaseMigration
1517
{
16-
public function change()
18+
public function change(): void
1719
{
1820
$this->table('auth_store', ['id' => false, 'primary_key' => ['id']])
1921
->addColumn('id', 'string', [

src/ApiInitializer.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,39 @@ class ApiInitializer implements AuthorizationServiceProviderInterface
3535
public function getAuthenticationService(): AuthenticationService
3636
{
3737
$service = new AuthenticationService();
38-
$service->loadIdentifier('Authentication.JwtSubject', []);
39-
$service->loadIdentifier('Authentication.Password', [
40-
'resolver' => [
41-
'className' => 'Authentication.Orm',
42-
'userModel' => 'CakeDC/Users.Users',
43-
'finder' => 'active',
44-
],
45-
]);
4638

4739
$service->loadAuthenticator('Authentication.Session', [
4840
'sessionKey' => 'Auth',
41+
'identifier' => [
42+
'Authentication.Password' => [
43+
'resolver' => [
44+
'className' => 'Authentication.Orm',
45+
'userModel' => 'CakeDC/Users.Users',
46+
'finder' => 'active',
47+
],
48+
],
49+
],
4950
]);
5051
$service->loadAuthenticator('CakeDC/Auth.Form', [
51-
// 'sessionKey' => 'Auth',
52+
'identifier' => [
53+
'Authentication.Password' => [
54+
'resolver' => [
55+
'className' => 'Authentication.Orm',
56+
'userModel' => 'CakeDC/Users.Users',
57+
'finder' => 'active',
58+
],
59+
],
60+
],
5261
]);
5362

54-
$service->loadIdentifier('Authentication.Token', [
55-
'dataField' => 'token',
56-
'tokenField' => 'api_token',
57-
]);
5863
$service->loadAuthenticator('Authentication.Token', [
5964
'queryParam' => 'token',
65+
'identifier' => [
66+
'Authentication.Token' => [
67+
'dataField' => 'token',
68+
'tokenField' => 'api_token',
69+
],
70+
],
6071
]);
6172

6273
$service->loadAuthenticator('Authentication.Jwt', [
@@ -66,6 +77,9 @@ public function getAuthenticationService(): AuthenticationService
6677
'algorithm' => 'HS512',
6778
'returnPayload' => false,
6879
'secretKey' => Configure::read('Api.Jwt.AccessToken.secret'),
80+
'identifier' => [
81+
'Authentication.JwtSubject' => [],
82+
],
6983
]);
7084

7185
return $service;

src/Model/Entity/AuthStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*
1111
* @property string $id
1212
* @property array|null $store
13-
* @property \Cake\I18n\FrozenTime $created
14-
* @property \Cake\I18n\FrozenTime $modified
13+
* @property \Cake\I18n\DateTime $created
14+
* @property \Cake\I18n\DateTime $modified
1515
*/
1616
class AuthStore extends Entity
1717
{

src/Rbac/ApiRbac.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ApiRbac implements RbacInterface
6868
*
6969
* @param array $config Class configuration
7070
*/
71-
public function __construct($config = [])
71+
public function __construct(array $config = [])
7272
{
7373
if (!isset($config['log'])) {
7474
$config['log'] = Configure::read('debug');

src/Rbac/CachedApiRbac.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ class CachedApiRbac extends ApiRbac
3232
*
3333
* @var array[] rules array
3434
*/
35-
protected $permissionsMap = [];
35+
protected array $permissionsMap = [];
3636

3737
/**
3838
* CachedApiRbac constructor.
3939
*
4040
* @param array $config Class configuration
4141
*/
42-
public function __construct($config = [])
42+
public function __construct(array $config = [])
4343
{
4444
parent::__construct($config);
4545
$this->permissionsMap = Cache::remember('api_permissions_map', function () {
@@ -52,7 +52,7 @@ public function __construct($config = [])
5252
*
5353
* @return array
5454
*/
55-
public function buildPermissionsMap()
55+
public function buildPermissionsMap(): array
5656
{
5757
$asArray = function ($permission, $key, $default = null) {
5858
if ($default !== null && !array_key_exists($key, $permission)) {
@@ -95,7 +95,7 @@ public function buildPermissionsMap()
9595
* @param \Psr\Http\Message\ServerRequestInterface $request request
9696
* @return bool true if there is a match in permissions
9797
*/
98-
public function checkPermissions($user, ServerRequestInterface $request)
98+
public function checkPermissions(array|\ArrayAccess $user, ServerRequestInterface $request): bool
9999
{
100100
$roleField = $this->getConfig('role_field');
101101
$defaultRole = $this->getConfig('default_role');

src/Rbac/Permissions/AbstractProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class AbstractProvider
3535
*
3636
* @param array $config config
3737
*/
38-
public function __construct($config = [])
38+
public function __construct(array $config = [])
3939
{
4040
$this->setConfig($config);
4141
$this->defaultPermissions = [
@@ -82,12 +82,12 @@ public function __construct($config = [])
8282
*
8383
* @return array Array of permissions
8484
*/
85-
abstract public function getPermissions();
85+
abstract public function getPermissions(): array;
8686

8787
/**
8888
* @return array
8989
*/
90-
public function getDefaultPermissions()
90+
public function getDefaultPermissions(): array
9191
{
9292
return $this->defaultPermissions;
9393
}
@@ -96,7 +96,7 @@ public function getDefaultPermissions()
9696
* @param array $defaultPermissions default permissions
9797
* @return void
9898
*/
99-
public function setDefaultPermissions($defaultPermissions)
99+
public function setDefaultPermissions(array $defaultPermissions): void
100100
{
101101
$this->defaultPermissions = $defaultPermissions;
102102
}

src/Rbac/Permissions/ApiConfigProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ApiConfigProvider extends AbstractProvider
3535
*
3636
* @return array Array of permissions
3737
*/
38-
public function getPermissions()
38+
public function getPermissions(): array
3939
{
4040
$autoload = $this->getConfig('autoload_config');
4141
if ($autoload) {
@@ -53,7 +53,7 @@ public function getPermissions()
5353
* @param string $key name of the configuration file to read permissions from
5454
* @return array permissions
5555
*/
56-
protected function _loadPermissions($key)
56+
protected function _loadPermissions(string $key): array
5757
{
5858
$permissions = null;
5959
try {

0 commit comments

Comments
 (0)