Skip to content

Commit cd5744c

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

49 files changed

Lines changed: 286 additions & 214 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.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: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
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",
39+
"cweagans/composer-patches": "^1.7",
3940
"endroid/qr-code": "^4",
4041
"google/recaptcha": "@stable",
4142
"laminas/laminas-diactoros": "^3.0",
@@ -59,9 +60,17 @@
5960
}
6061
},
6162
"prefer-stable": true,
63+
"extra": {
64+
"patches": {
65+
"league/flysystem-vfs": {
66+
"Fix null passed to str_replace in PHP 8.1+": "patches/flysystem-vfs-null-str-replace.patch"
67+
}
68+
}
69+
},
6270
"config": {
6371
"sort-packages": true,
6472
"allow-plugins": {
73+
"cweagans/composer-patches": true,
6574
"dealerdirect/phpcodesniffer-composer-installer": true
6675
}
6776
},

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', [
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a/src/VfsAdapter.php
2+
+++ b/src/VfsAdapter.php
3+
@@ -106,7 +106,7 @@ class VfsAdapter extends Local
4+
protected function wrapPath($path)
5+
{
6+
$scheme = $this->vfs->scheme().'://';
7+
- $path = str_replace($scheme, null, $path);
8+
+ $path = str_replace($scheme, '', $path ?? '');
9+
10+
return $scheme.$path;
11+
}

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/ApiPlugin.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Copyright 2016 - 2019, Cake Development Corporation (http://cakedc.com)
6+
*
7+
* Licensed under The MIT License
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright 2016 - 2019, Cake Development Corporation (http://cakedc.com)
11+
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
12+
*/
13+
14+
namespace CakeDC\Api;
15+
16+
use Cake\Console\CommandCollection;
17+
use Cake\Core\BasePlugin;
18+
use Cake\Core\Configure;
19+
use Cake\Core\ContainerInterface;
20+
use CakeDC\Api\Command\ServiceRoutesCommand;
21+
22+
/**
23+
* Api plugin
24+
*/
25+
class ApiPlugin extends BasePlugin
26+
{
27+
protected array $middlewares = [];
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function routes($routes): void
33+
{
34+
$middlewares = Configure::read('Api.Middleware', []);
35+
foreach ($middlewares as $alias => $middleware) {
36+
$class = $middleware['class'];
37+
if (array_key_exists('request', $middleware)) {
38+
$requestClass = $middleware['request'];
39+
$request = new $requestClass();
40+
if (array_key_exists('method', $middleware)) {
41+
$request = $request->{$middleware['method']}();
42+
}
43+
if (array_key_exists('params', $middleware)) {
44+
$options = $middleware['params'];
45+
$this->registerMiddleware($routes, $alias, new $class($request, $options));
46+
} else {
47+
$this->registerMiddleware($routes, $alias, new $class($request));
48+
}
49+
} else {
50+
if (array_key_exists('params', $middleware)) {
51+
$options = $middleware['params'];
52+
$this->registerMiddleware($routes, $alias, new $class($options));
53+
} else {
54+
$this->registerMiddleware($routes, $alias, new $class());
55+
}
56+
}
57+
}
58+
59+
parent::routes($routes);
60+
}
61+
62+
/**
63+
* Middleware registrator and holder.
64+
*
65+
* @param \Cake\Routing\RouteBuilder $routes Routes.
66+
* @param string $alias Middleware alias.
67+
* @param string $class Middleware class instance.
68+
* @return void
69+
*/
70+
protected function registerMiddleware($routes, $alias, $class)
71+
{
72+
$routes->registerMiddleware($alias, $class);
73+
$this->middlewares[$alias] = $class;
74+
}
75+
76+
/**
77+
* Register container services for this plugin.
78+
*
79+
* @param \Cake\Core\ContainerInterface $container The container to add services to.
80+
* @return void
81+
*/
82+
public function services(ContainerInterface $container): void
83+
{
84+
if (array_key_exists('apiParser', $this->middlewares)) {
85+
$this->middlewares['apiParser']->setContainer($container);
86+
}
87+
}
88+
89+
/**
90+
* Add console commands for the plugin.
91+
*
92+
* @param \Cake\Console\CommandCollection $commands The command collection to update
93+
* @return \Cake\Console\CommandCollection
94+
*/
95+
public function console(CommandCollection $commands): CommandCollection
96+
{
97+
return $commands->add('service routes', ServiceRoutesCommand::class);
98+
}
99+
}

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
{

0 commit comments

Comments
 (0)