N°9319 increase php min. version to 8.2 (#887)

* Update minimum PHP version to 8.2
* Fix previous wrong resolution of merge conflict
This commit is contained in:
jf-cbd
2026-04-20 14:47:44 +02:00
committed by GitHub
parent f439490bfc
commit 805087a01b
171 changed files with 5629 additions and 1446 deletions

View File

@@ -118,17 +118,15 @@ abstract class Collator
}
/**
* Not supported. Compare two Unicode strings.
* Compare two Unicode strings.
*
* @return int|false
*
* @see https://php.net/collator.compare
*
* @throws MethodNotImplementedException
*/
public function compare(string $string1, string $string2)
{
throw new MethodNotImplementedException(__METHOD__);
return strcasecmp($string1, $string2) ?: $string2 <=> $string1;
}
/**

View File

@@ -104,7 +104,7 @@ class FullTransformer
// handle unimplemented characters
if (false !== strpos($this->notImplementedChars, $dateChars[0])) {
throw new NotImplementedException(sprintf('Unimplemented date character "%s" in format "%s".', $dateChars[0], $this->pattern));
throw new NotImplementedException(\sprintf('Unimplemented date character "%s" in format "%s".', $dateChars[0], $this->pattern));
}
return '';
@@ -212,7 +212,7 @@ class FullTransformer
{
$specialCharsArray = str_split($specialChars);
$specialCharsMatch = implode('|', array_map(function ($char) {
$specialCharsMatch = implode('|', array_map(static function ($char) {
return $char.'+';
}, $specialCharsArray));

View File

@@ -53,7 +53,7 @@ class MonthTransformer extends Transformer
public function __construct()
{
if (0 === \count(self::$shortMonths)) {
self::$shortMonths = array_map(function ($month) {
self::$shortMonths = array_map(static function ($month) {
return substr($month, 0, 3);
}, self::$months);

View File

@@ -39,9 +39,9 @@ class QuarterTransformer extends Transformer
$map = [1 => '1st quarter', 2 => '2nd quarter', 3 => '3rd quarter', 4 => '4th quarter'];
return $map[$quarter];
} else {
return $quarter;
}
return $quarter;
}
}

View File

@@ -55,7 +55,7 @@ class TimezoneTransformer extends Transformer
return $dateTime->format('\G\M\TP');
}
return sprintf('GMT%s%d', $offset >= 0 ? '+' : '', $offset / 100);
return \sprintf('GMT%s%d', $offset >= 0 ? '+' : '', $offset / 100);
}
public function getReverseMatchingRegExp(int $length): string
@@ -97,12 +97,12 @@ class TimezoneTransformer extends Transformer
$signal = '-' === $matches['signal'] ? '+' : '-';
if (0 < $minutes) {
throw new NotImplementedException(sprintf('It is not possible to use a GMT time zone with minutes offset different than zero (0). GMT time zone tried: "%s".', $formattedTimeZone));
throw new NotImplementedException(\sprintf('It is not possible to use a GMT time zone with minutes offset different than zero (0). GMT time zone tried: "%s".', $formattedTimeZone));
}
return 'Etc/GMT'.(0 !== $hours ? $signal.$hours : '');
}
throw new \InvalidArgumentException(sprintf('The GMT time zone "%s" does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.', $formattedTimeZone));
throw new \InvalidArgumentException(\sprintf('The GMT time zone "%s" does not match with the supported formats GMT[+-]HH:MM or GMT[+-]HHMM.', $formattedTimeZone));
}
}

View File

@@ -22,7 +22,7 @@ class MethodArgumentNotImplementedException extends NotImplementedException
*/
public function __construct(string $methodName, string $argName)
{
$message = sprintf('The %s() method\'s argument $%s behavior is not implemented.', $methodName, $argName);
$message = \sprintf('The %s() method\'s argument $%s behavior is not implemented.', $methodName, $argName);
parent::__construct($message);
}
}

View File

