Fix the handling of null as locale in the stub intl classes
The Intl extension accepts null as locale in formatters and the collator and will use the default locale in such case. Given that the stub implementation considers that the default locale is always 'en', it should be supported here too instead of forcing libraries to pass the default locale explicitly.
This commit is contained in:
parent
6b02601e7b
commit
d6db6ad7f7
@ -70,13 +70,13 @@ class Collator
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $locale The locale code. The only currently supported locale is "en".
|
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
|
||||||
*
|
*
|
||||||
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
|
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
|
||||||
*/
|
*/
|
||||||
public function __construct($locale)
|
public function __construct($locale)
|
||||||
{
|
{
|
||||||
if ('en' != $locale) {
|
if ('en' !== $locale && null !== $locale) {
|
||||||
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
|
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,11 +84,11 @@ class Collator
|
|||||||
/**
|
/**
|
||||||
* Static constructor.
|
* Static constructor.
|
||||||
*
|
*
|
||||||
* @param string $locale The locale code. The only currently supported locale is "en".
|
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
|
||||||
*
|
*
|
||||||
* @return Collator
|
* @return Collator
|
||||||
*
|
*
|
||||||
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
|
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
|
||||||
*/
|
*/
|
||||||
public static function create($locale)
|
public static function create($locale)
|
||||||
{
|
{
|
||||||
|
@ -129,7 +129,7 @@ class IntlDateFormatter
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $locale The locale code. The only currently supported locale is "en".
|
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
|
||||||
* @param int $datetype Type of date formatting, one of the format type constants
|
* @param int $datetype Type of date formatting, one of the format type constants
|
||||||
* @param int $timetype Type of time formatting, one of the format type constants
|
* @param int $timetype Type of time formatting, one of the format type constants
|
||||||
* @param string $timezone Timezone identifier
|
* @param string $timezone Timezone identifier
|
||||||
@ -140,12 +140,12 @@ class IntlDateFormatter
|
|||||||
* @see http://www.php.net/manual/en/intldateformatter.create.php
|
* @see http://www.php.net/manual/en/intldateformatter.create.php
|
||||||
* @see http://userguide.icu-project.org/formatparse/datetime
|
* @see http://userguide.icu-project.org/formatparse/datetime
|
||||||
*
|
*
|
||||||
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
|
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
|
||||||
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
|
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
|
||||||
*/
|
*/
|
||||||
public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
|
public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
|
||||||
{
|
{
|
||||||
if ('en' !== $locale) {
|
if ('en' !== $locale && null !== $locale) {
|
||||||
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
|
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ class IntlDateFormatter
|
|||||||
/**
|
/**
|
||||||
* Static constructor.
|
* Static constructor.
|
||||||
*
|
*
|
||||||
* @param string $locale The locale code. The only currently supported locale is "en".
|
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
|
||||||
* @param int $datetype Type of date formatting, one of the format type constants
|
* @param int $datetype Type of date formatting, one of the format type constants
|
||||||
* @param int $timetype Type of time formatting, one of the format type constants
|
* @param int $timetype Type of time formatting, one of the format type constants
|
||||||
* @param string $timezone Timezone identifier
|
* @param string $timezone Timezone identifier
|
||||||
@ -176,7 +176,7 @@ class IntlDateFormatter
|
|||||||
* @see http://www.php.net/manual/en/intldateformatter.create.php
|
* @see http://www.php.net/manual/en/intldateformatter.create.php
|
||||||
* @see http://userguide.icu-project.org/formatparse/datetime
|
* @see http://userguide.icu-project.org/formatparse/datetime
|
||||||
*
|
*
|
||||||
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
|
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
|
||||||
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
|
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
|
||||||
*/
|
*/
|
||||||
public static function create($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
|
public static function create($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
|
||||||
|
@ -245,7 +245,7 @@ class NumberFormatter
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $locale The locale code. The only currently supported locale is "en".
|
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
|
||||||
* @param int $style Style of the formatting, one of the format style constants.
|
* @param int $style Style of the formatting, one of the format style constants.
|
||||||
* The only supported styles are NumberFormatter::DECIMAL
|
* The only supported styles are NumberFormatter::DECIMAL
|
||||||
* and NumberFormatter::CURRENCY.
|
* and NumberFormatter::CURRENCY.
|
||||||
@ -257,13 +257,13 @@ class NumberFormatter
|
|||||||
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
|
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
|
||||||
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
|
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
|
||||||
*
|
*
|
||||||
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
|
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
|
||||||
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
|
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
|
||||||
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
|
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
|
||||||
*/
|
*/
|
||||||
public function __construct($locale = 'en', $style = null, $pattern = null)
|
public function __construct($locale = 'en', $style = null, $pattern = null)
|
||||||
{
|
{
|
||||||
if ('en' != $locale) {
|
if ('en' !== $locale && null !== $locale) {
|
||||||
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
|
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ class NumberFormatter
|
|||||||
/**
|
/**
|
||||||
* Static constructor.
|
* Static constructor.
|
||||||
*
|
*
|
||||||
* @param string $locale The locale code. The only supported locale is "en".
|
* @param string $locale The locale code. The only supported locale is "en" (or null using the default locale, i.e. "en").
|
||||||
* @param int $style Style of the formatting, one of the format style constants.
|
* @param int $style Style of the formatting, one of the format style constants.
|
||||||
* The only currently supported styles are NumberFormatter::DECIMAL
|
* The only currently supported styles are NumberFormatter::DECIMAL
|
||||||
* and NumberFormatter::CURRENCY.
|
* and NumberFormatter::CURRENCY.
|
||||||
@ -296,7 +296,7 @@ class NumberFormatter
|
|||||||
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
|
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
|
||||||
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
|
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
|
||||||
*
|
*
|
||||||
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
|
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
|
||||||
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
|
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
|
||||||
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
|
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
|
||||||
*/
|
*/
|
||||||
|
@ -60,6 +60,12 @@ class CollatorTest extends AbstractCollatorTest
|
|||||||
$this->assertEquals('en', $collator->getLocale());
|
$this->assertEquals('en', $collator->getLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructWithoutLocale()
|
||||||
|
{
|
||||||
|
$collator = $this->getCollator(null);
|
||||||
|
$this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
|
* @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
|
||||||
*/
|
*/
|
||||||
|
@ -22,6 +22,12 @@ class IntlDateFormatterTest extends AbstractIntlDateFormatterTest
|
|||||||
$this->assertEquals('y-M-d', $formatter->getPattern());
|
$this->assertEquals('y-M-d', $formatter->getPattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructorWithoutLocale()
|
||||||
|
{
|
||||||
|
$formatter = new IntlDateFormatter(null, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN, 'y-M-d');
|
||||||
|
$this->assertEquals('y-M-d', $formatter->getPattern());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
|
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
|
||||||
*/
|
*/
|
||||||
|
@ -70,6 +70,14 @@ class NumberFormatterTest extends AbstractNumberFormatterTest
|
|||||||
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, null);
|
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructWithoutLocale()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
'\Symfony\Component\Intl\NumberFormatter\NumberFormatter',
|
||||||
|
$this->getNumberFormatter(null, NumberFormatter::DECIMAL)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreate()
|
public function testCreate()
|
||||||
{
|
{
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
|
Reference in New Issue
Block a user