diff --git a/composer.json b/composer.json index ceec6cfb..21ab12f9 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": ">=8.2", "spryker/cakephp-statemachine": "dev-master", "cakephp/plugin-installer": "^2.0.1", - "cakephp/cakephp": "^5.0.3", + "cakephp/cakephp": "^5.1.0", "cakephp/bake": "^3.0.2", "mobiledetect/mobiledetectlib": "4.*", "dereuromark/cakephp-comments": "dev-master", diff --git a/composer.lock b/composer.lock index 035975c1..4749e70a 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": "f11ab742af30b286c7a09c7ccbb189a6", + "content-hash": "6bdc2b01db87a5a5018c0311bac1fa10", "packages": [ { "name": "brick/math", @@ -68,26 +68,26 @@ }, { "name": "brick/varexporter", - "version": "0.4.0", + "version": "0.5.0", "source": { "type": "git", "url": "https://github.com/brick/varexporter.git", - "reference": "2fd038f7c9d12d468130c6e1b3ce06e4160a7dbb" + "reference": "84b2a7a91f69aa5d079aec5a0a7256ebf2dceb6b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/varexporter/zipball/2fd038f7c9d12d468130c6e1b3ce06e4160a7dbb", - "reference": "2fd038f7c9d12d468130c6e1b3ce06e4160a7dbb", + "url": "https://api.github.com/repos/brick/varexporter/zipball/84b2a7a91f69aa5d079aec5a0a7256ebf2dceb6b", + "reference": "84b2a7a91f69aa5d079aec5a0a7256ebf2dceb6b", "shasum": "" }, "require": { - "nikic/php-parser": "^4.0", + "nikic/php-parser": "^5.0", "php": "^7.4 || ^8.0" }, "require-dev": { "php-coveralls/php-coveralls": "^2.2", - "phpunit/phpunit": "^8.5 || ^9.0", - "vimeo/psalm": "5.15.0" + "phpunit/phpunit": "^9.3", + "psalm/phar": "5.21.1" }, "type": "library", "autoload": { @@ -105,7 +105,7 @@ ], "support": { "issues": "https://github.com/brick/varexporter/issues", - "source": "https://github.com/brick/varexporter/tree/0.4.0" + "source": "https://github.com/brick/varexporter/tree/0.5.0" }, "funding": [ { @@ -113,7 +113,7 @@ "type": "github" } ], - "time": "2023-09-01T21:10:07+00:00" + "time": "2024-05-10T17:15:19+00:00" }, { "name": "burzum/cakephp-service-layer", @@ -169,29 +169,29 @@ }, { "name": "cakephp/bake", - "version": "3.1.1", + "version": "3.2.0", "source": { "type": "git", "url": "https://github.com/cakephp/bake.git", - "reference": "2a30ba221859176dbe583783da7299bde95c8956" + "reference": "d9bbe8e359e3405485ac4df5589c7b2b909f2503" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cakephp/bake/zipball/2a30ba221859176dbe583783da7299bde95c8956", - "reference": "2a30ba221859176dbe583783da7299bde95c8956", + "url": "https://api.github.com/repos/cakephp/bake/zipball/d9bbe8e359e3405485ac4df5589c7b2b909f2503", + "reference": "d9bbe8e359e3405485ac4df5589c7b2b909f2503", "shasum": "" }, "require": { - "brick/varexporter": "^0.4.0", - "cakephp/cakephp": "^5.0.3", + "brick/varexporter": "^0.5.0", + "cakephp/cakephp": "^5.1", "cakephp/twig-view": "^2.0.0", - "nikic/php-parser": "^4.13.2 || ^5.0.0", + "nikic/php-parser": "^5.0.0", "php": ">=8.1" }, "require-dev": { "cakephp/cakephp-codesniffer": "^5.0.0", "cakephp/debug_kit": "^5.0.0", - "phpunit/phpunit": "^10.1.0" + "phpunit/phpunit": "^10.5.5 || ^11.1.3" }, "type": "cakephp-plugin", "autoload": { @@ -220,35 +220,35 @@ "issues": "https://github.com/cakephp/bake/issues", "source": "https://github.com/cakephp/bake" }, - "time": "2024-03-11T17:36:39+00:00" + "time": "2024-09-14T02:59:21+00:00" }, { "name": "cakephp/cakephp", - "version": "5.0.10", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/cakephp/cakephp.git", - "reference": "f0b88ba6cc42e319fd012a32e96af7b3826fefdc" + "reference": "eb61f6b7b7e9c39f91ccd5c48c82336128217e73" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cakephp/cakephp/zipball/f0b88ba6cc42e319fd012a32e96af7b3826fefdc", - "reference": "f0b88ba6cc42e319fd012a32e96af7b3826fefdc", + "url": "https://api.github.com/repos/cakephp/cakephp/zipball/eb61f6b7b7e9c39f91ccd5c48c82336128217e73", + "reference": "eb61f6b7b7e9c39f91ccd5c48c82336128217e73", "shasum": "" }, "require": { - "cakephp/chronos": "^3.0.2", - "composer/ca-bundle": "^1.2", + "cakephp/chronos": "^3.1", + "composer/ca-bundle": "^1.5", "ext-intl": "*", "ext-json": "*", "ext-mbstring": "*", - "laminas/laminas-diactoros": "^3.0", + "laminas/laminas-diactoros": "^3.3", "laminas/laminas-httphandlerrunner": "^2.6", "league/container": "^4.2", "php": ">=8.1", "psr/container": "^1.1 || ^2.0", "psr/http-client": "^1.0.2", - "psr/http-factory": "^1.0.2", + "psr/http-factory": "^1.1", "psr/http-message": "^1.1 || ^2.0", "psr/http-server-handler": "^1.0.2", "psr/http-server-middleware": "^1.0.2", @@ -287,8 +287,8 @@ "mockery/mockery": "^1.6", "paragonie/csp-builder": "^2.3 || ^3.0", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "1.11.*", - "phpunit/phpunit": "^10.1.0 <=10.5.3", + "phpstan/phpstan": "1.12.3", + "phpunit/phpunit": "^10.5.5 || ^11.1.3", "symplify/phpstan-rules": "^12.4" }, "suggest": { @@ -340,7 +340,7 @@ "issues": "https://github.com/cakephp/cakephp/issues", "source": "https://github.com/cakephp/cakephp" }, - "time": "2024-07-28T16:58:12+00:00" + "time": "2024-09-14T02:34:26+00:00" }, { "name": "cakephp/chronos", @@ -403,20 +403,20 @@ }, { "name": "cakephp/debug_kit", - "version": "5.0.6", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/cakephp/debug_kit.git", - "reference": "e3af2116c9a94a15d4cdf00835bb496d6f94f709" + "reference": "9df73d208464dd807e88b9d6b87ccc64f4c02f8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cakephp/debug_kit/zipball/e3af2116c9a94a15d4cdf00835bb496d6f94f709", - "reference": "e3af2116c9a94a15d4cdf00835bb496d6f94f709", + "url": "https://api.github.com/repos/cakephp/debug_kit/zipball/9df73d208464dd807e88b9d6b87ccc64f4c02f8d", + "reference": "9df73d208464dd807e88b9d6b87ccc64f4c02f8d", "shasum": "" }, "require": { - "cakephp/cakephp": "^5.0", + "cakephp/cakephp": "^5.1", "composer/composer": "^2.0", "doctrine/sql-formatter": "^1.1.3", "php": ">=8.1" @@ -424,7 +424,7 @@ "require-dev": { "cakephp/authorization": "^3.0", "cakephp/cakephp-codesniffer": "^5.0", - "phpunit/phpunit": "^10.1.0 <=10.5.3" + "phpunit/phpunit": "^10.5.5 || ^11.1.3" }, "suggest": { "ext-pdo_sqlite": "DebugKit needs to store panel data in a database. SQLite is simple and easy to use." @@ -464,7 +464,7 @@ "issues": "https://github.com/cakephp/debug_kit/issues", "source": "https://github.com/cakephp/debug_kit" }, - "time": "2024-03-04T15:03:18+00:00" + "time": "2024-09-14T03:01:20+00:00" }, { "name": "cakephp/localized", @@ -2142,12 +2142,12 @@ "source": { "type": "git", "url": "https://github.com/dereuromark/cakephp-feed.git", - "reference": "4c096b1b027a2880ed3557f0f967820e3d15e91f" + "reference": "966eb855746b2cb7c637890dafc92f726bd7a8c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dereuromark/cakephp-feed/zipball/4c096b1b027a2880ed3557f0f967820e3d15e91f", - "reference": "4c096b1b027a2880ed3557f0f967820e3d15e91f", + "url": "https://api.github.com/repos/dereuromark/cakephp-feed/zipball/966eb855746b2cb7c637890dafc92f726bd7a8c7", + "reference": "966eb855746b2cb7c637890dafc92f726bd7a8c7", "shasum": "" }, "require": { @@ -2190,7 +2190,7 @@ "issues": "https://github.com/dereuromark/cakephp-feed/issues", "source": "https://github.com/dereuromark/cakephp-feed" }, - "time": "2024-04-19T10:51:03+00:00" + "time": "2024-09-12T13:28:59+00:00" }, { "name": "dereuromark/cakephp-feedback", @@ -5188,25 +5188,27 @@ }, { "name": "nikic/php-parser", - "version": "v4.19.1", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b" + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" }, "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/683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", "shasum": "" }, "require": { + "ext-ctype": "*", + "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" @@ -5214,7 +5216,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -5238,9 +5240,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.1.0" }, - "time": "2024-03-17T08:10:35+00:00" + "time": "2024-07-01T20:03:41+00:00" }, { "name": "phenx/php-font-lib", @@ -9432,16 +9434,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.5.33", + "version": "10.5.34", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4def7a9cda75af9c2bc179ed53a8e41313e7f7cf" + "reference": "3c69d315bdf79080c8e115b69d1961c6905b0e18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4def7a9cda75af9c2bc179ed53a8e41313e7f7cf", - "reference": "4def7a9cda75af9c2bc179ed53a8e41313e7f7cf", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3c69d315bdf79080c8e115b69d1961c6905b0e18", + "reference": "3c69d315bdf79080c8e115b69d1961c6905b0e18", "shasum": "" }, "require": { @@ -9513,7 +9515,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.33" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.34" }, "funding": [ { @@ -9529,7 +9531,7 @@ "type": "tidelift" } ], - "time": "2024-09-09T06:06:56+00:00" + "time": "2024-09-13T05:19:38+00:00" }, { "name": "sebastian/cli-parser", diff --git a/plugins/Sandbox/src/Controller/CakeExamplesController.php b/plugins/Sandbox/src/Controller/CakeExamplesController.php index 2865f74a..feecbd7e 100644 --- a/plugins/Sandbox/src/Controller/CakeExamplesController.php +++ b/plugins/Sandbox/src/Controller/CakeExamplesController.php @@ -48,6 +48,32 @@ public function enums() { $this->set(compact('user')); } + /** + * @return \Cake\Http\Response|null|void + */ + public function enumValidation() { + $table = $this->fetchTable('Sandbox.SandboxUsers'); + $table->getValidator()->add('status', 'validEnum', [ + 'rule' => ['enumOnly', [UserStatus::Active, UserStatus::Inactive]], + 'message' => 'Invalid enum value.', + ]); + + $user = $table->newEmptyEntity(); + + if ($this->request->is(['post', 'put'])) { + $user = $table->patchEntity($user, $this->request->getData()); + $value = $this->request->getData('status'); + $label = UserStatus::tryFrom((int)$value)?->label(); + if (!$user->getErrors()) { + $this->Flash->success('Value posted: `' . $value . '` (`' . $label . '`)'); + } else { + $this->Flash->error('Value posted: `' . $value . '` (`' . $label . '`)'); + } + } + + $this->set(compact('user')); + } + /** * @return void */ diff --git a/plugins/Sandbox/templates/CakeExamples/enum_validation.php b/plugins/Sandbox/templates/CakeExamples/enum_validation.php new file mode 100644 index 00000000..e9421449 --- /dev/null +++ b/plugins/Sandbox/templates/CakeExamples/enum_validation.php @@ -0,0 +1,50 @@ + + +append('script'); ?> + + + + +end(); ?> + +
+With CakePHP 5.1 we can now use improved validation for enums in our apps. enumOnly() and enumExcept() are now available. +
+ ++ Let's use the `UserStatus` backed enum (int values and string labels) to test it. It can be found in source code for details. +
+ +getValidator()->add('status', 'validEnum', [ + 'rule' => ['enumOnly', [UserStatus::Active, UserStatus::Inactive]], + 'message' => 'Invalid enum value.' +]); +CODE; + + echo $this->Highlighter->highlight($code, ['lang' => 'php']); +?> + ++ We left the "Deleted" status in there on purpose. Usually it would not be here. +
++ Here you can see that now the "user" can only select "Active" and "Inactive". "Deleted" is not an allowed value for this form, even + though it is in the enum. +
diff --git a/plugins/Sandbox/templates/CakeExamples/enums.php b/plugins/Sandbox/templates/CakeExamples/enums.php index 4f33aae1..a586f2c8 100644 --- a/plugins/Sandbox/templates/CakeExamples/enums.php +++ b/plugins/Sandbox/templates/CakeExamples/enums.php @@ -117,3 +117,8 @@ public function initialize(array \$config): void {Here you can see that it is now a backed enum object again.
+ +