@@ -24,7 +24,7 @@ class MethodArgumentValueNotImplementedException extends NotImplementedException
*/
public function __construct(string $methodName, string $argName, $argValue, string $additionalMessage = '')
{
$message = sprintf(
$message = \sprintf(
'The %s() method\'s argument $%s value %s behavior is not implemented.%s',
$methodName,
$argName,

View File

@@ -21,6 +21,6 @@ class MethodNotImplementedException extends NotImplementedException
*/
public function __construct(string $methodName)
{
parent::__construct(sprintf('The %s() is not implemented.', $methodName));
parent::__construct(\sprintf('The %s() is not implemented.', $methodName));
}
}

View File

@@ -108,10 +108,10 @@ abstract class Icu
public static function setError(int $code, string $message = '')
{
if (!isset(self::$errorCodes[$code])) {
throw new \InvalidArgumentException(sprintf('No such error code: "%s".', $code));
throw new \InvalidArgumentException(\sprintf('No such error code: "%s".', $code));
}
self::$errorMessage = $message ? sprintf('%s: %s', $message, self::$errorCodes[$code]) : self::$errorCodes[$code];
self::$errorMessage = $message ? \sprintf('%s: %s', $message, self::$errorCodes[$code]) : self::$errorCodes[$code];
self::$errorCode = $code;
}
}

View File

@@ -225,7 +225,7 @@ abstract class IntlDateFormatter
// behave like the intl extension
$argumentError = null;
if (!\is_int($datetime) && !$datetime instanceof \DateTimeInterface) {
$argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $datetime);
$argumentError = \sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $datetime);
}
if (null !== $argumentError) {

View File

@@ -0,0 +1,169 @@
<?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.
*/
namespace Symfony\Polyfill\Intl\Icu;
/**
* @author Ayesh Karunaratne <ayesh@aye.sh>
*
* @internal
*/
class IntlListFormatter
{
public const TYPE_AND = 0;
public const TYPE_OR = 1;
public const TYPE_UNITS = 2;
public const WIDTH_WIDE = 0;
public const WIDTH_SHORT = 1;
public const WIDTH_NARROW = 2;
private $type;
private $width;
private const TYPE_MAP = [
self::TYPE_AND => 'standard',
self::TYPE_OR => 'or',
self::TYPE_UNITS => 'unit',
];
private const WIDTH_MAP = [
self::WIDTH_WIDE => '',
self::WIDTH_SHORT => '-short',
self::WIDTH_NARROW => '-narrow',
];
private const EN_LIST_PATTERNS = [
'listPattern-type-standard' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, and {1}',
2 => '{0} and {1}',
],
'listPattern-type-or' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, or {1}',
2 => '{0} or {1}',
],
'listPattern-type-or-narrow' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, or {1}',
2 => '{0} or {1}',
],
'listPattern-type-or-short' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, or {1}',
2 => '{0} or {1}',
],
'listPattern-type-standard-narrow' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, {1}',
2 => '{0}, {1}',
],
'listPattern-type-standard-short' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, & {1}',
2 => '{0} & {1}',
],
'listPattern-type-unit' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, {1}',
2 => '{0}, {1}',
],
'listPattern-type-unit-narrow' => [
'start' => '{0} {1}',
'middle' => '{0} {1}',
'end' => '{0} {1}',
2 => '{0} {1}',
],
'listPattern-type-unit-short' => [
'start' => '{0}, {1}',
'middle' => '{0}, {1}',
'end' => '{0}, {1}',
2 => '{0}, {1}',
],
];
public function __construct(string $locale, int $type = self::TYPE_AND, int $width = self::WIDTH_WIDE)
{
if ('en' !== $locale && 0 !== strpos($locale, 'en')) {
if (80000 > \PHP_VERSION_ID) {
throw new \InvalidArgumentException('Invalid locale, only "en" and "en-*" locales are supported.');
}
throw new \ValueError('Invalid locale, only "en" and "en-*" locales are supported.');
}
if (!isset(self::TYPE_MAP[$type])) {
if (80000 > \PHP_VERSION_ID) {
throw new \InvalidArgumentException('Argument #2 ($type) must be one of IntlListFormatter::TYPE_AND, IntlListFormatter::TYPE_OR, or IntlListFormatter::TYPE_UNITS.');
}
throw new \ValueError('Argument #2 ($type) must be one of IntlListFormatter::TYPE_AND, IntlListFormatter::TYPE_OR, or IntlListFormatter::TYPE_UNITS.');
}
if (!isset(self::WIDTH_MAP[$width])) {
if (80000 > \PHP_VERSION_ID) {
throw new \InvalidArgumentException('Argument #3 ($width) must be one of IntlListFormatter::WIDTH_WIDE, IntlListFormatter::WIDTH_SHORT, or IntlListFormatter::WIDTH_NARROW.');
}
throw new \ValueError('Argument #3 ($width) must be one of IntlListFormatter::WIDTH_WIDE, IntlListFormatter::WIDTH_SHORT, or IntlListFormatter::WIDTH_NARROW.');
}
$this->type = $type;
$this->width = $width;
}
public function format(array $strings): string
{
$count = \count($strings);
if (0 === $count) {
return '';
}
$strings = array_values($strings);
if (1 === $count) {
return (string) $strings[0];
}
$pattern = self::EN_LIST_PATTERNS['listPattern-type-'.self::TYPE_MAP[$this->type].self::WIDTH_MAP[$this->width]];
if (2 === $count) {
return strtr($pattern[2], ['{0}' => (string) $strings[0], '{1}' => (string) $strings[1]]);
}
$result = strtr($pattern['start'], ['{0}' => (string) $strings[0], '{1}' => (string) $strings[1]]);
for ($i = 2; $i < $count - 1; ++$i) {
$result = strtr($pattern['middle'], ['{0}' => $result, '{1}' => (string) $strings[$i]]);
}
return strtr($pattern['end'], ['{0}' => $result, '{1}' => (string) $strings[$count - 1]]);
}
public function getErrorCode(): int
{
return 0;
}
public function getErrorMessage(): string
{
return '';
}
}

