Skip to content

Commit 6b72439

Browse files
committed
upgrade to CakePHP 5.0
1 parent 2ba2294 commit 6b72439

File tree

104 files changed

+1223
-3220
lines changed

Some content is hidden

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

104 files changed

+1223
-3220
lines changed

.github/workflows/ci.yml

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# CI workflow adapted from https://github.com/cakephp/cakephp/blob/master/.github/workflows/ci.yml
2+
name: CI
3+
4+
on:
5+
push:
6+
pull_request:
7+
8+
jobs:
9+
testsuite:
10+
runs-on: ubuntu-22.04
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php-version: ['8.1', '8.2']
15+
db-type: [sqlite, mysql, pgsql]
16+
prefer-lowest: ['']
17+
18+
steps:
19+
- name: Setup MySQL latest
20+
if: matrix.db-type == 'mysql'
21+
run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql --default-authentication-plugin=mysql_native_password --disable-log-bin
22+
23+
- name: Setup PostgreSQL latest
24+
if: matrix.db-type == 'pgsql'
25+
run: docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=cakephp -p 5432:5432 -d postgres
26+
27+
- uses: actions/checkout@v2
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v2
31+
with:
32+
php-version: ${{ matrix.php-version }}
33+
extensions: mbstring, intl, apcu, memcached, redis, pdo_${{ matrix.db-type }}
34+
ini-values: apc.enable_cli = 1
35+
coverage: pcov
36+
37+
- name: Get composer cache directory
38+
id: composer-cache
39+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
40+
41+
- name: Get date part for cache key
42+
id: key-date
43+
run: echo "::set-output name=date::$(date +'%Y-%m')"
44+
45+
- name: Cache composer dependencies
46+
uses: actions/cache@v1
47+
with:
48+
path: ${{ steps.composer-cache.outputs.dir }}
49+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
50+
51+
- name: Composer install
52+
run: |
53+
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
54+
composer update --prefer-lowest --prefer-stable
55+
else
56+
composer update
57+
fi
58+
59+
- name: Setup problem matchers for PHPUnit
60+
if: matrix.php-version == '8.1' && matrix.db-type == 'mysql'
61+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
62+
63+
- name: Run PHPUnit
64+
run: |
65+
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi
66+
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:[email protected]/cakephp'; fi
67+
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:[email protected]/postgres'; fi
68+
if [[ ${{ matrix.php-version }} == '8.1' ]]; then
69+
export CODECOVERAGE=1 && vendor/bin/phpunit --stderr --verbose --coverage-clover=coverage.xml
70+
else
71+
vendor/bin/phpunit --stderr
72+
fi
73+
74+
- name: Submit code coverage
75+
if: matrix.php-version == '8.1'
76+
uses: codecov/codecov-action@v1
77+
78+
cs-stan:
79+
name: Coding Standard & Static Analysis
80+
runs-on: ubuntu-22.04
81+
82+
steps:
83+
- uses: actions/checkout@v2
84+
85+
- name: Setup PHP
86+
uses: shivammathur/setup-php@v2
87+
with:
88+
php-version: '8.1'
89+
extensions: mbstring, intl, apcu, memcached, redis
90+
tools: cs2pr
91+
coverage: none
92+
93+
- name: Get composer cache directory
94+
id: composer-cache
95+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
96+
97+
- name: Get date part for cache key
98+
id: key-date
99+
run: echo "::set-output name=date::$(date +'%Y-%m')"
100+
101+
- name: Cache composer dependencies
102+
uses: actions/cache@v1
103+
with:
104+
path: ${{ steps.composer-cache.outputs.dir }}
105+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
106+
107+
- name: composer install
108+
run: composer stan-setup
109+
110+
- name: Run PHP CodeSniffer
111+
run: composer cs-check
112+
continue-on-error: true
113+
114+
- name: Run psalm
115+
if: success() || failure()
116+
run: composer psalm
117+
continue-on-error: true
118+
119+
- name: Run phpstan
120+
if: success() || failure()
121+
run: composer stan
122+
continue-on-error: true

.semver

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
:major: 9
2+
:major: 10
33
:minor: 0
4-
:patch: 1
4+
:patch: 0
55
:special: ''

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
Changelog
22
=========
33

4-
Releases for CakePHP 4.3
4+
Releases for CakePHP 5.0
55
-------------
66

7+
* 10.0.0
8+
* Remove deprecates
9+
* Only middleware initialization allowed since 10.0
10+
* Cleanup auth layer. Remove inbuilt authentication and authorization. Using cakephp/authentication and cakephp/authorization plugins middlewares.
11+
712
* 9.0.0
813
Initial version that support CakePHP 4.3
914

