From 6ad0169c4feea4881b64dd5cb00acf5e9ecd11dd Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 3 Nov 2020 15:08:49 +0100 Subject: [PATCH] [Intl] deprecate polyfills in favor of symfony/polyfill-intl-icu --- src/Symfony/Component/Form/composer.json | 2 +- .../Component/Intl/Collator/Collator.php | 2 + .../DateFormat/AmPmTransformer.php | 2 + .../DateFormat/DayOfWeekTransformer.php | 2 + .../DateFormat/DayOfYearTransformer.php | 2 + .../DateFormat/DayTransformer.php | 2 + .../DateFormat/FullTransformer.php | 2 + .../DateFormat/Hour1200Transformer.php | 2 + .../DateFormat/Hour1201Transformer.php | 2 + .../DateFormat/Hour2400Transformer.php | 2 + .../DateFormat/Hour2401Transformer.php | 2 + .../DateFormat/HourTransformer.php | 2 + .../DateFormat/MinuteTransformer.php | 2 + .../DateFormat/MonthTransformer.php | 2 + .../DateFormat/QuarterTransformer.php | 2 + .../DateFormat/SecondTransformer.php | 2 + .../DateFormat/TimezoneTransformer.php | 2 + .../DateFormatter/DateFormat/Transformer.php | 2 + .../DateFormat/YearTransformer.php | 2 + .../Intl/DateFormatter/IntlDateFormatter.php | 2 + .../MethodArgumentNotImplementedException.php | 2 + ...odArgumentValueNotImplementedException.php | 2 + .../MethodNotImplementedException.php | 2 + .../Exception/NotImplementedException.php | 2 + .../Component/Intl/Globals/IntlGlobals.php | 32 ++++++++++++++++ src/Symfony/Component/Intl/Locale/Locale.php | 2 + .../Intl/NumberFormatter/NumberFormatter.php | 2 + src/Symfony/Component/Intl/README.md | 8 +--- .../Component/Intl/Resources/functions.php | 37 +++++++++++++++++++ .../Intl/Resources/stubs/Collator.php | 28 ++++++++++---- .../Resources/stubs/IntlDateFormatter.php | 34 ++++++++++++----- .../Component/Intl/Resources/stubs/Locale.php | 34 ++++++++++++----- .../Intl/Resources/stubs/NumberFormatter.php | 34 ++++++++++++----- .../Intl/Tests/Collator/CollatorTest.php | 3 ++ .../AbstractIntlDateFormatterTest.php | 2 + .../DateFormatter/IntlDateFormatterTest.php | 3 ++ .../Tests/Globals/AbstractIntlGlobalsTest.php | 2 + .../Intl/Tests/Globals/IntlGlobalsTest.php | 3 ++ .../Globals/Verification/IntlGlobalsTest.php | 2 + .../AbstractNumberFormatterTest.php | 2 + .../NumberFormatter/NumberFormatterTest.php | 2 + src/Symfony/Component/Intl/composer.json | 10 ++--- .../Translation/Test/TranslatorTest.php | 2 + 43 files changed, 242 insertions(+), 48 deletions(-) create mode 100644 src/Symfony/Component/Intl/Resources/functions.php diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index b17ef9804901d..9f1656ac3cb4f 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -22,6 +22,7 @@ "symfony/intl": "^4.4|^5.0", "symfony/options-resolver": "^5.1", "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-intl-icu": "^1.21", "symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-php80": "^1.15", "symfony/property-access": "^5.0.8", @@ -48,7 +49,6 @@ "symfony/error-handler": "<4.4.5", "symfony/framework-bundle": "<4.4", "symfony/http-kernel": "<4.4", - "symfony/intl": "<4.4", "symfony/translation": "<4.4", "symfony/translation-contracts": "<1.1.7", "symfony/twig-bridge": "<4.4" diff --git a/src/Symfony/Component/Intl/Collator/Collator.php b/src/Symfony/Component/Intl/Collator/Collator.php index a43a4f69bf0eb..37a312280346a 100644 --- a/src/Symfony/Component/Intl/Collator/Collator.php +++ b/src/Symfony/Component/Intl/Collator/Collator.php @@ -32,6 +32,8 @@ * @author Bernhard Schussek * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ abstract class Collator { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php index 36a1294c70b92..7d370bfb87d95 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class AmPmTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php index f18abb9024b51..626d304b54f81 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class DayOfWeekTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php index 93c09d8b22da3..0d6f0b60cdf9d 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class DayOfYearTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php index 91676d3e58f19..47295252991ec 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class DayTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php index 2641528989609..709632f3172dd 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php @@ -20,6 +20,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class FullTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php index 59d10fe20dae4..34e4b3a5c5594 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class Hour1200Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php index f090ba4c27759..8e5eba1daf4fe 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class Hour1201Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php index 9ca6dfaacf94a..4296978713f13 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class Hour2400Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php index e4db51cdf0e1b..0db1a888b5ee7 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class Hour2401Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php index 349cd794de3ae..54dcbfe25d24d 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php @@ -17,6 +17,8 @@ * @author Eriksen Costa * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ abstract class HourTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php index 32f60d0928c55..30b76c9779383 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class MinuteTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php index fcc4c4fee9fe5..5db91114f8c79 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class MonthTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php index 6efea71f2ff44..71b95c8b9e7e0 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class QuarterTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php index bce89af1c95f3..b6428e114f21e 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class SecondTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php index 4a4e38e3e1a1a..ad243634d3790 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php @@ -19,6 +19,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class TimezoneTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php index 2351323946090..4ab993338224c 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ abstract class Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php index 8718094c06df0..8ed7b4165741b 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php @@ -17,6 +17,8 @@ * @author Igor Wiedler * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class YearTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index fee4f0a5d951b..c1c4715601897 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -45,6 +45,8 @@ * @author Bernhard Schussek * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ abstract class IntlDateFormatter { diff --git a/src/Symfony/Component/Intl/Exception/MethodArgumentNotImplementedException.php b/src/Symfony/Component/Intl/Exception/MethodArgumentNotImplementedException.php index bd6e4791debb1..d0a1d61c4c773 100644 --- a/src/Symfony/Component/Intl/Exception/MethodArgumentNotImplementedException.php +++ b/src/Symfony/Component/Intl/Exception/MethodArgumentNotImplementedException.php @@ -13,6 +13,8 @@ /** * @author Eriksen Costa + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class MethodArgumentNotImplementedException extends NotImplementedException { diff --git a/src/Symfony/Component/Intl/Exception/MethodArgumentValueNotImplementedException.php b/src/Symfony/Component/Intl/Exception/MethodArgumentValueNotImplementedException.php index ee9ebe5e2fb55..611e6ed02fb63 100644 --- a/src/Symfony/Component/Intl/Exception/MethodArgumentValueNotImplementedException.php +++ b/src/Symfony/Component/Intl/Exception/MethodArgumentValueNotImplementedException.php @@ -13,6 +13,8 @@ /** * @author Eriksen Costa + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class MethodArgumentValueNotImplementedException extends NotImplementedException { diff --git a/src/Symfony/Component/Intl/Exception/MethodNotImplementedException.php b/src/Symfony/Component/Intl/Exception/MethodNotImplementedException.php index 6a45d71a483b2..6eb7dc120d9e6 100644 --- a/src/Symfony/Component/Intl/Exception/MethodNotImplementedException.php +++ b/src/Symfony/Component/Intl/Exception/MethodNotImplementedException.php @@ -13,6 +13,8 @@ /** * @author Eriksen Costa + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class MethodNotImplementedException extends NotImplementedException { diff --git a/src/Symfony/Component/Intl/Exception/NotImplementedException.php b/src/Symfony/Component/Intl/Exception/NotImplementedException.php index 1413886b3e86d..83668993c4418 100644 --- a/src/Symfony/Component/Intl/Exception/NotImplementedException.php +++ b/src/Symfony/Component/Intl/Exception/NotImplementedException.php @@ -15,6 +15,8 @@ * Base exception class for not implemented behaviors of the intl extension in the Locale component. * * @author Eriksen Costa + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ class NotImplementedException extends RuntimeException { diff --git a/src/Symfony/Component/Intl/Globals/IntlGlobals.php b/src/Symfony/Component/Intl/Globals/IntlGlobals.php index d353368900d02..9eaf04355b512 100644 --- a/src/Symfony/Component/Intl/Globals/IntlGlobals.php +++ b/src/Symfony/Component/Intl/Globals/IntlGlobals.php @@ -11,12 +11,16 @@ namespace Symfony\Component\Intl\Globals; +use Symfony\Polyfill\Intl\Icu\Icu; + /** * Provides fake static versions of the global functions in the intl extension. * * @author Bernhard Schussek * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ abstract class IntlGlobals { @@ -61,6 +65,12 @@ abstract class IntlGlobals */ public static function isFailure(int $errorCode): bool { + if (class_exists(Icu::class)) { + return Icu::isFailure($errorCode); + } + + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + return isset(self::$errorCodes[$errorCode]) && $errorCode > self::U_ZERO_ERROR; } @@ -74,6 +84,12 @@ public static function isFailure(int $errorCode): bool */ public static function getErrorCode() { + if (class_exists(Icu::class)) { + return Icu::getErrorCode(); + } + + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + return self::$errorCode; } @@ -84,6 +100,12 @@ public static function getErrorCode() */ public static function getErrorMessage(): string { + if (class_exists(Icu::class)) { + return Icu::getErrorMessage(); + } + + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + return self::$errorMessage; } @@ -94,6 +116,12 @@ public static function getErrorMessage(): string */ public static function getErrorName(int $code): string { + if (class_exists(Icu::class)) { + return Icu::getErrorName($code); + } + + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + return self::$errorCodes[$code] ?? '[BOGUS UErrorCode]'; } @@ -107,6 +135,10 @@ public static function getErrorName(int $code): string */ public static function setError(int $code, string $message = '') { + if (class_exists(Icu::class)) { + return Icu::setError($code, $message); + } + if (!isset(self::$errorCodes[$code])) { throw new \InvalidArgumentException(sprintf('No such error code: "%s".', $code)); } diff --git a/src/Symfony/Component/Intl/Locale/Locale.php b/src/Symfony/Component/Intl/Locale/Locale.php index 6fbe50e3faa3b..b300e03599f5b 100644 --- a/src/Symfony/Component/Intl/Locale/Locale.php +++ b/src/Symfony/Component/Intl/Locale/Locale.php @@ -23,6 +23,8 @@ * @author Bernhard Schussek * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ abstract class Locale { diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index 40223dc86da6d..a298dcbf3ce49 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -39,6 +39,8 @@ * @author Bernhard Schussek * * @internal + * + * @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead */ abstract class NumberFormatter { diff --git a/src/Symfony/Component/Intl/README.md b/src/Symfony/Component/Intl/README.md index 03b50c91a048f..3911053dd759d 100644 --- a/src/Symfony/Component/Intl/README.md +++ b/src/Symfony/Component/Intl/README.md @@ -1,11 +1,7 @@ Intl Component ============= -A PHP replacement layer for the C intl extension that also provides access to -the localization data of the ICU library. - -The replacement layer is limited to the locale "en". If you want to use other -locales, you should [install the intl PHP extension][0] instead. +This package provides access to the CLDR localization data of the ICU library. Resources --------- @@ -17,5 +13,3 @@ Resources in the [main Symfony repository](https://github.com/symfony/symfony) * [Docker images with intl support](https://hub.docker.com/r/jakzal/php-intl) (for the Intl component development) - -[0]: https://php.net/intl.setup diff --git a/src/Symfony/Component/Intl/Resources/functions.php b/src/Symfony/Component/Intl/Resources/functions.php new file mode 100644 index 0000000000000..251d039fdd843 --- /dev/null +++ b/src/Symfony/Component/Intl/Resources/functions.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Component\Intl\Globals\IntlGlobals; + +if (!function_exists('intl_is_failure')) { + function intl_is_failure($error_code) + { + return IntlGlobals::isFailure($error_code); + } +} +if (!function_exists('intl_get_error_code')) { + function intl_get_error_code() + { + return IntlGlobals::getErrorCode(); + } +} +if (!function_exists('intl_get_error_message')) { + function intl_get_error_message() + { + return IntlGlobals::getErrorMessage(); + } +} +if (!function_exists('intl_error_name')) { + function intl_error_name($error_code) + { + return IntlGlobals::getErrorName($error_code); + } +} diff --git a/src/Symfony/Component/Intl/Resources/stubs/Collator.php b/src/Symfony/Component/Intl/Resources/stubs/Collator.php index 1977fdf6173f9..91acdf146d2c6 100644 --- a/src/Symfony/Component/Intl/Resources/stubs/Collator.php +++ b/src/Symfony/Component/Intl/Resources/stubs/Collator.php @@ -10,12 +10,26 @@ */ use Symfony\Component\Intl\Collator\Collator as IntlCollator; +use Symfony\Polyfill\Intl\Icu\Collator as CollatorPolyfill; -/** - * Stub implementation for the Collator class of the intl extension. - * - * @author Bernhard Schussek - */ -class Collator extends IntlCollator -{ +if (!class_exists(CollatorPolyfill::class)) { + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + + /** + * Stub implementation for the Collator class of the intl extension. + * + * @author Bernhard Schussek + */ + class Collator extends IntlCollator + { + } +} else { + /** + * Stub implementation for the Collator class of the intl extension. + * + * @author Bernhard Schussek + */ + class Collator extends CollatorPolyfill + { + } } diff --git a/src/Symfony/Component/Intl/Resources/stubs/IntlDateFormatter.php b/src/Symfony/Component/Intl/Resources/stubs/IntlDateFormatter.php index e5209b62cccd4..b8948c157bbd2 100644 --- a/src/Symfony/Component/Intl/Resources/stubs/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/Resources/stubs/IntlDateFormatter.php @@ -10,14 +10,30 @@ */ use Symfony\Component\Intl\DateFormatter\IntlDateFormatter as BaseIntlDateFormatter; +use Symfony\Polyfill\Intl\Icu\IntlDateFormatter as IntlDateFormatterPolyfill; -/** - * Stub implementation for the IntlDateFormatter class of the intl extension. - * - * @author Bernhard Schussek - * - * @see BaseIntlDateFormatter - */ -class IntlDateFormatter extends BaseIntlDateFormatter -{ +if (!class_exists(IntlDateFormatterPolyfill::class)) { + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + + /** + * Stub implementation for the IntlDateFormatter class of the intl extension. + * + * @author Bernhard Schussek + * + * @see BaseIntlDateFormatter + */ + class IntlDateFormatter extends BaseIntlDateFormatter + { + } +} else { + /** + * Stub implementation for the IntlDateFormatter class of the intl extension. + * + * @author Bernhard Schussek + * + * @see BaseIntlDateFormatter + */ + class IntlDateFormatter extends IntlDateFormatterPolyfill + { + } } diff --git a/src/Symfony/Component/Intl/Resources/stubs/Locale.php b/src/Symfony/Component/Intl/Resources/stubs/Locale.php index 8a3b89bc3efe7..5021fa0ceb773 100644 --- a/src/Symfony/Component/Intl/Resources/stubs/Locale.php +++ b/src/Symfony/Component/Intl/Resources/stubs/Locale.php @@ -10,14 +10,30 @@ */ use Symfony\Component\Intl\Locale\Locale as IntlLocale; +use Symfony\Polyfill\Intl\Icu\Locale as LocalePolyfill; -/** - * Stub implementation for the Locale class of the intl extension. - * - * @author Bernhard Schussek - * - * @see IntlLocale - */ -class Locale extends IntlLocale -{ +if (!class_exists(LocalePolyfill::class)) { + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + + /** + * Stub implementation for the Locale class of the intl extension. + * + * @author Bernhard Schussek + * + * @see IntlLocale + */ + class Locale extends IntlLocale + { + } +} else { + /** + * Stub implementation for the Locale class of the intl extension. + * + * @author Bernhard Schussek + * + * @see IntlLocale + */ + class Locale extends LocalePolyfill + { + } } diff --git a/src/Symfony/Component/Intl/Resources/stubs/NumberFormatter.php b/src/Symfony/Component/Intl/Resources/stubs/NumberFormatter.php index c8e689b3abbd6..7ec6e1c1028fb 100644 --- a/src/Symfony/Component/Intl/Resources/stubs/NumberFormatter.php +++ b/src/Symfony/Component/Intl/Resources/stubs/NumberFormatter.php @@ -10,14 +10,30 @@ */ use Symfony\Component\Intl\NumberFormatter\NumberFormatter as IntlNumberFormatter; +use Symfony\Polyfill\Intl\Icu\NumberFormatter as NumberFormatterPolyfill; -/** - * Stub implementation for the NumberFormatter class of the intl extension. - * - * @author Bernhard Schussek - * - * @see IntlNumberFormatter - */ -class NumberFormatter extends IntlNumberFormatter -{ +if (!class_exists(NumberFormatterPolyfill::class)) { + trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.'); + + /** + * Stub implementation for the NumberFormatter class of the intl extension. + * + * @author Bernhard Schussek + * + * @see IntlNumberFormatter + */ + class NumberFormatter extends IntlNumberFormatter + { + } +} else { + /** + * Stub implementation for the NumberFormatter class of the intl extension. + * + * @author Bernhard Schussek + * + * @see IntlNumberFormatter + */ + class NumberFormatter extends NumberFormatterPolyfill + { + } } diff --git a/src/Symfony/Component/Intl/Tests/Collator/CollatorTest.php b/src/Symfony/Component/Intl/Tests/Collator/CollatorTest.php index 0964e31e34c1e..2cf74afc828d0 100644 --- a/src/Symfony/Component/Intl/Tests/Collator/CollatorTest.php +++ b/src/Symfony/Component/Intl/Tests/Collator/CollatorTest.php @@ -14,6 +14,9 @@ use Symfony\Component\Intl\Collator\Collator; use Symfony\Component\Intl\Globals\IntlGlobals; +/** + * @group legacy + */ class CollatorTest extends AbstractCollatorTest { public function testConstructorWithUnsupportedLocale() diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php index cee6b548a29fb..e18b01f604e21 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/AbstractIntlDateFormatterTest.php @@ -21,6 +21,8 @@ * Test case for IntlDateFormatter implementations. * * @author Bernhard Schussek + * + * @group legacy */ abstract class AbstractIntlDateFormatterTest extends TestCase { diff --git a/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php b/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php index f674c657ed85f..145f4c8da663a 100644 --- a/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php @@ -14,6 +14,9 @@ use Symfony\Component\Intl\DateFormatter\IntlDateFormatter; use Symfony\Component\Intl\Globals\IntlGlobals; +/** + * @group legacy + */ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest { public function testConstructor() diff --git a/src/Symfony/Component/Intl/Tests/Globals/AbstractIntlGlobalsTest.php b/src/Symfony/Component/Intl/Tests/Globals/AbstractIntlGlobalsTest.php index 2cb49ef8275b3..5c4731babd8d2 100644 --- a/src/Symfony/Component/Intl/Tests/Globals/AbstractIntlGlobalsTest.php +++ b/src/Symfony/Component/Intl/Tests/Globals/AbstractIntlGlobalsTest.php @@ -17,6 +17,8 @@ * Test case for intl function implementations. * * @author Bernhard Schussek + * + * @group legacy */ abstract class AbstractIntlGlobalsTest extends TestCase { diff --git a/src/Symfony/Component/Intl/Tests/Globals/IntlGlobalsTest.php b/src/Symfony/Component/Intl/Tests/Globals/IntlGlobalsTest.php index 34e3a6a3a7875..27400e65fd74c 100644 --- a/src/Symfony/Component/Intl/Tests/Globals/IntlGlobalsTest.php +++ b/src/Symfony/Component/Intl/Tests/Globals/IntlGlobalsTest.php @@ -13,6 +13,9 @@ use Symfony\Component\Intl\Globals\IntlGlobals; +/** + * @group legacy + */ class IntlGlobalsTest extends AbstractIntlGlobalsTest { protected function getIntlErrorName($errorCode) diff --git a/src/Symfony/Component/Intl/Tests/Globals/Verification/IntlGlobalsTest.php b/src/Symfony/Component/Intl/Tests/Globals/Verification/IntlGlobalsTest.php index 4b390d58c1ea0..c7bc125b2e7c4 100644 --- a/src/Symfony/Component/Intl/Tests/Globals/Verification/IntlGlobalsTest.php +++ b/src/Symfony/Component/Intl/Tests/Globals/Verification/IntlGlobalsTest.php @@ -19,6 +19,8 @@ * intl functions with a specific version of ICU. * * @author Bernhard Schussek + * + * @group legacy */ class IntlGlobalsTest extends AbstractIntlGlobalsTest { diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php index 73c845180a34a..99c095977d769 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/AbstractNumberFormatterTest.php @@ -20,6 +20,8 @@ /** * Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known * behavior of PHP. + * + * @group legacy */ abstract class AbstractNumberFormatterTest extends TestCase { diff --git a/src/Symfony/Component/Intl/Tests/NumberFormatter/NumberFormatterTest.php b/src/Symfony/Component/Intl/Tests/NumberFormatter/NumberFormatterTest.php index 9e5a82fe5cfb5..aacd698994a78 100644 --- a/src/Symfony/Component/Intl/Tests/NumberFormatter/NumberFormatterTest.php +++ b/src/Symfony/Component/Intl/Tests/NumberFormatter/NumberFormatterTest.php @@ -17,6 +17,8 @@ /** * Note that there are some values written like -2147483647 - 1. This is the lower 32bit int max and is a known * behavior of PHP. + * + * @group legacy */ class NumberFormatterTest extends AbstractNumberFormatterTest { diff --git a/src/Symfony/Component/Intl/composer.json b/src/Symfony/Component/Intl/composer.json index ff93e44b860f4..2f29e466dac30 100644 --- a/src/Symfony/Component/Intl/composer.json +++ b/src/Symfony/Component/Intl/composer.json @@ -1,8 +1,8 @@ { "name": "symfony/intl", "type": "library", - "description": "A PHP replacement layer for the C intl extension that includes additional data from the ICU library.", - "keywords": ["intl", "icu", "internationalization", "localization", "i18n", "l10n"], + "description": "This package provides access to the CLDR localization data of the ICU library.", + "keywords": ["intl", "icu", "internationalization", "localization", "i18n", "l10n", "cldr"], "homepage": "https://symfony.com", "license": "MIT", "authors": [ @@ -25,18 +25,16 @@ ], "require": { "php": ">=7.2.5", - "symfony/polyfill-intl-icu": "~1.0", + "symfony/deprecation-contracts": "^2.1", "symfony/polyfill-php80": "^1.15" }, "require-dev": { "symfony/filesystem": "^4.4|^5.0" }, - "suggest": { - "ext-intl": "to use the component with locales other than \"en\"" - }, "autoload": { "psr-4": { "Symfony\\Component\\Intl\\": "" }, "classmap": [ "Resources/stubs" ], + "files": [ "Resources/functions.php" ], "exclude-from-classmap": [ "/Tests/" ] diff --git a/src/Symfony/Contracts/Translation/Test/TranslatorTest.php b/src/Symfony/Contracts/Translation/Test/TranslatorTest.php index 5bfb0f8df616a..4d84f4729f830 100644 --- a/src/Symfony/Contracts/Translation/Test/TranslatorTest.php +++ b/src/Symfony/Contracts/Translation/Test/TranslatorTest.php @@ -59,6 +59,8 @@ public function testTransChoiceWithExplicitLocale($expected, $id, $number) } /** + * @requires extension intl + * * @dataProvider getTransChoiceTests */ public function testTransChoiceWithDefaultLocale($expected, $id, $number)