From 50992eafa2b1d78edf81991faac1427d91102632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Tue, 19 Nov 2019 02:11:56 +0100 Subject: [PATCH] Deprecated the usage of number unaware underscore naming strategy --- UPGRADE.md | 8 +++++++ .../ORM/Mapping/UnderscoreNamingStrategy.php | 9 ++++++++ .../Mapping/UnderscoreNamingStrategyTest.php | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php diff --git a/UPGRADE.md b/UPGRADE.md index f8ae5f03562..9794f968312 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -10,6 +10,14 @@ Method `Doctrine\ORM\AbstractQuery#useResultCache()` which could be used for bot To optimize DB interaction, `Doctrine\ORM\Tools\Pagination\Paginator` no longer fetches identifiers to be able to perform the pagination with join collections when max results isn't set in the query. +## Deprecated number unaware `Doctrine\ORM\Mapping\UnderscoreNamingStrategy` + +In the last patch of the `v2.6.x` series, we fixed a bug that was not converting names properly when they had numbers +(e.g.: `base64Encoded` was wrongly converted to `base64encoded` instead of `base64_encoded`). + +In order to not break BC we've introduced a way to enable the fixed behavior using a boolean constructor argument. This +argument will be removed in 3.0 and the default behavior will be the fixed one. + ## Deprecated: `Doctrine\ORM\AbstractQuery#useResultCache()` Method `Doctrine\ORM\AbstractQuery#useResultCache()` is deprecated because it is split into `enableResultCache()` diff --git a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php index 1c219caa2cc..f4b77b97faf 100644 --- a/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php +++ b/lib/Doctrine/ORM/Mapping/UnderscoreNamingStrategy.php @@ -22,12 +22,14 @@ use const CASE_LOWER; use const CASE_UPPER; +use const E_USER_DEPRECATED; use function preg_replace; use function strpos; use function strrpos; use function strtolower; use function strtoupper; use function substr; +use function trigger_error; /** * Naming strategy implementing the underscore naming convention. @@ -58,6 +60,13 @@ class UnderscoreNamingStrategy implements NamingStrategy */ public function __construct($case = CASE_LOWER, bool $numberAware = false) { + if (! $numberAware) { + @trigger_error( + 'Creating ' . self::class . ' without making it number aware is deprecated and will be removed in Doctrine 3.0.', + E_USER_DEPRECATED + ); + } + $this->case = $case; $this->pattern = $numberAware ? self::NUMBER_AWARE_PATTERN : self::DEFAULT_PATTERN; } diff --git a/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php b/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php new file mode 100644 index 00000000000..5d7782c1a30 --- /dev/null +++ b/tests/Doctrine/Tests/Mapping/UnderscoreNamingStrategyTest.php @@ -0,0 +1,22 @@ +expectDeprecationMessage('Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine 3.0.'); + new UnderscoreNamingStrategy(CASE_LOWER, false); + } +}