README.md

+2-1
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+
| 5.0 | [10.x-cake5.0](https://github.com/cakedc/cakephp-api/tree/10.x-cake5.0) | 10.0.0 | unstable |
1819
| 4.3 | [9.x-cake4.3](https://github.com/cakedc/cakephp-api/tree/9.x-cake4.3) | 9.0.1 | unstable |
1920
| 4.0 | [8.x](https://github.com/cakedc/cakephp-api/tree/8.x) | 8.0.14 | unstable |
2021
| ^3.7 | [master](https://github.com/cakedc/cakephp-api/tree/master) | 7.0.0 | stable |
@@ -44,6 +45,6 @@ This repository follows the [CakeDC Plugin Standard](http://cakedc.com/plugin-st
4445
License
4546
-------
4647

47-
Copyright 2016-2022 Cake Development Corporation (CakeDC). All rights reserved.
48+
Copyright 2016-2023 Cake Development Corporation (CakeDC). All rights reserved.
4849

4950
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
"source": "https://github.com/CakeDC/cakephp-api"
2828
},
2929
"require": {
30-
"php": ">=7.4",
30+
"php": ">=8.1",
3131
"ext-json": "*",
32-
"cakephp/cakephp": "^4.3",
33-
"cakedc/users": "^11.0",
32+
"cakephp/cakephp": "5.x-dev",
33+
"cakedc/users": "12.next-cake5-dev",
3434
"lcobucci/jwt": "~4.0.0",
35-
"firebase/php-jwt": "^5.0"
35+
"firebase/php-jwt": "^6.3"
3636
},
3737
"require-dev": {
3838
"cakephp/cakephp-codesniffer": "~4.4.0",
3939
"league/flysystem-vfs": "^1.0",
40-
"phpunit/phpunit": "^9.5",
40+
"phpunit/phpunit": "^9.5.16",
4141
"vlucas/phpdotenv": "^3.3"
4242
},
4343
"autoload": {
@@ -75,7 +75,7 @@
7575
"test": "phpunit --stderr",
7676
"stan": "phpstan analyse src/",
7777
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ",
78-
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.2 && mv composer.backup composer.json",
78+
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^1.9.0 psalm/phar:^5.1.0 && mv composer.backup composer.json",
7979
"stan-rebuild-baseline": "phpstan analyse --configuration phpstan.neon --error-format baselineNeon src/ > phpstan-baseline.neon",
8080
"psalm-rebuild-baseline": "php vendor/psalm/phar/psalm.phar --show-info=false --set-baseline=psalm-baseline.xml src/",
8181
"rector": "rector process src/",

docs/Documentation/di.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
##Dependency Injection
2+
3+
The CakePHP service container enables you to manage class dependencies for your application services through dependency injection. Dependency injection automatically “injects” an Action's dependencies via the constructor without having to manually instantiate them.
4+
5+
### Api plugin preconfiguration for Dependency Injection
6+
7+
First of all, needs to load ContainerInjector middleware from App\Application class.
8+
9+
```php
10+
class Application extends BaseApplication
11+
{
12+
13+
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue
14+
{
15+
$middleware
16+
// ....
17+
->add(new ContainerInjectorMiddleware($this->getContainer()))
18+
// ....
19+
;
20+
}
21+
```
22+

phpstan-baseline.neon

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
parameters:
44
ignoreErrors:
5-
-
6-
message: "#^Instantiated class CakeDC\\\\Api\\\\Rbac\\\\Permissions\\\\AbstractProvider is abstract\\.$#"
7-
count: 1
8-
path: src\Rbac\ApiRbac.php
9-
105
-
116
message: "#^Call to an undefined method Cake\\\\ORM\\\\Table\\:\\:getRegisterValidators\\(\\)\\.$#"
127
count: 1

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ includes:
33

44
parameters:
55
level: 4
6-
autoload_files:
6+
bootstrapFiles:
77
- tests/bootstrap.php
88
ignoreErrors:
99

src/ApiInitializer.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,20 @@ public function getAuthenticationService(): AuthenticationService
3636
{
3737
$service = new AuthenticationService();
3838
$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+
]);
3946

40-
$service->loadIdentifier('Authentication.Password', []);
4147
$service->loadAuthenticator('Authentication.Session', [
4248
'sessionKey' => 'Auth',
4349
]);
50+
$service->loadAuthenticator('CakeDC/Auth.Form', [
51+
// 'sessionKey' => 'Auth',
52+
]);
4453

4554
$service->loadIdentifier('Authentication.Token', [
4655
'dataField' => 'token',

src/Collection.php

-68
This file was deleted.

0 commit comments

Comments
 (0)