diff --git a/docs/en/appendices/6-0-migration-guide.md b/docs/en/appendices/6-0-migration-guide.md index 7343e6e4f4..2b2f62ea4e 100644 --- a/docs/en/appendices/6-0-migration-guide.md +++ b/docs/en/appendices/6-0-migration-guide.md @@ -27,8 +27,22 @@ deprecation warnings. table unless they are attached with the `implementedMethods` configuration set to `true`, a map of `alias => method` pairs, or a list of method names. +- The immutable `with*()` methods of `Response`, `ServerRequest`, + `Client\Response`, `Cookie` and `Link` are marked with PHP's `#[NoDiscard]` + attribute. Calling them without using the returned object now emits a warning. +- `StaticConfigTrait::parseDsn()` now URL-decodes all DSN components, including + the username, password, host and database name. Percent-encode literal `%` + characters in DSNs. + ## Breaking Changes +### Dependencies + +- CakePHP 6.0 requires `cakephp/chronos` 4.x. Review the Chronos 4 changes if + your application uses Chronos classes directly. +- The test suite requires PHPUnit 13. Update `phpunit/phpunit` in your + `composer.json` and review the PHPUnit 12 and 13 changelogs. + ### Renamed Methods Methods starting with a `_` have been renamed to **remove the leading underscore**. @@ -67,6 +81,8 @@ Some properties have also been renamed to better reflect their purpose. These ar - `Cake\ORM\Entity` - `$_accessible` has been renamed to `patchable` + - `$_fields` has been renamed to `dynamicFields`. Fields backed by declared + class properties are no longer stored in this array. - `Cake\View\View` - `$_helpers` has been renamed to `helperRegistry` as `$helpers` already exists to hold the configuration @@ -77,6 +93,10 @@ Some properties have also been renamed to better reflect their purpose. These ar - The `Cake\Command\Helper` namespace has been removed. Use the `Cake\Console\Helper` namespace for `BannerHelper`, `ProgressHelper`, `TableHelper`, and `TreeHelper`. +- The `Cake\ORM\Query` class alias has been removed. Use + `Cake\ORM\Query\SelectQuery`. +- `Cake\Container\DefinitionContainerInterface` has been renamed to + `Cake\Container\ContainerInterface`. ### Method Signatures @@ -88,25 +108,78 @@ Some properties have also been renamed to better reflect their purpose. These ar contains the full list. - The following methods now return `void`: `ServerRequest::allowMethod()`, `Configure::load()`, `ResponseEmitter::emit()`, `Session::close()`, - `Table::deleteOrFail()`, `FixtureInterface::insert()` and `truncate()`, + `Table::deleteOrFail()`, `Table::deleteManyOrFail()`, + `FixtureInterface::insert()` and `truncate()`, and `ConsoleInputArgument::validateChoice()` and `ConsoleInputOption::validateChoice()`. Remove assignments and conditions that depend on their former return values. Handle exceptions where applicable. +- The controller callbacks `Controller::beforeFilter()`, `beforeRender()`, + `afterFilter()` and `beforeRedirect()` now declare a `void` return type. Add + `: void` to overrides in your controllers, including `ErrorController`. - The callback parameters of `CsrfProtectionMiddleware::skipCheckCallback()`, `SessionCsrfProtectionMiddleware::skipCheckCallback()`, `View::cache()`, - `TestCase::withErrorReporting()`, `Table::executeTransaction()`, and - `AttributeCollection::filter()` now require a `Closure` instead of a general + `TestCase::withErrorReporting()`, `Table::executeTransaction()`, + `AttributeCollection::filter()`, `ValidationSet::allowEmpty()` and + `ValidationSet::requirePresence()` now require a `Closure` instead of a general `callable`. `ResultSetFactory::getDtoHydrator()` now returns a `Closure`. +- Class constants in the core now declare types, for example + `public const string BUILD_VALIDATOR_EVENT`. Subclasses that redefine these + constants must declare a compatible type. +- Several methods that were previously only annotated with `@method` are now + declared on their interfaces. Custom implementations must add them: + - `CollectionInterface::any()` + - `Datasource\QueryInterface::firstOrFail()` and `andWhere()` + - `Database\Schema\CollectionInterface::listTablesWithoutViews()` + - `TableSchemaInterface::column()`, `index()` and `constraint()` + - `PluginInterface::events()` +- `CollectionInterface::groupBy()` has a new `bool $preserveKeys = false` + parameter. Update custom collection implementations accordingly. +- `Table::updateAll()`, `deleteAll()` and `exists()` now accept + `ExpressionInterface|Closure|array|string|null` for their conditions. Widen + the parameter types of overrides. ### Console - The `validChoice` method on `ConsoleInputArgument` and `ConsoleInputOption` has been renamed to `validateChoice`. +- `Cake\Console\ConsoleIoInterface` has been added and is implemented by + `ConsoleIo`. The verbosity constants are defined on the interface. Type hints + have changed from `ConsoleIo` to `ConsoleIoInterface` in + `CommandInterface::run()`, `BaseCommand::run()`, `executeCommand()`, + `beforeExecute()`, `afterExecute()`, `CommandRunner::run()`, + `ConsoleOptionParser::parse()` and the `Cake\Console\Helper` constructor. + Update the signatures of overridden methods. +- `ConsoleInputArgument::__construct()` no longer accepts an array of + properties as its first argument. Pass the name as a string and use named + arguments for the other properties, or use `ConsoleOptionParser::addArgument()`. ### Command - Command args and io are now available as properties instead of them being passed down to the execute method. See the current state of [Commands](../console-commands/commands.md) for examples. +- `CommandInterface::run()` now has the signature + `run(array $argv, ?ConsoleIoInterface $io = null): ?int`. Commands must extend + `BaseCommand`; implementing `CommandInterface` alone is no longer sufficient + for `CommandRunner`. +- `BaseCommand::displayHelp()` and `setOutputLevel()` no longer receive the + arguments and io objects. Argument parsing has moved to the new + `parseArguments()` hook, and `setIo()` is now public. +- `executeCommand()` reuses the calling command's io object when no io is + passed, instead of creating a new `ConsoleIo`. +- Protected helper methods of core commands, such as + `RoutesGenerateCommand::splitArgs()`, `I18nExtractCommand` and + `PluginAssetsTrait` methods, no longer take `$args` and `$io` parameters. + Update subclasses of core commands accordingly. + +### Core + +- Classes using `StaticConfigTrait` now provide their DSN class map by + overriding `protected static function initDsnClassMap(): array`. The + `$dsnClassMap` property is declared by the trait and initialized lazily, so + redeclaring it in your class causes a fatal error. Use `getDsnClassMap()` to + read the map. +- `EventAwareApplicationInterface::pluginEvents()` and + `BaseApplication::pluginEvents()` have been removed. ### Event @@ -114,6 +187,10 @@ Some properties have also been renamed to better reflect their purpose. These ar parameters have been swapped. Calls which pass an options array as the 2nd argument will need to be updated to pass it as the 3rd argument instead or use named parameters. +- `EventList` no longer implements `ArrayAccess`. Use `hasEvent()`, iteration, + or `add()` instead. +- `EventManager::callListener()` now takes a `Closure`, and listeners are + stored as closures. This affects `EventManager` subclasses. ### Dependency Injection @@ -129,6 +206,9 @@ Some properties have also been renamed to better reflect their purpose. These ar [Auto-wiring](../development/dependency-injection#auto-wiring) for details. - `Container::defaultToShared()`, `enableAutoWiring()` and `disableAutoWiring()` return `static`. Update the return types of overrides accordingly. +- With auto-wiring enabled, `Container::has()` returns `true` for any class + that can be autoloaded. Use `hasDefinition()` to check whether a service has + been registered explicitly. ### Datasource @@ -163,9 +243,36 @@ Some properties have also been renamed to better reflect their purpose. These ar `binary` columns to `varbinary`. The `fixed` option is no longer used; `TableSchemaInterface::TYPE_VARBINARY` is available for the new type. +- The `Mysql` driver no longer detects MariaDB servers. + `Mysql::isMariadb()`, `Mariadb::isMariadb()`, the `Mysql::SERVER_TYPE_*` + constants and `Mysql::$serverType` have been removed. Use + `'driver' => Mariadb::class` for MariaDB connections to get correct feature + detection. `Mariadb::$featureVersionMap` has been renamed to + `$featureVersions`. +- `FunctionsBuilder::cast()` now returns a `CastExpression` instead of a + `FunctionExpression`. +- `ComparisonExpression`, `BetweenExpression`, `TupleComparison` and + `StringExpression` now implement `TypedResultInterface`. When these + expressions are selected as fields, comparison results are cast to booleans. +- `Query::newExpr()` has been removed. Use `expr()` instead. +- `TypeFactory::getMap()` no longer accepts a type argument. Use + `getMapped()` to look up a single type. +- `Cake\Database\ConstraintsInterface` has been removed. +- `SchemaDialect` has been reworked for custom drivers: `listTablesSql()` is + now protected and abstract, `listTablesWithoutViewsSql()` was added, and + `describeColumns()`, `describeIndexes()`, `describeForeignKeys()`, + `describeOptions()` and `columnDefinitionSql()` are abstract. The + `describe*Sql()` and `convert*Description()` methods have been removed. + ### Error -- `Debugger::outputMask()`, `setOutputMask()` have been removed. +- `Debugger::outputMask()`, `setOutputMask()` and the `outputMask` + configuration option have been removed. Sensitive keys are no longer masked + in debug output. +- `dd()` now accepts any number of variables and dumps each of them. The + `$showHtml` parameter has been removed. +- `ErrorLoggerInterface` now extends `Psr\Log\LoggerInterface`. Custom error + loggers must implement the PSR-3 logging methods. ### Http @@ -198,8 +305,32 @@ still uses other Diactoros classes or functions, declare `Cake\Http\Client\Auth\ProxyAuthenticationInterface`. Update overrides of `Client::createAuth()` to return `AuthenticationInterface`. See [Custom Authentication Strategies](../core-libraries/httpclient#custom-authentication-strategies). -- `Client::createRequest()` now accepts `array|string|null` for its `$data` - argument. Update the signatures of overrides accordingly. +- `ServerRequestFactory::createServerRequest()` now declares + `Cake\Http\ServerRequest` as its return type, and `Client::sendRequest()` + declares `Cake\Http\Client\Response`. +- `Client::createRequest()`, `doRequest()`, `post()`, `put()`, `patch()`, + `delete()`, `options()` and `trace()` now accept `array|string|null` for their + `$data` argument. Update the signatures of overrides accordingly. +- `Client::createAuth()` no longer accepts an `$options` argument, and + authentication classes are constructed with only the client. The deprecated + `$options` argument of `Client\Auth\Digest::__construct()` has been removed. +- The HTTP client cookie jar follows RFC 6265 more closely. Cookies without a + `Domain` attribute are only sent to the host that set them, IP hosts do not + use suffix matching, path matching respects segment boundaries, and the + default cookie path is the directory of the request path. +- `Client\Message::cookies()` has been removed. Use + `Client\Response::getCookies()` instead. +- `ResponseEmitter::__construct()` has a new `$flushOutputBuffers` parameter + and `emit()` has a new `?bool $bodyIsRange` parameter. Non-seekable bodies are + streamed, and no body is sent for `1xx` and `205` responses. +- `CsrfProtectionMiddleware` no longer accepts unsalted hexadecimal CSRF + tokens created by older CakePHP versions, and `isHexadecimalToken()` has been + removed. Clients with an old token cookie receive a new token after a failed + check. +- `Cookie::expand()` and `CookieCryptTrait` no longer parse the CakePHP 1.x + `key|value,key2|value2` cookie format. Such values are returned as strings. +- The `$value` argument of `HttpException::setHeader()` is now required and no + longer accepts `null`. - When following a `303` redirect, the HTTP client now changes non-`HEAD` requests to `GET` and removes the request body and its associated headers. Redirects to a different scheme, host, or port remove the original @@ -234,6 +365,14 @@ still uses other Diactoros classes or functions, declare `InvalidArgumentException`. See [Creating Scoped Clients](../core-libraries/httpclient#http_client_scoped_client). +### I18n + +- `Number::DEFAULT_LOCALE` has been removed. `Number` falls back to + `I18n::getLocale()` when no locale is given. Use `I18n::DEFAULT_LOCALE` if you + need the constant. +- `DateTime::toQuarter(true)` is no longer supported. Use `toQuarterRange()`. + `TimeHelper::toQuarter()` now always returns an integer. + ### ORM - The `_accessible` property inside Entities has been renamed to `patchable` @@ -246,18 +385,54 @@ still uses other Diactoros classes or functions, declare - `TranslateTrait::translation()` now only retrieves an existing translation and returns `null` when none exists. Use `getOrCreateTranslation()` if the previous create-on-access behavior is needed. +- `SelectQuery::disableHydration()` has been removed. Use + `Table::unhydratedFind()` to fetch arrays instead of entities. +- In the `associated` option of `newEntity()`, `patchEntity()` and `save()`, + every string key that is not a known option (such as `onlyIds`, `validate`, + `patchableFields`, `fields` or `atomic`) is treated as an association name. + Previously only keys starting with an uppercase letter were treated as + associations. Remove unknown option keys such as `accessibleFields`. +- `Association::__construct()` now has the signature + `__construct(string $alias, Table $sourceTable, array $options = [])`, and + `AssociationCollection::load()` takes the source table before `$options`. + The `sourceTable` option is no longer used. +- `Table::getDisplayField()` no longer returns `null`. ### Router -- `RouteBuilder` has adjusted the signature of `scope()`, `prefix()` and `resources()` - so the 2nd and 3rd parameters have been swapped. +- `RouteBuilder` has adjusted the signature of `scope()`, `prefix()`, `plugin()` + and `resources()` so the 2nd and 3rd parameters have been swapped. We recommend using named parameters to prevent confusion and make the code more readable. +- The `$options` parameter of `RouteBuilder::plugin()` has been renamed to + `$params`. The callbacks of `scope()`, `prefix()` and `plugin()` are now + required and must be a `Closure`. +- `RouteBuilder::connect()` no longer accepts a `Route` instance. Use + `RouteBuilder::add()` for prebuilt route objects. The first parameter of + `connect()` and `redirect()` has been renamed from `$route` to `$template`. +- `Route::$keys`, `Route::$options` and `Route::$defaults` can no longer be + modified outside the route class. `Route::hostMatches()` is now protected and + has a new `$hostPattern` parameter, and `persistParams()` has a new `$persist` + parameter. +- `RedirectRoute::$redirect` is now protected. String redirect targets are + passed as the `_redirect` default instead of `redirect`. ### Utility - The default placeholder format for `Text::insert()` has been changed. They now use `{foo}` instead of `:foo`. You can get the old behavior by using the `before` and `after` keys of `$options`. +- `Text::parseFileSize()` now uses `null` as the default for `$default`. When + `$default` is `null` an exception is thrown for invalid sizes. Passing `false` + is no longer allowed. + +### Validation + +- `ValidationRule` has been rewritten. Its constructor takes the rule closure, + name, message, `on` condition, `last` flag and pass arguments, which are + exposed as public readonly properties. `get()` and `isLast()` have been + removed, and `process()` no longer receives the providers. +- Rule providers are now resolved when a rule is added with `Validator::add()`. + Call `setProvider()` before adding rules that use the `provider` key. ### View @@ -278,9 +453,45 @@ still uses other Diactoros classes or functions, declare - Multicheckbox option labels cannot be disabled. Use an array for label attributes when calling `multiCheckbox()`; direct `MultiCheckboxWidget` callers must also pass an array for `label`. +- The default FormHelper container templates have changed. `inputContainer` is + now `