Skip to content

Commit

Permalink
[Intl] deprecate polyfills in favor of symfony/polyfill-intl-icu
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 4, 2020
1 parent eaac169 commit 7119bf4
Show file tree
Hide file tree
Showing 41 changed files with 239 additions and 47 deletions.
2 changes: 2 additions & 0 deletions Collator/Collator.php
Expand Up @@ -32,6 +32,8 @@
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
abstract class Collator
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/AmPmTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class AmPmTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/DayOfWeekTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class DayOfWeekTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/DayOfYearTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class DayOfYearTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/DayTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class DayTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/FullTransformer.php
Expand Up @@ -20,6 +20,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class FullTransformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/Hour1200Transformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class Hour1200Transformer extends HourTransformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/Hour1201Transformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class Hour1201Transformer extends HourTransformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/Hour2400Transformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class Hour2400Transformer extends HourTransformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/Hour2401Transformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class Hour2401Transformer extends HourTransformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/HourTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Eriksen Costa <eriksen.costa@infranology.com.br>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
abstract class HourTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/MinuteTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class MinuteTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/MonthTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class MonthTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/QuarterTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class QuarterTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/SecondTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class SecondTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/TimezoneTransformer.php
Expand Up @@ -19,6 +19,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class TimezoneTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/Transformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
abstract class Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/DateFormat/YearTransformer.php
Expand Up @@ -17,6 +17,8 @@
* @author Igor Wiedler <igor@wiedler.ch>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class YearTransformer extends Transformer
{
Expand Down
2 changes: 2 additions & 0 deletions DateFormatter/IntlDateFormatter.php
Expand Up @@ -45,6 +45,8 @@
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
abstract class IntlDateFormatter
{
Expand Down
2 changes: 2 additions & 0 deletions Exception/MethodArgumentNotImplementedException.php
Expand Up @@ -13,6 +13,8 @@

/**
* @author Eriksen Costa <eriksen.costa@infranology.com.br>
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class MethodArgumentNotImplementedException extends NotImplementedException
{
Expand Down
2 changes: 2 additions & 0 deletions Exception/MethodArgumentValueNotImplementedException.php
Expand Up @@ -13,6 +13,8 @@

/**
* @author Eriksen Costa <eriksen.costa@infranology.com.br>
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class MethodArgumentValueNotImplementedException extends NotImplementedException
{
Expand Down
2 changes: 2 additions & 0 deletions Exception/MethodNotImplementedException.php
Expand Up @@ -13,6 +13,8 @@

/**
* @author Eriksen Costa <eriksen.costa@infranology.com.br>
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class MethodNotImplementedException extends NotImplementedException
{
Expand Down
2 changes: 2 additions & 0 deletions Exception/NotImplementedException.php
Expand Up @@ -15,6 +15,8 @@
* Base exception class for not implemented behaviors of the intl extension in the Locale component.
*
* @author Eriksen Costa <eriksen.costa@infranology.com.br>
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
class NotImplementedException extends RuntimeException
{
Expand Down
32 changes: 32 additions & 0 deletions Globals/IntlGlobals.php
Expand Up @@ -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 <bschussek@gmail.com>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
abstract class IntlGlobals
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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]';
}

Expand All @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions Locale/Locale.php
Expand Up @@ -23,6 +23,8 @@
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
abstract class Locale
{
Expand Down
2 changes: 2 additions & 0 deletions NumberFormatter/NumberFormatter.php
Expand Up @@ -39,6 +39,8 @@
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal
*
* @deprecated since Symfony 5.3, use symfony/polyfill-intl-icu ^1.21 instead
*/
abstract class NumberFormatter
{
Expand Down
8 changes: 1 addition & 7 deletions 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
---------
Expand All @@ -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
37 changes: 37 additions & 0 deletions Resources/functions.php
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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);
}
}
28 changes: 21 additions & 7 deletions Resources/stubs/Collator.php
Expand Up @@ -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 <bschussek@gmail.com>
*/
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 <bschussek@gmail.com>
*/
class Collator extends IntlCollator
{
}
} else {
/**
* Stub implementation for the Collator class of the intl extension.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class Collator extends CollatorPolyfill
{
}
}

0 comments on commit 7119bf4

Please sign in to comment.