View File

@@ -41,6 +41,28 @@ abstract class Locale
public const GRANDFATHERED_LANG_TAG = 'grandfathered';
public const PRIVATE_TAG = 'private';
private const RTL_SCRIPTS = [
'Adlm' => true, 'Arab' => true, 'Armi' => true, 'Hebr' => true,
'Mand' => true, 'Mani' => true, 'Mend' => true, 'Nkoo' => true,
'Orkh' => true, 'Phnx' => true, 'Rohg' => true, 'Samr' => true,
'Syrc' => true, 'Thaa' => true, 'Yezi' => true,
];
private const LANG_TO_SCRIPT = [
'ar' => 'Arab',
'ckb' => 'Arab',
'dv' => 'Thaa',
'fa' => 'Arab',
'he' => 'Hebr',
'ku' => 'Arab',
'nqo' => 'Nkoo',
'ps' => 'Arab',
'sd' => 'Arab',
'ug' => 'Arab',
'ur' => 'Arab',
'yi' => 'Hebr',
];
/**
* Not supported. Returns the best available locale based on HTTP "Accept-Language" header according to RFC 2616.
*
@@ -307,4 +329,22 @@ abstract class Locale
return true;
}
public static function isRightToLeft(string $locale): bool
{
if ('' === $locale) {
return false;
}
$parts = preg_split('/[_-]/', $locale);
$language = strtolower($parts[0]);
foreach ($parts as $part) {
if (4 === \strlen($part) && ctype_alpha($part)) {
return isset(self::RTL_SCRIPTS[ucfirst(strtolower($part))]);
}
}
return isset(self::LANG_TO_SCRIPT[$language]) && isset(self::RTL_SCRIPTS[self::LANG_TO_SCRIPT[$language]]);
}
}

View File

@@ -261,7 +261,7 @@ abstract class NumberFormatter
}
if (!\in_array($style, self::$supportedStyles)) {
$message = sprintf('The available styles are: %s.', implode(', ', array_keys(self::$supportedStyles)));
$message = \sprintf('The available styles are: %s.', implode(', ', array_keys(self::$supportedStyles)));
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'style', $style, $message);
}
@@ -352,7 +352,7 @@ abstract class NumberFormatter
// The original NumberFormatter does not support this format type
if (self::TYPE_CURRENCY === $type) {
if (\PHP_VERSION_ID >= 80000) {
throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%s given).', $type));
throw new \ValueError(\sprintf('The format type must be a NumberFormatter::TYPE_* constant (%s given).', $type));
}
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
@@ -361,7 +361,7 @@ abstract class NumberFormatter
}
if (self::CURRENCY === $this->style) {
throw new NotImplementedException(sprintf('"%s()" method does not support the formatting of currencies (instance with CURRENCY style). "%s".', __METHOD__, NotImplementedException::INTL_INSTALL_MESSAGE));
throw new NotImplementedException(\sprintf('"%s()" method does not support the formatting of currencies (instance with CURRENCY style). "%s".', __METHOD__, NotImplementedException::INTL_INSTALL_MESSAGE));
}
// Only the default type is supported.
@@ -496,7 +496,7 @@ abstract class NumberFormatter
{
if (self::TYPE_DEFAULT === $type || self::TYPE_CURRENCY === $type) {
if (\PHP_VERSION_ID >= 80000) {
throw new \ValueError(sprintf('The format type must be a NumberFormatter::TYPE_* constant (%d given).', $type));
throw new \ValueError(\sprintf('The format type must be a NumberFormatter::TYPE_* constant (%d given).', $type));
}
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
@@ -553,7 +553,7 @@ abstract class NumberFormatter
public function setAttribute(int $attribute, $value)
{
if (!\in_array($attribute, self::$supportedAttributes)) {
$message = sprintf(
$message = \sprintf(
'The available attributes are: %s',
implode(', ', array_keys(self::$supportedAttributes))
);
@@ -562,7 +562,7 @@ abstract class NumberFormatter
}
if (self::$supportedAttributes['ROUNDING_MODE'] === $attribute && $this->isInvalidRoundingMode($value)) {
$message = sprintf(
$message = \sprintf(
'The supported values for ROUNDING_MODE are: %s',
implode(', ', array_keys(self::$roundingModes))
);

View File

@@ -13,6 +13,7 @@ It is limited to the "en" locale and to:
- [`NumberFormatter`](https://php.net/NumberFormatter)
- [`Locale`](https://php.net/Locale)
- [`IntlDateFormatter`](https://php.net/IntlDateFormatter)
- [`IntlListFormatter`](https://php.net/IntlListFormatter)
More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).

View File

@@ -0,0 +1,21 @@
<?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\Polyfill\Intl\Icu\IntlListFormatter as IntlListFormatterPolyfill;
/**
* Stub implementation for the IntlListFormatter class of the intl extension.
*
* @author Ayesh Karunaratne <ayesh@aye.sh>
*/
final class IntlListFormatter extends IntlListFormatterPolyfill
{
}