From be819c162f7507cfe9585da96c26fd440d186aef Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 15 Sep 2014 13:39:24 +0200 Subject: [PATCH 01/18] [Intl] Integrated ICU data into Intl component --- .travis.yml | 4 +- composer.json | 1 - phpunit.xml.dist | 1 + .../Extension/Core/Type/LanguageTypeTest.php | 2 +- .../Compiler/BundleCompilerInterface.php | 2 +- .../Bundle/Compiler/GenrbCompiler.php} | 4 +- .../Bundle}/Reader/BufferedBundleReader.php | 12 +- .../Bundle/Reader/BundleEntryReader.php} | 28 +- .../Reader/BundleEntryReaderInterface.php} | 4 +- .../Bundle}/Reader/BundleReaderInterface.php | 11 +- .../Bundle/Reader/IntlBundleReader.php} | 20 +- .../Data/Bundle/Reader/JsonBundleReader.php | 89 ++ .../Bundle}/Reader/PhpBundleReader.php | 16 +- .../Bundle}/Writer/BundleWriterInterface.php | 2 +- .../Data/Bundle/Writer/JsonBundleWriter.php | 48 + .../Bundle}/Writer/PhpBundleWriter.php | 21 +- .../Bundle}/Writer/TextBundleWriter.php | 2 +- .../Data/Generator/AbstractDataGenerator.php | 143 +++ .../Data/Generator/CurrencyDataGenerator.php | 217 ++++ .../Intl/Data/Generator/GeneratorConfig.php | 87 ++ .../Data/Generator/LanguageDataGenerator.php | 211 ++++ .../Data/Generator/LocaleDataGenerator.php | 252 +++++ .../Data/Generator/RegionDataGenerator.php | 163 +++ .../Data/Generator/ScriptDataGenerator.php | 101 ++ .../Data/Provider/CurrencyDataProvider.php | 152 +++ .../Data/Provider/LanguageDataProvider.php | 91 ++ .../Intl/Data/Provider/LocaleDataProvider.php | 92 ++ .../Intl/Data/Provider/RegionDataProvider.php | 81 ++ .../Intl/Data/Provider/ScriptDataProvider.php | 81 ++ .../Util/ArrayAccessibleResourceBundle.php | 2 +- .../Intl/Data/Util/LocaleScanner.php | 85 ++ .../Util/RecursiveArrayAccess.php | 2 +- .../Util/RingBuffer.php | 2 +- src/Symfony/Component/Intl/Intl.php | 132 ++- src/Symfony/Component/Intl/Locale.php | 53 +- .../Intl/ResourceBundle/AbstractBundle.php | 72 -- .../Intl/ResourceBundle/CurrencyBundle.php | 97 +- .../CurrencyBundleInterface.php | 12 +- .../Intl/ResourceBundle/LanguageBundle.php | 130 +-- .../LanguageBundleInterface.php | 20 +- .../Intl/ResourceBundle/LocaleBundle.php | 43 +- .../ResourceBundle/LocaleBundleInterface.php | 10 +- .../Intl/ResourceBundle/RegionBundle.php | 61 +- .../ResourceBundle/RegionBundleInterface.php | 8 +- .../Transformer/BundleTransformer.php | 98 -- .../Transformer/CompilationContext.php | 99 -- .../CompilationContextInterface.php | 58 -- .../Rule/CurrencyBundleTransformationRule.php | 96 -- .../Rule/LanguageBundleTransformationRule.php | 73 -- .../Rule/LocaleBundleTransformationRule.php | 258 ----- .../Rule/RegionBundleTransformationRule.php | 72 -- .../Rule/TransformationRuleInterface.php | 72 -- .../Transformer/StubbingContext.php | 82 -- .../Transformer/StubbingContextInterface.php | 48 - .../Component/Intl/Resources/bin/autoload.php | 2 +- .../Resources/bin/copy-stubs-to-component.php | 62 -- .../Intl/Resources/bin/create-stubs.php | 112 --- .../Intl/Resources/bin/icu-version.php | 18 - .../Component/Intl/Resources/bin/icu.ini | 1 + .../Intl/Resources/bin/test-compat.php | 56 -- .../Intl/Resources/bin/update-data.php | 295 ++++++ .../Resources/bin/update-icu-component.php | 212 ---- .../Resources/bin/util/test-compat-helper.php | 23 - .../Bundle/Reader/BundleEntryReaderTest.php} | 12 +- .../Reader/Fixtures/NotAFile/en.php/.gitkeep | 0 .../Bundle}/Reader/Fixtures/build.sh | 0 .../Bundle}/Reader/Fixtures/en.php | 0 .../Bundle}/Reader/Fixtures/en.res | Bin .../Bundle}/Reader/Fixtures/en.txt | 0 .../Data/Bundle/Reader/Fixtures/json/en.json | 1 + .../Reader/Fixtures/json/en_Invalid.json | 1 + .../Bundle}/Reader/Fixtures/php/en.php | 0 .../Bundle}/Reader/Fixtures/res/alias.res | Bin .../Bundle}/Reader/Fixtures/res/mo.res | Bin .../Bundle}/Reader/Fixtures/res/ro.res | Bin .../Bundle}/Reader/Fixtures/res/ro_MD.res | Bin .../Bundle}/Reader/Fixtures/res/root.res | Bin .../Bundle}/Reader/Fixtures/txt/alias.txt | 0 .../Bundle}/Reader/Fixtures/txt/mo.txt | 0 .../Bundle}/Reader/Fixtures/txt/ro.txt | 0 .../Bundle}/Reader/Fixtures/txt/ro_MD.txt | 0 .../Bundle}/Reader/Fixtures/txt/root.txt | 0 .../Bundle/Reader/IntlBundleReaderTest.php} | 10 +- .../Bundle/Reader/JsonBundleReaderTest.php | 71 ++ .../Bundle}/Reader/PhpBundleReaderTest.php | 4 +- .../Tests/Data/Bundle/Writer/Fixtures/en.json | 15 + .../Bundle}/Writer/Fixtures/en.php | 12 +- .../Bundle}/Writer/Fixtures/en.res | Bin .../Bundle}/Writer/Fixtures/en.txt | 0 .../Bundle}/Writer/Fixtures/en_nofallback.txt | 0 .../Bundle}/Writer/Fixtures/escaped.txt | 0 .../Tests/Data/Bundle/Writer/Fixtures/rb.json | 5 + .../Tests/Data/Bundle/Writer/Fixtures/rb.php | 7 + .../Tests/Data/Bundle/Writer/Fixtures/rb.res | Bin 0 -> 104 bytes .../Tests/Data/Bundle/Writer/Fixtures/rb.txt | 5 + .../Bundle/Writer/JsonBundleWriterTest.php | 85 ++ .../Bundle}/Writer/PhpBundleWriterTest.php | 19 +- .../Bundle}/Writer/TextBundleWriterTest.php | 4 +- .../AbstractCurrencyDataProviderTest.php | 782 +++++++++++++++ .../Provider/AbstractDataProviderTest.php | 853 ++++++++++++++++ .../AbstractLanguageDataProviderTest.php | 933 ++++++++++++++++++ .../AbstractLocaleDataProviderTest.php | 108 ++ .../AbstractRegionDataProviderTest.php | 355 +++++++ .../AbstractScriptDataProviderTest.php | 267 +++++ .../Json/JsonCurrencyDataProviderTest.php | 37 + .../Json/JsonLanguageDataProviderTest.php | 37 + .../Json/JsonLocaleDataProviderTest.php | 37 + .../Json/JsonRegionDataProviderTest.php | 37 + .../Json/JsonScriptDataProviderTest.php | 37 + .../Tests/Data/Util/LocaleScannerTest.php | 76 ++ .../Util/RingBufferTest.php | 4 +- .../ResourceBundle/AbstractBundleTest.php | 55 -- .../ResourceBundle/CurrencyBundleTest.php | 98 -- .../ResourceBundle/LanguageBundleTest.php | 197 ---- .../Tests/ResourceBundle/LocaleBundleTest.php | 64 -- .../Tests/ResourceBundle/RegionBundleTest.php | 63 -- .../Component/Intl/Util/IntlTestHelper.php | 12 +- src/Symfony/Component/Intl/composer.json | 3 +- src/Symfony/Component/Intl/phpunit.xml.dist | 6 + 119 files changed, 6403 insertions(+), 2313 deletions(-) rename src/Symfony/Component/Intl/{ResourceBundle => Data/Bundle}/Compiler/BundleCompilerInterface.php (91%) rename src/Symfony/Component/Intl/{ResourceBundle/Compiler/BundleCompiler.php => Data/Bundle/Compiler/GenrbCompiler.php} (94%) rename src/Symfony/Component/Intl/{ResourceBundle => Data/Bundle}/Reader/BufferedBundleReader.php (82%) rename src/Symfony/Component/Intl/{ResourceBundle/Reader/StructuredBundleReader.php => Data/Bundle/Reader/BundleEntryReader.php} (88%) rename src/Symfony/Component/Intl/{ResourceBundle/Reader/StructuredBundleReaderInterface.php => Data/Bundle/Reader/BundleEntryReaderInterface.php} (93%) rename src/Symfony/Component/Intl/{ResourceBundle => Data/Bundle}/Reader/BundleReaderInterface.php (70%) rename src/Symfony/Component/Intl/{ResourceBundle/Reader/BinaryBundleReader.php => Data/Bundle/Reader/IntlBundleReader.php} (74%) create mode 100644 src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php rename src/Symfony/Component/Intl/{ResourceBundle => Data/Bundle}/Reader/PhpBundleReader.php (75%) rename src/Symfony/Component/Intl/{ResourceBundle => Data/Bundle}/Writer/BundleWriterInterface.php (92%) create mode 100644 src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php rename src/Symfony/Component/Intl/{ResourceBundle => Data/Bundle}/Writer/PhpBundleWriter.php (72%) rename src/Symfony/Component/Intl/{ResourceBundle => Data/Bundle}/Writer/TextBundleWriter.php (99%) create mode 100644 src/Symfony/Component/Intl/Data/Generator/AbstractDataGenerator.php create mode 100644 src/Symfony/Component/Intl/Data/Generator/CurrencyDataGenerator.php create mode 100644 src/Symfony/Component/Intl/Data/Generator/GeneratorConfig.php create mode 100644 src/Symfony/Component/Intl/Data/Generator/LanguageDataGenerator.php create mode 100644 src/Symfony/Component/Intl/Data/Generator/LocaleDataGenerator.php create mode 100644 src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php create mode 100644 src/Symfony/Component/Intl/Data/Generator/ScriptDataGenerator.php create mode 100644 src/Symfony/Component/Intl/Data/Provider/CurrencyDataProvider.php create mode 100644 src/Symfony/Component/Intl/Data/Provider/LanguageDataProvider.php create mode 100644 src/Symfony/Component/Intl/Data/Provider/LocaleDataProvider.php create mode 100644 src/Symfony/Component/Intl/Data/Provider/RegionDataProvider.php create mode 100644 src/Symfony/Component/Intl/Data/Provider/ScriptDataProvider.php rename src/Symfony/Component/Intl/{ResourceBundle => Data}/Util/ArrayAccessibleResourceBundle.php (97%) create mode 100644 src/Symfony/Component/Intl/Data/Util/LocaleScanner.php rename src/Symfony/Component/Intl/{ResourceBundle => Data}/Util/RecursiveArrayAccess.php (95%) rename src/Symfony/Component/Intl/{ResourceBundle => Data}/Util/RingBuffer.php (97%) delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/AbstractBundle.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContext.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/CompilationContextInterface.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/CurrencyBundleTransformationRule.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LanguageBundleTransformationRule.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/LocaleBundleTransformationRule.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/RegionBundleTransformationRule.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/Rule/TransformationRuleInterface.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContext.php delete mode 100644 src/Symfony/Component/Intl/ResourceBundle/Transformer/StubbingContextInterface.php delete mode 100644 src/Symfony/Component/Intl/Resources/bin/copy-stubs-to-component.php delete mode 100644 src/Symfony/Component/Intl/Resources/bin/create-stubs.php delete mode 100644 src/Symfony/Component/Intl/Resources/bin/icu-version.php delete mode 100644 src/Symfony/Component/Intl/Resources/bin/test-compat.php create mode 100644 src/Symfony/Component/Intl/Resources/bin/update-data.php delete mode 100644 src/Symfony/Component/Intl/Resources/bin/update-icu-component.php delete mode 100644 src/Symfony/Component/Intl/Resources/bin/util/test-compat-helper.php rename src/Symfony/Component/Intl/Tests/{ResourceBundle/Reader/StructuredBundleReaderTest.php => Data/Bundle/Reader/BundleEntryReaderTest.php} (97%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/NotAFile/en.php/.gitkeep (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/build.sh (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/en.php (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/en.res (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/en.txt (100%) create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/Fixtures/json/en.json create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/Fixtures/json/en_Invalid.json rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/php/en.php (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/res/alias.res (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/res/mo.res (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/res/ro.res (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/res/ro_MD.res (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/res/root.res (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/txt/alias.txt (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/txt/mo.txt (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/txt/ro.txt (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/txt/ro_MD.txt (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/Fixtures/txt/root.txt (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle/Reader/BinaryBundleReaderTest.php => Data/Bundle/Reader/IntlBundleReaderTest.php} (90%) create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/JsonBundleReaderTest.php rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Reader/PhpBundleReaderTest.php (91%) create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/Fixtures/en.json rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Writer/Fixtures/en.php (51%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Writer/Fixtures/en.res (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Writer/Fixtures/en.txt (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Writer/Fixtures/en_nofallback.txt (100%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Writer/Fixtures/escaped.txt (100%) create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/Fixtures/rb.json create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/Fixtures/rb.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/Fixtures/rb.res create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/Fixtures/rb.txt create mode 100644 src/Symfony/Component/Intl/Tests/Data/Bundle/Writer/JsonBundleWriterTest.php rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Writer/PhpBundleWriterTest.php (69%) rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data/Bundle}/Writer/TextBundleWriterTest.php (96%) create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/AbstractCurrencyDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/AbstractDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLanguageDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/AbstractLocaleDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/AbstractRegionDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/AbstractScriptDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/Json/JsonCurrencyDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/Json/JsonLanguageDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/Json/JsonLocaleDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/Json/JsonRegionDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Provider/Json/JsonScriptDataProviderTest.php create mode 100644 src/Symfony/Component/Intl/Tests/Data/Util/LocaleScannerTest.php rename src/Symfony/Component/Intl/Tests/{ResourceBundle => Data}/Util/RingBufferTest.php (95%) delete mode 100644 src/Symfony/Component/Intl/Tests/ResourceBundle/AbstractBundleTest.php delete mode 100644 src/Symfony/Component/Intl/Tests/ResourceBundle/CurrencyBundleTest.php delete mode 100644 src/Symfony/Component/Intl/Tests/ResourceBundle/LanguageBundleTest.php delete mode 100644 src/Symfony/Component/Intl/Tests/ResourceBundle/LocaleBundleTest.php delete mode 100644 src/Symfony/Component/Intl/Tests/ResourceBundle/RegionBundleTest.php diff --git a/.travis.yml b/.travis.yml index cecdc9500c05..cc764bea0d13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,6 +35,6 @@ install: - sh -c 'if [ "$components" = "no" ]; then sh -c "COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install"; fi;' script: - - sh -c 'if [ "$components" = "no" ]; then sh -c "ls -d src/Symfony/*/* | parallel --gnu --keep-order '\''echo \"Running {} tests\"; phpunit --exclude-group tty,benchmark {};'\''"; fi;' + - sh -c 'if [ "$components" = "no" ]; then sh -c "ls -d src/Symfony/*/* | parallel --gnu --keep-order '\''echo \"Running {} tests\"; phpunit --exclude-group tty,benchmark,intl-data {};'\''"; fi;' - sh -c 'if [ "$components" = "no" ]; then sh -c "echo "\""Running tests requiring tty"\""; phpunit --group tty"; fi;' - - sh -c 'if [ "$components" = "yes" ]; then sh -c "find src/Symfony -mindepth 3 -type f -name '\''phpunit.xml.dist'\'' | sed '\''s#\(.*\)/.*#\1#'\'' | parallel --gnu --keep-order '\''echo \"Running {} tests\"; cd {}; COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install; phpunit --exclude-group tty,benchmark;'\''"; fi;' + - sh -c 'if [ "$components" = "yes" ]; then sh -c "find src/Symfony -mindepth 3 -type f -name '\''phpunit.xml.dist'\'' | sed '\''s#\(.*\)/.*#\1#'\'' | parallel --gnu --keep-order '\''echo \"Running {} tests\"; cd {}; COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install; phpunit --exclude-group tty,benchmark,intl-data;'\''"; fi;' diff --git a/composer.json b/composer.json index 395a874edb1d..0b8555a2dae6 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ ], "require": { "php": ">=5.3.3", - "symfony/icu": "~1.0", "doctrine/common": "~2.2", "twig/twig": "~1.12", "psr/log": "~1.0" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0a5ed5cfaa80..ce0621d0a9ee 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -23,6 +23,7 @@ benchmark + intl-data diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php index 24434b2148e5..5c54632e7952 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php @@ -31,7 +31,7 @@ public function testCountriesAreSelectable() $this->assertContains(new ChoiceView('en', 'en', 'English'), $choices, '', false, false); $this->assertContains(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices, '', false, false); - $this->assertContains(new ChoiceView('en_US', 'en_US', 'U.S. English'), $choices, '', false, false); + $this->assertContains(new ChoiceView('en_US', 'en_US', 'American English'), $choices, '', false, false); $this->assertContains(new ChoiceView('fr', 'fr', 'French'), $choices, '', false, false); $this->assertContains(new ChoiceView('my', 'my', 'Burmese'), $choices, '', false, false); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php b/src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php similarity index 91% rename from src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php rename to src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php index d9cde44d82f7..8c9d233d92b8 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompilerInterface.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Compiler; +namespace Symfony\Component\Intl\Data\Bundle\Compiler; /** * Compiles a resource bundle. diff --git a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php b/src/Symfony/Component/Intl/Data/Bundle/Compiler/GenrbCompiler.php similarity index 94% rename from src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php rename to src/Symfony/Component/Intl/Data/Bundle/Compiler/GenrbCompiler.php index 9075842b9ab8..cf8ee1a74b5b 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Compiler/GenrbCompiler.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Compiler; +namespace Symfony\Component\Intl\Data\Bundle\Compiler; use Symfony\Component\Intl\Exception\RuntimeException; @@ -20,7 +20,7 @@ * * @internal */ -class BundleCompiler implements BundleCompilerInterface +class GenrbCompiler implements BundleCompilerInterface { /** * @var string The path to the "genrb" executable. diff --git a/src/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/BufferedBundleReader.php similarity index 82% rename from src/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php rename to src/Symfony/Component/Intl/Data/Bundle/Reader/BufferedBundleReader.php index 2a79385e61c5..fede9cdb4a51 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/BufferedBundleReader.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Reader; +namespace Symfony\Component\Intl\Data\Bundle\Reader; -use Symfony\Component\Intl\ResourceBundle\Util\RingBuffer; +use Symfony\Component\Intl\Data\Util\RingBuffer; /** * @author Bernhard Schussek @@ -53,12 +53,4 @@ public function read($path, $locale) return $this->buffer[$hash]; } - - /** - * {@inheritdoc} - */ - public function getLocales($path) - { - return $this->reader->getLocales($path); - } } diff --git a/src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReader.php similarity index 88% rename from src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php rename to src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReader.php index 01ec26190a34..91a844b73a0d 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReader.php @@ -9,24 +9,24 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Reader; +namespace Symfony\Component\Intl\Data\Bundle\Reader; use Symfony\Component\Intl\Exception\MissingResourceException; use Symfony\Component\Intl\Exception\OutOfBoundsException; use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException; use Symfony\Component\Intl\Locale; -use Symfony\Component\Intl\ResourceBundle\Util\RecursiveArrayAccess; +use Symfony\Component\Intl\Data\Util\RecursiveArrayAccess; /** - * Default implementation of {@link StructuredBundleReaderInterface}. + * Default implementation of {@link BundleEntryReaderInterface}. * * @author Bernhard Schussek * - * @see StructuredResourceBundleBundleReaderInterface + * @see BundleEntryReaderInterface * * @internal */ -class StructuredBundleReader implements StructuredBundleReaderInterface +class BundleEntryReader implements BundleEntryReaderInterface { /** * @var BundleReaderInterface @@ -138,7 +138,7 @@ public function readEntry($path, $locale, array $indices, $fallback = true) } // Remember which locales we tried - $testedLocales[] = $currentLocale.'.res'; + $testedLocales[] = $currentLocale; // Check whether fallback is allowed if (!$fallback) { @@ -162,10 +162,10 @@ public function readEntry($path, $locale, array $indices, $fallback = true) // Entry is still NULL, read error occurred. Throw an exception // containing the detailed path and locale $errorMessage = sprintf( - 'Couldn\'t read the indices [%s] from "%s/%s.res".', + 'Couldn\'t read the indices [%s] for the locale "%s" in "%s".', implode('][', $indices), - $path, - $locale + $locale, + $path ); // Append fallback locales, if any @@ -174,19 +174,11 @@ public function readEntry($path, $locale, array $indices, $fallback = true) array_shift($testedLocales); $errorMessage .= sprintf( - ' The indices also couldn\'t be found in the fallback locale(s) "%s".', + ' The indices also couldn\'t be found for the fallback locale(s) "%s".', implode('", "', $testedLocales) ); } throw new MissingResourceException($errorMessage, 0, $exception); } - - /** - * {@inheritdoc} - */ - public function getLocales($path) - { - return $this->reader->getLocales($path); - } } diff --git a/src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReaderInterface.php similarity index 93% rename from src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php rename to src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReaderInterface.php index 19bb3fb49bdd..8a4ecd8e6309 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReaderInterface.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReaderInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Reader; +namespace Symfony\Component\Intl\Data\Bundle\Reader; use Symfony\Component\Intl\Exception\MissingResourceException; @@ -20,7 +20,7 @@ * * @internal */ -interface StructuredBundleReaderInterface extends BundleReaderInterface +interface BundleEntryReaderInterface extends BundleReaderInterface { /** * Reads an entry from a resource bundle. diff --git a/src/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/BundleReaderInterface.php similarity index 70% rename from src/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php rename to src/Symfony/Component/Intl/Data/Bundle/Reader/BundleReaderInterface.php index c11d90e04643..7257b0df7ac6 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Reader/BundleReaderInterface.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/BundleReaderInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Reader; +namespace Symfony\Component\Intl\Data\Bundle\Reader; /** * Reads resource bundle files. @@ -30,13 +30,4 @@ interface BundleReaderInterface * complex data, a scalar value otherwise. */ public function read($path, $locale); - - /** - * Reads the available locales of a resource bundle. - * - * @param string $path The path to the resource bundle. - * - * @return string[] A list of supported locale codes. - */ - public function getLocales($path); } diff --git a/src/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/IntlBundleReader.php similarity index 74% rename from src/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php rename to src/Symfony/Component/Intl/Data/Bundle/Reader/IntlBundleReader.php index 77b86aee4259..9f800ccace7e 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Reader/BinaryBundleReader.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/IntlBundleReader.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Reader; +namespace Symfony\Component\Intl\Data\Bundle\Reader; use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException; -use Symfony\Component\Intl\ResourceBundle\Util\ArrayAccessibleResourceBundle; +use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle; /** * Reads binary .res resource bundles. @@ -21,7 +21,7 @@ * * @internal */ -class BinaryBundleReader implements BundleReaderInterface +class IntlBundleReader implements BundleReaderInterface { /** * {@inheritdoc} @@ -52,18 +52,4 @@ public function read($path, $locale) // which are OK for us. return new ArrayAccessibleResourceBundle($bundle); } - - /** - * {@inheritdoc} - */ - public function getLocales($path) - { - $locales = glob($path.'/*.res'); - - // Remove file extension and sort - array_walk($locales, function (&$locale) { $locale = basename($locale, '.res'); }); - sort($locales); - - return $locales; - } } diff --git a/src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php new file mode 100644 index 000000000000..197384348199 --- /dev/null +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php @@ -0,0 +1,89 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Data\Bundle\Reader; + +use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException; +use Symfony\Component\Intl\Exception\RuntimeException; + +/** + * Reads .json resource bundles. + * + * @author Bernhard Schussek + * + * @internal + */ +class JsonBundleReader implements BundleReaderInterface +{ + /** + * {@inheritdoc} + */ + public function read($path, $locale) + { + $fileName = $path.'/'.$locale.'.json'; + + if (!file_exists($fileName)) { + throw new ResourceBundleNotFoundException(sprintf( + 'The resource bundle "%s/%s.json" does not exist.', + $path, + $locale + )); + } + + if (!is_file($fileName)) { + throw new RuntimeException(sprintf( + 'The resource bundle "%s/%s.json" is not a file.', + $path, + $locale + )); + } + + $data = json_decode(file_get_contents($fileName), true); + + if (null === $data) { + throw new RuntimeException(sprintf( + 'The resource bundle "%s/%s.json" contains invalid JSON: %s', + $path, + $locale, + self::getLastJsonError() + )); + } + + return $data; + } + + /** + * @return string The last error message created by {@link json_decode()} + * + * @link http://de2.php.net/manual/en/function.json-last-error-msg.php#113243 + */ + private static function getLastJsonError() + { + if (function_exists('json_last_error_msg')) { + return json_last_error_msg(); + } + + static $errors = array( + JSON_ERROR_NONE => null, + JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', + JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', + JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', + JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', + ); + + $error = json_last_error(); + + return array_key_exists($error, $errors) + ? $errors[$error] + : sprintf('Unknown error (%s)', $error); + } +} diff --git a/src/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/PhpBundleReader.php similarity index 75% rename from src/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php rename to src/Symfony/Component/Intl/Data/Bundle/Reader/PhpBundleReader.php index 2082916827bd..57391ce01007 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Reader/PhpBundleReader.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/PhpBundleReader.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Reader; +namespace Symfony\Component\Intl\Data\Bundle\Reader; use Symfony\Component\Intl\Exception\ResourceBundleNotFoundException; use Symfony\Component\Intl\Exception\RuntimeException; @@ -48,18 +48,4 @@ public function read($path, $locale) return include $fileName; } - - /** - * {@inheritdoc} - */ - public function getLocales($path) - { - $locales = glob($path.'/*.php'); - - // Remove file extension and sort - array_walk($locales, function (&$locale) { $locale = basename($locale, '.php'); }); - sort($locales); - - return $locales; - } } diff --git a/src/Symfony/Component/Intl/ResourceBundle/Writer/BundleWriterInterface.php b/src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php similarity index 92% rename from src/Symfony/Component/Intl/ResourceBundle/Writer/BundleWriterInterface.php rename to src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php index f612aacae7d1..e85376dc64bf 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Writer/BundleWriterInterface.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Writer; +namespace Symfony\Component\Intl\Data\Bundle\Writer; /** * Writes resource bundle files. diff --git a/src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php b/src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php new file mode 100644 index 000000000000..2af08157353f --- /dev/null +++ b/src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php @@ -0,0 +1,48 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Intl\Data\Bundle\Writer; + +/** + * Writes .json resource bundles. + * + * @author Bernhard Schussek + * + * @internal + */ +class JsonBundleWriter implements BundleWriterInterface +{ + /** + * {@inheritdoc} + */ + public function write($path, $locale, $data) + { + if ($data instanceof \Traversable) { + $data = iterator_to_array($data); + } + + array_walk_recursive($data, function (&$value) { + if ($value instanceof \Traversable) { + $value = iterator_to_array($value); + } + }); + + if (version_compare(PHP_VERSION, '5.4.0', '>=')) { + // Use JSON_PRETTY_PRINT so that we can see what changed in Git diffs + file_put_contents( + $path.'/'.$locale.'.json', + json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)."\n" + ); + } else { + file_put_contents($path.'/'.$locale.'.json', json_encode($data)."\n"); + } + } +} diff --git a/src/Symfony/Component/Intl/ResourceBundle/Writer/PhpBundleWriter.php b/src/Symfony/Component/Intl/Data/Bundle/Writer/PhpBundleWriter.php similarity index 72% rename from src/Symfony/Component/Intl/ResourceBundle/Writer/PhpBundleWriter.php rename to src/Symfony/Component/Intl/Data/Bundle/Writer/PhpBundleWriter.php index d5a30b907dcf..a29972cd0210 100644 --- a/src/Symfony/Component/Intl/ResourceBundle/Writer/PhpBundleWriter.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Writer/PhpBundleWriter.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Intl\ResourceBundle\Writer; +namespace Symfony\Component\Intl\Data\Bundle\Writer; /** * Writes .php resource bundles. @@ -28,19 +28,20 @@ public function write($path, $locale, $data) $template = <<