8000 bug #15411 Fix the handling of null as locale in the stub intl classe… · symfony/symfony@85c1099 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85c1099

Browse files
committed
bug #15411 Fix the handling of null as locale in the stub intl classes (stof)
This PR was merged into the 2.3 branch. Discussion ---------- 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. For instance, ``Twig_Extensions_Extension_Intl`` relies on the fact that ``null`` as locale uses the default one: twigphp/Twig-extensions#94 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/demo#123 | License | MIT | Doc PR | n/a Commits ------- d6db6ad Fix the handling of null as locale in the stub intl classes
2 parents 79b5baf + d6db6ad commit 85c1099

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

src/Symfony/Component/Intl/Collator/Collator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,25 @@ class Collator
7070
/**
7171
* Constructor.
7272
*
73-
* @param string $locale The locale code. The only currently supported locale is "en".
73+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
7474
*
75-
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
75+
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
7676
*/
7777
public function __construct($locale)
7878
{
79-
if ('en' != $locale) {
79+
if ('en' !== $locale && null !== $locale) {
8080
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
8181
}
8282
}
8383

8484
/**
8585
* Static constructor.
8686
*
87-
* @param string $locale The locale code. The only currently supported locale is "en".
87+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
8888
*
8989
* @return Collator
9090
*
91-
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
91+
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
9292
*/
9393
public static function create($locale)
9494
{

src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class IntlDateFormatter
129129
/**
130130
* Constructor.
131131
*
132-
* @param string $locale The locale code. The only currently supported locale is "en".
132+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
133133
* @param int $datetype Type of date formatting, one of the format type constants
134134
* @param int $timetype Type of time formatting, one of the format type constants
135135
* @param string $timezone Timezone identifier
@@ -140,12 +140,12 @@ class IntlDateFormatter
140140
* @see http://www.php.net/manual/en/intldateformatter.create.php
141141
* @see http://userguide.icu-project.org/formatparse/datetime
142142
*
143-
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
143+
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
144144
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
145145
*/
146146
public function __construct($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
147147
{
148-
if ('en' !== $locale) {
148+
if ('en' !== $locale && null !== $locale) {
149149
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
150150
}
151151

@@ -163,7 +163,7 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
163163
/**
164164
* Static constructor.
165165
*
166-
* @param string $locale The locale code. The only currently supported locale is "en".
166+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
167167
* @param int $datetype Type of date formatting, one of the format type constants
168168
* @param int $timetype Type of time formatting, one of the format type constants
169169
* @param string $timezone Timezone identifier
@@ -176,7 +176,7 @@ public function __construct($locale, $datetype, $timetype, $timezone = null, $ca
176176
* @see http://www.php.net/manual/en/intldateformatter.create.php
177177
* @see http://userguide.icu-project.org/formatparse/datetime
178178
*
179-
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
179+
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
180180
* @throws MethodArgumentValueNotImplementedException When $calendar different than GREGORIAN is passed
181181
*/
182182
public static function create($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class NumberFormatter
245245
/**
246246
* Constructor.
247247
*
248-
* @param string $locale The locale code. The only currently supported locale is "en".
248+
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en").
249249
* @param int $style Style of the formatting, one of the format style constants.
250250
* The only supported styles are NumberFormatter::DECIMAL
251251
* and NumberFormatter::CURRENCY.
@@ -257,13 +257,13 @@ class NumberFormatter
257257
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
258258
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
259259
*
260-
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
260+
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
261261
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
262262
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
263263
*/
264264
public function __construct($locale = 'en', $style = null, $pattern = null)
265265
{
266-
if ('en' != $locale) {
266+
if ('en' !== $locale && null !== $locale) {
267267
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
268268
}
269269

@@ -282,7 +282,7 @@ public function __construct($locale = 'en', $style = null, $pattern = null)
282282
/**
283283
* Static constructor.
284284
*
285-
* @param string $locale The locale code. The only supported locale is "en".
285+
* @param string $locale The locale code. The only supported locale is "en" (or null using the default locale, i.e. "en").
286286
* @param int $style Style of the formatting, one of the format style constants.
287287
* The only currently supported styles are NumberFormatter::DECIMAL
288288
* and NumberFormatter::CURRENCY.
@@ -296,7 +296,7 @@ public function __construct($locale = 'en', $style = null, $pattern = null)
296296
* @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details
297297
* @see http://www.icu-project.org/apiref/icu4c/classRuleBasedNumberFormat.html#_details
298298
*
299-
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" is passed
299+
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
300300
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
301301
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
302302
*/

src/Symfony/Component/Intl/Tests/Collator/CollatorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public function testGetLocale()
6060
$this->assertEquals('en', $collator->getLocale());
6161
}
6262

63+
public function testConstructWithoutLocale()
64+
{
65+
$collator = $this->getCollator(null);
66+
$this->assertInstanceOf('\Symfony\Component\Intl\Collator\Collator', $collator);
67+
}
68+
6369
/**
6470
* @expectedException \Symfony\Component\Intl\Exception\MethodNotImplementedException
6571
*/

src/Symfony/Component/Intl/Tests/DateFormatter/IntlDateFormatterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public function testConstructor()
2222
$this->assertEquals('y-M-d', $formatter->getPattern());
2323
}
2424

25+
public function testConstructorWithoutLocale()
26+
{
27+
$formatter = new IntlDateFormatter(null, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, 'UTC', IntlDateFormatter::GREGORIAN, 'y-M-d');
28+
$this->assertEquals('y-M-d', $formatter->getPattern());
29+
}
30+
2531
/**
2632
* @expectedException \Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException
2733
*/

src/Symfony/Component/Intl/Tests/NumberFormatter/NumberFormatterTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ public function testSetAttributeInvalidRoundingMode()
7070
$formatter->setAttribute(NumberFormatter::ROUNDING_MODE, null);
7171
}
7272

73+
public function testConstructWithoutLocale()
74+
{
75+
$this->assertInstanceOf(
76+
'\Symfony\Component\Intl\NumberFormatter\NumberFormatter',
77+
$this->getNumberFormatter(null, NumberFormatter::DECIMAL)
78+
);
79+
}
80+
7381
public function testCreate()
7482
{
7583
$this->assertInstanceOf(

0 commit comments

Comments
 (0)
0