Skip to content

Commit 47061d7

Browse files
committed
merged branch bschussek/intl (PR #7386)
This PR was merged into the master branch. Discussion ---------- [Intl] Refactored Locale component into two new components Icu and Intl | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | yes | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #5279 | License | MIT | Doc PR | symfony/symfony-docs#2312 The Intl component is now a simple drop-in replacement layer for the C intl extension. Install it via Composer and have it available automatically if the intl extension is not available. Additionally, the component ships data from the ICU library which can be accessed through the methods: ```php use Symfony\Component\Intl\Intl; Intl::getCurrencyBundle()->... Intl::getLanguageBundle()->... Intl::getLocaleBundle()->... Intl::getRegionBundle()->... ``` If the intl extension is installed, Composer will install the ICU data for the ICU version in the intl extension. If the intl extension is not installed, Composer will use stub ICU data for the latest ICU version (see `Intl::getStubIcuVersion()`). See the [README](/bschussek/symfony/blob/intl/src/Symfony/Component/Intl/README.md) for more information. Todo: - [x] finish the Intl README file - [x] update the Icu README file - [x] update the documentation - [x] make parameter `$locale` optional (default to `\Locale::getDefault()`) in resource bundle methods - [x] remove `(Icu)?Version::compare` calls in the tests - [x] solve deployment problem when trying to install incompatible symfony/icu version listed in composer.lock Create the following branches in the [Icu component](https://github.com/symfony/Icu): - [x] 1.0.x - [x] 1.1.x - [x] 1.2.x Commits ------- 9118b4a [Locale] Removed "Stub" prefixes in Intl component b4cccfd [Intl] Removed "Stub" prefix from stub classes 60f31d1 [Intl] Improved inline documentation c2d37e6 [Intl] Improved error messages in the build scripts 1249f01 [Intl] Added scripts to test the compatibility of various versions of symfony/icu with the ICU version installed on the system 9dbafd7 [Intl] Split update-stubs.php script into two scripts to function with the changed Icu component versioning e2c11cb [Intl] Added a check for the ICU data version to IntlTestHelper to prevent the stub class tests from failing 427d24a [Intl] Outsourced bundle reader creation to Icu component 0160fd5 [Intl] Moved stub data to Icu component 1.0.x dbca3b7 [Intl] Added empty directory needed for the tests a717ce9 [Intl] Removed ICU version comparisons from the tests 5d17de5 [Intl] Fixed version comparisons in the transformation rules 470927d [Intl] Improved build scripts aceb20d [Form] Improved tests to use the IntlTestHelper class 3dd75ff [Locale] Improved tests to use the IntlTestHelper class 03b78b0 [Validator] Improved tests to use the IntlTestHelper class 9d9c389 [Intl] Simplified tests c55c4a2 [Intl] Only the StubNumberFormatterTest requires stub data 17a480b [Intl] Added IntlTestHelper class for convenience 1dcdcd3 [Locale] Fixed failing tests f6b75b9 [Intl] Changed composer.json to disallow future versions of the Icu component 080c880 [Intl] Bumped the stub version to 50.1.2 dd2d013 [Intl] Improved the bundle compilation process f47e60a [Intl] Fixed small bugs in the resource bundle transformation 467cc93 [Intl] Fixed various problems in the resource compilation process 4a5c453 [Intl] Moved the content of the README file to symfony/symfony-docs 9899de7 [Intl] Updated the README bfec58a [Intl] Fixed flawed PHPDoc 21323ba [Intl] Updated the README file 209a9cb [Validator] Adapted to latest Intl changes f2a0aec [Form] Adapted to latest Intl changes 0f6277f [Locale] Adapted to latest Intl changes 2cd1be8 [Intl] Made the $locale parameter optional in the bundle interfaces b9e9cb2 [Intl] Added autoload.php which was ignored by .gitignore 838798f [Intl] Removed method IntlTestCase::skipIfInsufficientIcuVersion() dde1d34 [Intl] Changed Intl::getIcuVersion() to return the stub version if the intl extension is not loaded 99f6f8a [Form] Fixed failing tests 5d0b849 Fixed PHPDoc b60866c [Intl] Changed Intl::getStubIcuVersion() to Intl::getIcuStubVersion() b902b6b [Locale] Added default locale 01d0ee8 [Validator] Changed component to use the Intl component 0c1fe39 [Form] Changed component to use the Intl component 5917a2e [Intl] Refactored Locale component into two new components Icu and Intl
2 parents 5a3428d + 9118b4a commit 47061d7

File tree

1,391 files changed

+12782
-10530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,391 files changed

+12782
-10530
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ before_script:
1414
- echo '' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
1515
- sh -c 'if [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
1616
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
17-
- php src/Symfony/Component/Locale/Resources/data/build-data.php
18-
- export USE_INTL_ICU_DATA_VERSION=1

autoload.php.dist

-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@ $loader = require_once __DIR__.'/vendor/autoload.php';
1010

1111
use Doctrine\Common\Annotations\AnnotationRegistry;
1212

13-
if (!function_exists('intl_get_error_code')) {
14-
require_once __DIR__.'/src/Symfony/Component/Locale/Resources/stubs/functions.php';
15-
}
16-
1713
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

composer.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20+
"symfony/icu": "~1.0",
2021
"doctrine/common": "~2.2",
2122
"twig/twig": "~1.11",
2223
"psr/log": "~1.0"
@@ -37,6 +38,7 @@
3738
"symfony/framework-bundle": "self.version",
3839
"symfony/http-foundation": "self.version",
3940
"symfony/http-kernel": "self.version",
41+
"symfony/intl": "self.version",
4042
"symfony/locale": "self.version",
4143
"symfony/monolog-bridge": "self.version",
4244
"symfony/options-resolver": "self.version",
@@ -68,8 +70,9 @@
6870
"psr-0": { "Symfony\\": "src/" },
6971
"classmap": [
7072
"src/Symfony/Component/HttpFoundation/Resources/stubs",
71-
"src/Symfony/Component/Locale/Resources/stubs"
72-
]
73+
"src/Symfony/Component/Intl/Resources/stubs"
74+
],
75+
"files": [ "src/Symfony/Component/Intl/Resources/stubs/functions.php" ]
7376
},
7477
"minimum-stability": "dev",
7578
"extra": {

src/Symfony/Component/Form/Extension/Core/Type/CountryType.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Intl\Intl;
1516
use Symfony\Component\Locale\Locale;
1617
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
1718

@@ -23,7 +24,7 @@ class CountryType extends AbstractType
2324
public function setDefaultOptions(OptionsResolverInterface $resolver)
2425
{
2526
$resolver->setDefaults(array(
26-
'choices' => Locale::getDisplayCountries(\Locale::getDefault()),
27+
'choices' => Intl::getRegionBundle()->getCountryNames(),
2728
));
2829
}
2930

src/Symfony/Component/Form/Extension/Core/Type/LanguageType.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Intl\Intl;
1516
use Symfony\Component\Locale\Locale;
1617
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
1718

@@ -23,7 +24,7 @@ class LanguageType extends AbstractType
2324
public function setDefaultOptions(OptionsResolverInterface $resolver)
2425
{
2526
$resolver->setDefaults(array(
26-
'choices' => Locale::getDisplayLanguages(\Locale::getDefault()),
27+
'choices' => Intl::getLanguageBundle()->getLanguageNames(),
2728
));
2829
}
2930

src/Symfony/Component/Form/Extension/Core/Type/LocaleType.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Intl\Intl;
1516
use Symfony\Component\Locale\Locale;
1617
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
1718

@@ -23,7 +24,7 @@ class LocaleType extends AbstractType
2324
public function setDefaultOptions(OptionsResolverInterface $resolver)
2425
{
2526
$resolver->setDefaults(array(
26-
'choices' => Locale::getDisplayLocales(\Locale::getDefault()),
27+
'choices' => Intl::getLocaleBundle()->getLocaleNames(),
2728
));
2829
}
2930

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
1313

14-
abstract class DateTimeTestCase extends LocalizedTestCase
14+
abstract class DateTimeTestCase extends \PHPUnit_Framework_TestCase
1515
{
1616
public static function assertDateTimeEquals(\DateTime $expected, \DateTime $actual)
1717
{

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

+9-19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
1313

1414
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

1617
class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
1718
{
@@ -22,6 +23,9 @@ protected function setUp()
2223
{
2324
parent::setUp();
2425

26+
// Since we test against "de_AT", we need the full implementation
27+
IntlTestHelper::requireFullIntl($this);
28+
2529
\Locale::setDefault('de_AT');
2630

2731
$this->dateTime = new \DateTime('2010-02-03 04:05:06 UTC');
@@ -57,15 +61,11 @@ public function dataProvider()
5761
array(\IntlDateFormatter::FULL, \IntlDateFormatter::NONE, null, 'Mittwoch, 03. Februar 2010', '2010-02-03 00:00:00 UTC'),
5862
array(null, \IntlDateFormatter::SHORT, null, '03.02.2010 04:05', '2010-02-03 04:05:00 UTC'),
5963
array(null, \IntlDateFormatter::MEDIUM, null, '03.02.2010 04:05:06', '2010-02-03 04:05:06 UTC'),
60-
array(null, \IntlDateFormatter::LONG, null,
61-
'03.02.2010 04:05:06 GMT'.($this->isLowerThanIcuVersion('4.8') ? '+00:00' : ''),
62-
'2010-02-03 04:05:06 UTC'),
64+
array(null, \IntlDateFormatter::LONG, null, '03.02.2010 04:05:06 GMT', '2010-02-03 04:05:06 UTC'),
6365
// see below for extra test case for time format FULL
6466
array(\IntlDateFormatter::NONE, \IntlDateFormatter::SHORT, null, '04:05', '1970-01-01 04:05:00 UTC'),
6567
array(\IntlDateFormatter::NONE, \IntlDateFormatter::MEDIUM, null, '04:05:06', '1970-01-01 04:05:06 UTC'),
66-
array(\IntlDateFormatter::NONE, \IntlDateFormatter::LONG, null,
67-
'04:05:06 GMT'.($this->isLowerThanIcuVersion('4.8') ? '+00:00' : ''),
68-
'1970-01-01 04:05:06 UTC'),
68+
array(\IntlDateFormatter::NONE, \IntlDateFormatter::LONG, null, '04:05:06 GMT', '1970-01-01 04:05:06 UTC'),
6969
array(null, null, 'yyyy-MM-dd HH:mm:00', '2010-02-03 04:05:00', '2010-02-03 04:05:00 UTC'),
7070
array(null, null, 'yyyy-MM-dd HH:mm', '2010-02-03 04:05', '2010-02-03 04:05:00 UTC'),
7171
array(null, null, 'yyyy-MM-dd HH', '2010-02-03 04', '2010-02-03 04:00:00 UTC'),
@@ -101,15 +101,9 @@ public function testTransform($dateFormat, $timeFormat, $pattern, $output, $inpu
101101

102102
public function testTransformFullTime()
103103
{
104-
if ($this->isLowerThanIcuVersion('4.0')) {
105-
$this->markTestSkipped('Please upgrade ICU version to 4.0+');
106-
}
107-
108104
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL);
109105

110-
$expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT';
111-
112-
$this->assertEquals($expected, $transformer->transform($this->dateTime));
106+
$this->assertEquals('03.02.2010 04:05:06 GMT', $transformer->transform($this->dateTime));
113107
}
114108

115109
public function testTransformToDifferentLocale()
@@ -118,7 +112,7 @@ public function testTransformToDifferentLocale()
118112

119113
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC');
120114

121-
$this->assertEquals('Feb 3, 2010 4:05 AM', $transformer->transform($this->dateTime));
115+
$this->assertEquals('Feb 3, 2010, 4:05 AM', $transformer->transform($this->dateTime));
122116
}
123117

124118
public function testTransformEmpty()
@@ -188,10 +182,6 @@ public function testReverseTransform($dateFormat, $timeFormat, $pattern, $input,
188182

189183
public function testReverseTransformFullTime()
190184
{
191-
if ($this->isLowerThanIcuVersion('4.0')) {
192-
$this->markTestSkipped('Please upgrade ICU version to 4.0+');
193-
}
194-
195185
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL);
196186

197187
$this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('03.02.2010 04:05:06 GMT+00:00'));
@@ -203,7 +193,7 @@ public function testReverseTransformFromDifferentLocale()
203193

204194
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC');
205195

206-
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('Feb 3, 2010 04:05 AM'));
196+
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('Feb 3, 2010, 04:05 AM'));
207197
}
208198

209199
public function testReverseTransformWithDifferentTimezones()

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
1313

1414
use Symfony\Component\Form\Extension\Core\DataTransformer\IntegerToLocalizedStringTransformer;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

16-
class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
17+
class IntegerToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
1718
{
1819
protected function setUp()
1920
{
2021
parent::setUp();
2122

23+
// Since we test against "de_AT", we need the full implementation
24+
IntlTestHelper::requireFullIntl($this);
25+
2226
\Locale::setDefault('de_AT');
2327
}
2428

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/LocalizedTestCase.php

-70
This file was deleted.

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
1313

1414
use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

16-
class MoneyToLocalizedStringTransformerTest extends LocalizedTestCase
17+
class MoneyToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
1718
{
1819
protected function setUp()
1920
{
2021
parent::setUp();
2122

23+
// Since we test against "de_AT", we need the full implementation
24+
IntlTestHelper::requireFullIntl($this);
25+
2226
\Locale::setDefault('de_AT');
2327
}
2428

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

+6-26
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
1313

1414
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

16-
class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
17+
class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
1718
{
1819
protected function setUp()
1920
{
2021
parent::setUp();
2122

23+
// Since we test against "de_AT", we need the full implementation
24+
IntlTestHelper::requireFullIntl($this);
25+
2226
\Locale::setDefault('de_AT');
2327
}
2428

@@ -96,10 +100,6 @@ public function testReverseTransformWithGrouping()
96100

97101
public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot()
98102
{
99-
if ($this->isLowerThanIcuVersion('4.7')) {
100-
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
101-
}
102-
103103
\Locale::setDefault('fr');
104104
$transformer = new NumberToLocalizedStringTransformer(null, true);
105105

@@ -117,10 +117,6 @@ public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsNotDot()
117117
*/
118118
public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot()
119119
{
120-
if ($this->isLowerThanIcuVersion('4.7')) {
121-
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
122-
}
123-
124120
$transformer = new NumberToLocalizedStringTransformer(null, true);
125121

126122
$transformer->reverseTransform('1.234.5');
@@ -131,10 +127,6 @@ public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDot()
131127
*/
132128
public function testDecimalSeparatorMayNotBeDotIfGroupingSeparatorIsDotWithNoGroupSep()
133129
{
134-
if ($this->isLowerThanIcuVersion('4.7')) {
135-
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
136-
}
137-
138130
$transformer = new NumberToLocalizedStringTransformer(null, true);
139131

140132
$transformer->reverseTransform('1234.5');
@@ -151,11 +143,7 @@ public function testDecimalSeparatorMayBeDotIfGroupingSeparatorIsDotButNoGroupin
151143

152144
public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma()
153145
{
154-
if ($this->isLowerThanIcuVersion('4.7')) {
155-
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
156-
}
157-
158-
\Locale::setDefault('ak');
146+
\Locale::setDefault('bg');
159147
$transformer = new NumberToLocalizedStringTransformer(null, true);
160148

161149
// completely valid format
@@ -172,10 +160,6 @@ public function testDecimalSeparatorMayBeCommaIfGroupingSeparatorIsNotComma()
172160
*/
173161
public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma()
174162
{
175-
if ($this->isLowerThanIcuVersion('4.7')) {
176-
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
177-
}
178-
179163
\Locale::setDefault('en');
180164
$transformer = new NumberToLocalizedStringTransformer(null, true);
181165

@@ -187,10 +171,6 @@ public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsComma()
187171
*/
188172
public function testDecimalSeparatorMayNotBeCommaIfGroupingSeparatorIsCommaWithNoGroupSep()
189173
{
190-
if ($this->isLowerThanIcuVersion('4.7')) {
191-
$this->markTestSkipped('Please upgrade ICU version to 4.7+');
192-
}
193-
194174
\Locale::setDefault('en');
195175
$transformer = new NumberToLocalizedStringTransformer(null, true);
196176

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/PercentToLocalizedStringTransformerTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\DataTransformer;
1313

1414
use Symfony\Component\Form\Extension\Core\DataTransformer\PercentToLocalizedStringTransformer;
15+
use Symfony\Component\Intl\Util\IntlTestHelper;
1516

16-
class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
17+
class PercentToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase
1718
{
1819
protected function setUp()
1920
{
2021
parent::setUp();
2122

23+
// Since we test against "de_AT", we need the full implementation
24+
IntlTestHelper::requireFullIntl($this);
25+
2226
\Locale::setDefault('de_AT');
2327
}
2428

0 commit comments

Comments
 (0)