From 549aec6ba1ca410110ad352037d7c2ed8fab3f7d Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 29 Nov 2026 11:04:32 +0100 Subject: [PATCH 1/2] add CakePHP 6 capabilities --- Dockerfile | 1 + Makefile | 13 ++++++--- README.md | 19 +++++++++++++ composer.json | 2 +- composer.lock | 27 ++++++++++--------- config/cakephp3.php | 1 + config/cakephp4.php | 1 + config/cakephp5.php | 1 + config/cakephp6.php | 65 +++++++++++++++++++++++++++++++++++++++++++++ nginx.conf | 4 +-- src/Factory.php | 6 ++--- src/FileVisitor.php | 6 ++--- src/Loader.php | 2 +- 13 files changed, 122 insertions(+), 26 deletions(-) create mode 100644 config/cakephp6.php diff --git a/Dockerfile b/Dockerfile index d6cd891d..1d82407e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,6 +41,7 @@ RUN ls -lah \ && make build-cakephp3-all CAKEPHP_SOURCE_DIR=/cakephp \ && make build-cakephp4-all CAKEPHP_SOURCE_DIR=/cakephp \ && make build-cakephp5-all CAKEPHP_SOURCE_DIR=/cakephp \ + && make build-cakephp6-all CAKEPHP_SOURCE_DIR=/cakephp \ && make build-authentication-all AUTHENTICATION_SOURCE_DIR=/authentication \ && make build-authorization-all AUTHORIZATION_SOURCE_DIR=/authorization \ && make build-chronos-all CHRONOS_SOURCE_DIR=/chronos \ diff --git a/Makefile b/Makefile index 1dce4259..0c6c43a3 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,9 @@ CAKEPHP5_RELEASES := \ 5.3|5.3.7|update \ 5.4|origin/5.x|update +CAKEPHP6_RELEASES := \ + 6.0|origin/6.x|update + CHRONOS_RELEASES := \ 1.x|origin/1.x|update \ 2.x|origin/2.x|update \ @@ -73,6 +76,7 @@ release_mode = $(word 3,$(subst |, ,$1)) CAKEPHP3_VERSIONS := $(foreach release,$(CAKEPHP3_RELEASES),$(call release_version,$(release))) CAKEPHP4_VERSIONS := $(foreach release,$(CAKEPHP4_RELEASES),$(call release_version,$(release))) CAKEPHP5_VERSIONS := $(foreach release,$(CAKEPHP5_RELEASES),$(call release_version,$(release))) +CAKEPHP6_VERSIONS := $(foreach release,$(CAKEPHP6_RELEASES),$(call release_version,$(release))) CHRONOS_VERSIONS := $(foreach release,$(CHRONOS_RELEASES),$(call release_version,$(release))) ELASTIC_VERSIONS := $(foreach release,$(ELASTIC_RELEASES),$(call release_version,$(release))) QUEUE_VERSIONS := $(foreach release,$(QUEUE_RELEASES),$(call release_version,$(release))) @@ -80,12 +84,13 @@ AUTHENTICATION_VERSIONS := $(foreach release,$(AUTHENTICATION_RELEASES),$(call r AUTHORIZATION_VERSIONS := $(foreach release,$(AUTHORIZATION_RELEASES),$(call release_version,$(release))) .PHONY: help clean deploy install \ - build-cakephp3-all build-cakephp4-all build-cakephp5-all \ + build-cakephp3-all build-cakephp4-all build-cakephp5-all build-cakephp6-all \ build-chronos-all build-elastic-all build-queue-all \ build-authentication-all build-authorization-all \ $(foreach version,$(CAKEPHP3_VERSIONS),build-cakephp-$(version)) \ $(foreach version,$(CAKEPHP4_VERSIONS),build-cakephp-$(version)) \ $(foreach version,$(CAKEPHP5_VERSIONS),build-cakephp-$(version)) \ + $(foreach version,$(CAKEPHP6_VERSIONS),build-cakephp-$(version)) \ $(foreach version,$(CHRONOS_VERSIONS),build-chronos-$(version)) \ $(foreach version,$(ELASTIC_VERSIONS),build-elastic-$(version)) \ $(foreach version,$(QUEUE_VERSIONS),build-queue-$(version)) \ @@ -105,7 +110,7 @@ help: @echo " deploy" @echo " Move built release directories from $(BUILD_DIR) into $(DEPLOY_DIR)." @echo " build-cakephp-" - @echo " Versions: $(CAKEPHP3_VERSIONS) $(CAKEPHP4_VERSIONS) $(CAKEPHP5_VERSIONS)" + @echo " Versions: $(CAKEPHP3_VERSIONS) $(CAKEPHP4_VERSIONS) $(CAKEPHP5_VERSIONS) $(CAKEPHP6_VERSIONS)" @echo " build-chronos-" @echo " Versions: $(CHRONOS_VERSIONS)" @echo " build-elastic-" @@ -116,7 +121,7 @@ help: @echo " Versions: $(AUTHENTICATION_VERSIONS)" @echo " build-authorization-" @echo " Versions: $(AUTHORIZATION_VERSIONS)" - @echo " build-cakephp3-all build-cakephp4-all build-cakephp5-all" + @echo " build-cakephp3-all build-cakephp4-all build-cakephp5-all build-cakephp6-all" @echo " build-chronos-all build-elastic-all build-queue-all" @echo " build-authentication-all build-authorization-all" @echo "" @@ -170,6 +175,7 @@ endef build-cakephp3-all: $(foreach version,$(CAKEPHP3_VERSIONS),build-cakephp-$(version)) build-cakephp4-all: $(foreach version,$(CAKEPHP4_VERSIONS),build-cakephp-$(version)) build-cakephp5-all: $(foreach version,$(CAKEPHP5_VERSIONS),build-cakephp-$(version)) +build-cakephp6-all: $(foreach version,$(CAKEPHP6_VERSIONS),build-cakephp-$(version)) build-chronos-all: $(foreach version,$(CHRONOS_VERSIONS),build-chronos-$(version)) build-elastic-all: $(foreach version,$(ELASTIC_VERSIONS),build-elastic-$(version)) build-queue-all: $(foreach version,$(QUEUE_VERSIONS),build-queue-$(version)) @@ -179,6 +185,7 @@ build-authorization-all: $(foreach version,$(AUTHORIZATION_VERSIONS),build-autho $(foreach release,$(CAKEPHP3_RELEASES),$(eval $(call build_docs,cakephp,CAKEPHP_SOURCE_DIR,cakephp,cakephp3,$(call release_version,$(release)),$(call release_tag,$(release)),$(call release_mode,$(release))))) $(foreach release,$(CAKEPHP4_RELEASES),$(eval $(call build_docs,cakephp,CAKEPHP_SOURCE_DIR,cakephp,cakephp4,$(call release_version,$(release)),$(call release_tag,$(release)),$(call release_mode,$(release))))) $(foreach release,$(CAKEPHP5_RELEASES),$(eval $(call build_docs,cakephp,CAKEPHP_SOURCE_DIR,cakephp,cakephp5,$(call release_version,$(release)),$(call release_tag,$(release)),$(call release_mode,$(release))))) +$(foreach release,$(CAKEPHP6_RELEASES),$(eval $(call build_docs,cakephp,CAKEPHP_SOURCE_DIR,cakephp,cakephp6,$(call release_version,$(release)),$(call release_tag,$(release)),$(call release_mode,$(release))))) $(foreach release,$(CHRONOS_RELEASES),$(eval $(call build_docs,chronos,CHRONOS_SOURCE_DIR,chronos,chronos,$(call release_version,$(release)),$(call release_tag,$(release)),$(call release_mode,$(release))))) $(foreach release,$(ELASTIC_RELEASES),$(eval $(call build_docs,elastic,ELASTIC_SOURCE_DIR,elastic-search,elastic,$(call release_version,$(release)),$(call release_tag,$(release)),$(call release_mode,$(release))))) $(foreach release,$(QUEUE_RELEASES),$(eval $(call build_docs,queue,QUEUE_SOURCE_DIR,queue,queue,$(call release_version,$(release)),$(call release_tag,$(release)),$(call release_mode,$(release))))) diff --git a/README.md b/README.md index 8ecef6ba..aa9af516 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,22 @@ cd ../cakephp/ && git checkout origin/5.x && cd - php bin/apitool.php generate --config cakephp5 --version 5.2 --tag origin/5.x --output-dir build/test/ ../cakephp ``` +### Building CakePHP 6.0 documentation + +Build the development documentation from `origin/6.x`: + +```sh +make build-cakephp-6.0 +``` + +The `build-cakephp6-all` target builds all configured 6.x versions. The Makefile +checks out the source branch and updates its dependencies, so use a clean CakePHP +clone. Output is written to `build/api/cakephp/6.0/`. + +To generate directly from an existing 6.x checkout: + +```sh +mkdir -p build/api/cakephp/6.0 +cp -r static/assets/* build/api/cakephp/6.0/ +php bin/apitool.php generate --config cakephp6 --version 6.0 --tag origin/6.x --output-dir build/api/cakephp/6.0/ ../cakephp +``` diff --git a/composer.json b/composer.json index 3278a7fd..e43596d5 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "cakephp/console": "^5.0", "composer/composer": "^2.0", "erusev/parsedown": "^1.7", - "nikic/php-parser": "^4.13", + "nikic/php-parser": "^5.6", "phpstan/phpdoc-parser": "^1.29.1", "twig/markdown-extra": "^3.0", "twig/twig": "^3.0" diff --git a/composer.lock b/composer.lock index f5e9c7d8..18983e54 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "bcb185113e89a14bb5158f0090c71418", + "content-hash": "85d6c5cb7f08a5bc981183e98b89c32d", "packages": [ { "name": "cakephp/collection", @@ -1174,25 +1174,26 @@ }, { "name": "nikic/php-parser", - "version": "v4.19.1", + "version": "v5.10.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b" + "reference": "95d3450d7b8421795182fb4e310aa3c949423fa7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4e1b88d21c69391150ace211e9eaf05810858d0b", - "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/95d3450d7b8421795182fb4e310aa3c949423fa7", + "reference": "95d3450d7b8421795182fb4e310aa3c949423fa7", "shasum": "" }, "require": { + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.1" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^9.0" }, "bin": [ "bin/php-parse" @@ -1200,7 +1201,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.x-dev" } }, "autoload": { @@ -1224,9 +1225,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.19.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.10.0" }, - "time": "2024-03-17T08:10:35+00:00" + "time": "2026-11-28T17:47:43+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -3127,12 +3128,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=8.1" }, - "platform-dev": [], - "plugin-api-version": "2.6.0" + "platform-dev": {}, + "plugin-api-version": "2.9.0" } diff --git a/config/cakephp3.php b/config/cakephp3.php index 83eada03..7c414107 100644 --- a/config/cakephp3.php +++ b/config/cakephp3.php @@ -22,6 +22,7 @@ 'project' => 'CakePHP', 'release' => 'Red Velvet', 'versions' => [ + '6.0' => '../6.0/', '5.4' => '../5.4/', '5.3' => '../5.3/', '5.2' => '../5.2/', diff --git a/config/cakephp4.php b/config/cakephp4.php index c350e17d..386cbaed 100644 --- a/config/cakephp4.php +++ b/config/cakephp4.php @@ -22,6 +22,7 @@ 'project' => 'CakePHP', 'release' => 'Strawberry', 'versions' => [ + '6.0' => '../6.0/', '5.4' => '../5.4/', '5.3' => '../5.3/', '5.2' => '../5.2/', diff --git a/config/cakephp5.php b/config/cakephp5.php index 78f4faed..d86ad03c 100644 --- a/config/cakephp5.php +++ b/config/cakephp5.php @@ -22,6 +22,7 @@ 'project' => 'CakePHP', 'release' => 'Chiffon', 'versions' => [ + '6.0' => '../6.0/', '5.4' => '../5.4/', '5.3' => '../5.3/', '5.2' => '../5.2/', diff --git a/config/cakephp6.php b/config/cakephp6.php new file mode 100644 index 00000000..ac0eeb61 --- /dev/null +++ b/config/cakephp6.php @@ -0,0 +1,65 @@ + [ + 'namespaces' => 'Cake', + 'sourceDirs' => ['src', 'config'], + 'exclude' => [ + 'classes' => [ + 'Cake\Collection\CollectionTrait', + 'Cake\Collection\ExtractTrait', + 'Cake\Datasource\EntityTrait', + 'Cake\Datasource\QueryTrait', + 'Cake\I18n\DateFormatTrait', + ], + ], + 'repo' => 'https://github.com/cakephp/cakephp', + ], + + 'Twig' => [ + 'templateDir' => 'templates', + 'globals' => [ + 'project' => 'CakePHP', + 'release' => '', + 'versions' => [ + '6.0' => '../6.0/', + '5.4' => '../5.4/', + '5.3' => '../5.3/', + '5.2' => '../5.2/', + '5.1' => '../5.1/', + '5.0' => '../5.0/', + '4.6' => '../4.6/', + '4.5' => '../4.5/', + '4.4' => '../4.4/', + '4.3' => '../4.3/', + '4.2' => '../4.2/', + '4.1' => '../4.1/', + '4.0' => '../4.0/', + '3.10' => '../3.10', + '3.9' => '../3.9/', + '3.8' => '../3.8/', + '3.7' => '../3.7/', + '3.6' => '../3.6/', + '3.5' => '../3.5/', + '3.4' => '../3.4/', + '3.3' => '../3.3/', + '3.2' => '../3.2/', + '3.1' => '../3.1/', + '3.0' => '../3.0/', + '2.10' => '../2.10/', + '2.9' => '../2.9/', + '2.8' => '../2.8/', + '2.7' => '../2.7/', + '2.6' => '../2.6/', + '2.5' => '../2.5/', + '2.4' => '../2.4/', + '2.3' => '../2.3/', + '2.2' => '../2.2/', + '2.1' => '../2.1/', + '2.0' => '../2.0/', + '1.3' => '../1.3/', + '1.2' => '../1.2/', + ], + ], + ], +]; diff --git a/nginx.conf b/nginx.conf index e24a0bba..85d78d7c 100644 --- a/nginx.conf +++ b/nginx.conf @@ -5,7 +5,7 @@ server { index index.html index.; server_name _; - location ~ "^/([345]\.\d+)/.*\.html$" { + location ~ "^/([3456]\.\d+)/.*\.html$" { try_files $uri @overview; } @@ -14,7 +14,7 @@ server { } location @overview { - rewrite "^/([345]\.\d+)/.*$" /$1/ redirect; + rewrite "^/([3456]\.\d+)/.*$" /$1/ redirect; rewrite "^/4\.next/.*$" /$1/ redirect; return 404; } diff --git a/src/Factory.php b/src/Factory.php index fe68cd80..276bcbdb 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -35,6 +35,7 @@ use PhpParser\Node\Const_; use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; +use PhpParser\Node\PropertyItem; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\ClassLike; @@ -42,7 +43,6 @@ use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Interface_; use PhpParser\Node\Stmt\Property; -use PhpParser\Node\Stmt\PropertyProperty; use PhpParser\Node\Stmt\Trait_; use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode; @@ -181,13 +181,13 @@ protected function createConstant( /** * @param \Cake\ApiDocs\Reflection\ReflectedClassLike $classLike Reflected classLike * @param \PhpParser\Node\Stmt\Property $classNode Property node - * @param \PhpParser\Node\Stmt\PropertyProperty $propNode Property node + * @param \PhpParser\Node\PropertyItem $propNode Property node * @return \Cake\ApiDocs\Reflection\ReflectedDefine */ protected function createProperty( ReflectedClassLike $classLike, Property $classNode, - PropertyProperty $propNode + PropertyItem $propNode ): ReflectedProperty { $doc = new DocBlock($classNode->getDocComment()?->getText()); $source = new Source( diff --git a/src/FileVisitor.php b/src/FileVisitor.php index 4a071489..a46aafed 100644 --- a/src/FileVisitor.php +++ b/src/FileVisitor.php @@ -31,7 +31,7 @@ use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Trait_; use PhpParser\Node\Stmt\Use_; -use PhpParser\Node\Stmt\UseUse; +use PhpParser\Node\UseItem; use PhpParser\NodeTraverser; use PhpParser\NodeVisitorAbstract; @@ -183,11 +183,11 @@ public function leaveNode(Node $node) } /** - * @param \PhpParser\Node\Stmt\UseUse $use Use node + * @param \PhpParser\Node\UseItem $use Use node * @param string|null $prefix Group use prefix * @return array */ - protected function normalizeUse(UseUse $use, ?string $prefix = null): array + protected function normalizeUse(UseItem $use, ?string $prefix = null): array { $name = (string)$use->name; if ($prefix) { diff --git a/src/Loader.php b/src/Loader.php index 4cfeca87..0928d758 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -41,7 +41,7 @@ class Loader public function __construct(string $projectPath) { $this->projectPath = $projectPath; - $this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $this->parser = (new ParserFactory())->createForNewestSupportedVersion(); } /** From 8b44fdf5f51933db43dd1d3d3e8827c5cea4faad Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 29 Nov 2026 11:09:19 +0100 Subject: [PATCH 2/2] fix older PHP version syntax problem --- .github/workflows/ci.yml | 3 +++ config/cakephp3.php | 2 ++ src/Loader.php | 9 +++++-- src/Project.php | 2 +- tests/loader.php | 58 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 tests/loader.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b32ff4dc..c61fcaab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,5 +50,8 @@ jobs: - name: Composer install run: composer install + - name: Run loader regression checks + run: php tests/loader.php + - name: Run PHP CodeSniffer run: vendor/bin/phpcs -q --report=checkstyle src/ | cs2pr diff --git a/config/cakephp3.php b/config/cakephp3.php index 7c414107..bdb3acb9 100644 --- a/config/cakephp3.php +++ b/config/cakephp3.php @@ -2,6 +2,8 @@ return [ 'Project' => [ + // Early 3.x releases use PHP 5 syntax, including curly-brace string offsets. + 'phpVersion' => '5.6', 'namespaces' => 'Cake', 'sourceDirs' => ['src', 'config'], 'exclude' => [ diff --git a/src/Loader.php b/src/Loader.php index 0928d758..dfe59fea 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -22,6 +22,7 @@ use PhpParser\NodeTraverser; use PhpParser\Parser; use PhpParser\ParserFactory; +use PhpParser\PhpVersion; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; @@ -37,11 +38,15 @@ class Loader /** * @param string $projectPath Project path + * @param string|null $phpVersion PHP syntax version, or null for the newest supported version */ - public function __construct(string $projectPath) + public function __construct(string $projectPath, ?string $phpVersion = null) { $this->projectPath = $projectPath; - $this->parser = (new ParserFactory())->createForNewestSupportedVersion(); + $factory = new ParserFactory(); + $this->parser = $phpVersion === null + ? $factory->createForNewestSupportedVersion() + : $factory->createForVersion(PhpVersion::fromString($phpVersion)); } /** diff --git a/src/Project.php b/src/Project.php index a57af45c..bf9d3693 100644 --- a/src/Project.php +++ b/src/Project.php @@ -59,7 +59,7 @@ public function __construct(string $projectPath, array $config) $this->namespaces[$namespace] = new ProjectNamespace($namespace, $namespace); } - $this->loader = new Loader($projectPath); + $this->loader = new Loader($projectPath, $config['phpVersion'] ?? null); $this->classLoader = $this->createClassLoader($projectPath); foreach ($this->_config['sourceDirs'] as $dir) { diff --git a/tests/loader.php b/tests/loader.php new file mode 100644 index 00000000..272fd69e --- /dev/null +++ b/tests/loader.php @@ -0,0 +1,58 @@ +namespaces['Example']->classes['Legacy'] ?? null; + if ($legacy === null || !isset($legacy->methods['first'])) { + throw new RuntimeException('Legacy string offsets must be parsed and reflected.'); + } + + file_put_contents($directory . '/modern.php', <<<'SOURCE' +loadFile($directory . '/modern.php', true); + if (count($nodes) !== 1 || !isset($nodes[0]->constants['NAME'], $nodes[0]->methods['name'])) { + throw new RuntimeException('Modern syntax must still be parsed and reflected.'); + } + + echo "Loader regression checks passed.\n"; +} finally { + foreach (glob($directory . '/*.php') as $file) { + unlink($file); + } + rmdir($directory); +}