Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd6b67d4

Browse files
ro0NLfabpot
authored andcommitted
[Intl] Simplify API
1 parent9a7a276 commitd6b67d4

File tree

59 files changed

+3767
-60
lines changed

Some content is hidden

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

59 files changed

+3767
-60
lines changed

‎UPGRADE-4.3.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ HttpKernel
9494
* Renamed `PostResponseEvent` to `TerminateEvent`
9595
* Deprecated `TranslatorListener` in favor of `LocaleAwareListener`
9696

97+
Intl
98+
----
99+
100+
* Deprecated `ResourceBundle` namespace
101+
* Deprecated `Intl::getCurrencyBundle()`, use `Currencies` instead
102+
* Deprecated `Intl::getLanguageBundle()`, use `Languages` or `Scripts` instead
103+
* Deprecated `Intl::getLocaleBundle()`, use `Locales` instead
104+
* Deprecated `Intl::getRegionBundle()`, use `Regions` instead
105+
97106
Messenger
98107
---------
99108

‎UPGRADE-5.0.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ HttpKernel
237237
* Removed `PostResponseEvent`, use `TerminateEvent` instead
238238
* Removed `TranslatorListener` in favor of `LocaleAwareListener`
239239

240+
Intl
241+
----
242+
243+
* Removed `ResourceBundle` namespace
244+
* Removed `Intl::getLanguageBundle()`, use `Languages` or `Scripts` instead
245+
* Removed `Intl::getCurrencyBundle()`, use `Currencies` instead
246+
* Removed `Intl::getLocaleBundle()`, use `Locales` instead
247+
* Removed `Intl::getRegionBundle()`, use `Regions` instead
248+
240249
Messenger
241250
---------
242251

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
useSymfony\Component\Form\ChoiceList\ArrayChoiceList;
1616
useSymfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1717
useSymfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
18-
useSymfony\Component\Intl\Intl;
18+
useSymfony\Component\Intl\Regions;
1919
useSymfony\Component\OptionsResolver\Options;
2020
useSymfony\Component\OptionsResolver\OptionsResolver;
2121

@@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver)
4444
$choiceTranslationLocale =$options['choice_translation_locale'];
4545

4646
returnnewIntlCallbackChoiceLoader(function ()use ($choiceTranslationLocale) {
47-
returnarray_flip(Intl::getRegionBundle()->getCountryNames($choiceTranslationLocale));
47+
returnarray_flip(Regions::getNames($choiceTranslationLocale));
4848
});
4949
},
5050
'choice_translation_domain' =>false,
@@ -83,7 +83,7 @@ public function loadChoiceList($value = null)
8383
return$this->choiceList;
8484
}
8585

86-
return$this->choiceList =newArrayChoiceList(array_flip(Intl::getRegionBundle()->getCountryNames()),$value);
86+
return$this->choiceList =newArrayChoiceList(array_flip(Regions::getNames()),$value);
8787
}
8888

8989
/**

‎src/Symfony/Component/Form/Extension/Core/Type/CurrencyType.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
useSymfony\Component\Form\ChoiceList\ArrayChoiceList;
1616
useSymfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1717
useSymfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
18-
useSymfony\Component\Intl\Intl;
18+
useSymfony\Component\Intl\Currencies;
1919
useSymfony\Component\OptionsResolver\Options;
2020
useSymfony\Component\OptionsResolver\OptionsResolver;
2121

@@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver)
4444
$choiceTranslationLocale =$options['choice_translation_locale'];
4545

4646
returnnewIntlCallbackChoiceLoader(function ()use ($choiceTranslationLocale) {
47-
returnarray_flip(Intl::getCurrencyBundle()->getCurrencyNames($choiceTranslationLocale));
47+
returnarray_flip(Currencies::getNames($choiceTranslationLocale));
4848
});
4949
},
5050
'choice_translation_domain' =>false,
@@ -83,7 +83,7 @@ public function loadChoiceList($value = null)
8383
return$this->choiceList;
8484
}
8585

86-
return$this->choiceList =newArrayChoiceList(array_flip(Intl::getCurrencyBundle()->getCurrencyNames()),$value);
86+
return$this->choiceList =newArrayChoiceList(array_flip(Currencies::getNames()),$value);
8787
}
8888

8989
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
useSymfony\Component\Form\ChoiceList\ArrayChoiceList;
1616
useSymfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1717
useSymfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
18-
useSymfony\Component\Intl\Intl;
18+
useSymfony\Component\Intl\Languages;
1919
useSymfony\Component\OptionsResolver\Options;
2020
useSymfony\Component\OptionsResolver\OptionsResolver;
2121

@@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver)
4444
$choiceTranslationLocale =$options['choice_translation_locale'];
4545

4646
returnnewIntlCallbackChoiceLoader(function ()use ($choiceTranslationLocale) {
47-
returnarray_flip(Intl::getLanguageBundle()->getLanguageNames($choiceTranslationLocale));
47+
returnarray_flip(Languages::getNames($choiceTranslationLocale));
4848
});
4949
},
5050
'choice_translation_domain' =>false,
@@ -83,7 +83,7 @@ public function loadChoiceList($value = null)
8383
return$this->choiceList;
8484
}
8585

86-
return$this->choiceList =newArrayChoiceList(array_flip(Intl::getLanguageBundle()->getLanguageNames()),$value);
86+
return$this->choiceList =newArrayChoiceList(array_flip(Languages::getNames()),$value);
8787
}
8888

8989
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
useSymfony\Component\Form\ChoiceList\ArrayChoiceList;
1616
useSymfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
1717
useSymfony\Component\Form\ChoiceList\Loader\IntlCallbackChoiceLoader;
18-
useSymfony\Component\Intl\Intl;
18+
useSymfony\Component\Intl\Locales;
1919
useSymfony\Component\OptionsResolver\Options;
2020
useSymfony\Component\OptionsResolver\OptionsResolver;
2121

@@ -44,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver)
4444
$choiceTranslationLocale =$options['choice_translation_locale'];
4545

4646
returnnewIntlCallbackChoiceLoader(function ()use ($choiceTranslationLocale) {
47-
returnarray_flip(Intl::getLocaleBundle()->getLocaleNames($choiceTranslationLocale));
47+
returnarray_flip(Locales::getNames($choiceTranslationLocale));
4848
});
4949
},
5050
'choice_translation_domain' =>false,
@@ -83,7 +83,7 @@ public function loadChoiceList($value = null)
8383
return$this->choiceList;
8484
}
8585

86-
return$this->choiceList =newArrayChoiceList(array_flip(Intl::getLocaleBundle()->getLocaleNames()),$value);
86+
return$this->choiceList =newArrayChoiceList(array_flip(Locales::getNames()),$value);
8787
}
8888

8989
/**

‎src/Symfony/Component/Form/composer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php":"^7.1.3",
2020
"symfony/event-dispatcher":"^4.3",
21-
"symfony/intl":"~3.4|~4.0",
21+
"symfony/intl":"^4.3",
2222
"symfony/options-resolver":"~4.2",
2323
"symfony/polyfill-ctype":"~1.8",
2424
"symfony/polyfill-mbstring":"~1.0",
@@ -43,6 +43,7 @@
4343
"symfony/doctrine-bridge":"<3.4",
4444
"symfony/framework-bundle":"<3.4",
4545
"symfony/http-kernel":"<4.3",
46+
"symfony/intl":"<4.3",
4647
"symfony/translation":"<4.2",
4748
"symfony/twig-bridge":"<3.4.5|<4.0.5,>=4.0"
4849
},

‎src/Symfony/Component/Intl/CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
7+
* deprecated`ResourceBundle` namespace
8+
* added`Currencies` in favor of`Intl::getCurrencyBundle()`
9+
* added`Languages` and`Scripts` in favor of`Intl::getLanguageBundle()`
10+
* added`Locales` in favor of`Intl::getLocaleBundle()`
11+
* added`Regions` in favor of`Intl::getRegionBundle()`
12+
413
4.2.0
514
-----
615

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Intl;
13+
14+
useSymfony\Component\Intl\Exception\MissingResourceException;
15+
16+
/**
17+
* Gives access to currency-related ICU data.
18+
*
19+
* @author Bernhard Schussek <bschussek@gmail.com>
20+
* @author Roland Franssen <franssen.roland@gmail.com>
21+
*/
22+
finalclass Currenciesextends ResourceBundle
23+
{
24+
privateconstINDEX_SYMBOL =0;
25+
privateconstINDEX_NAME =1;
26+
privateconstINDEX_FRACTION_DIGITS =0;
27+
privateconstINDEX_ROUNDING_INCREMENT =1;
28+
29+
/**
30+
* @return string[]
31+
*/
32+
publicstaticfunctiongetCurrencyCodes():array
33+
{
34+
returnself::readEntry(['Currencies'],'meta');
35+
}
36+
37+
publicstaticfunctionexists(string$currency):bool
38+
{
39+
try {
40+
self::readEntry(['Names',$currency,self::INDEX_NAME]);
41+
42+
returntrue;
43+
}catch (MissingResourceException$e) {
44+
returnfalse;
45+
}
46+
}
47+
48+
publicstaticfunctiongetName(string$currency,string$displayLocale =null):string
49+
{
50+
returnself::readEntry(['Names',$currency,self::INDEX_NAME],$displayLocale);
51+
}
52+
53+
/**
54+
* @return string[]
55+
*/
56+
publicstaticfunctiongetNames(string$displayLocale =null):array
57+
{
58+
// ====================================================================
59+
// For reference: It is NOT possible to return names indexed by
60+
// numeric code here, because some numeric codes map to multiple
61+
// 3-letter codes (e.g. 32 => "ARA", "ARP", "ARS")
62+
// ====================================================================
63+
64+
$names =self::readEntry(['Names'],$displayLocale);
65+
66+
if ($namesinstanceof \Traversable) {
67+
$names =iterator_to_array($names);
68+
}
69+
70+
array_walk($names,function (&$value) {
71+
$value =$value[self::INDEX_NAME];
72+
});
73+
74+
returnself::asort($names,$displayLocale);
75+
}
76+
77+
publicstaticfunctiongetSymbol(string$currency,string$displayLocale =null):string
78+
{
79+
returnself::readEntry(['Names',$currency,self::INDEX_SYMBOL],$displayLocale);
80+
}
81+
82+
publicstaticfunctiongetFractionDigits(string$currency):int
83+
{
84+
try {
85+
returnself::readEntry(['Meta',$currency,self::INDEX_FRACTION_DIGITS],'meta');
86+
}catch (MissingResourceException$e) {
87+
returnself::readEntry(['Meta','DEFAULT',self::INDEX_FRACTION_DIGITS],'meta');
88+
}
89+
}
90+
91+
/**
92+
* @return float|int
93+
*/
94+
publicstaticfunctiongetRoundingIncrement(string$currency)
95+
{
96+
try {
97+
returnself::readEntry(['Meta',$currency,self::INDEX_ROUNDING_INCREMENT],'meta');
98+
}catch (MissingResourceException$e) {
99+
returnself::readEntry(['Meta','DEFAULT',self::INDEX_ROUNDING_INCREMENT],'meta');
100+
}
101+
}
102+
103+
publicstaticfunctiongetNumericCode(string$currency):int
104+
{
105+
returnself::readEntry(['Alpha3ToNumeric',$currency],'meta');
106+
}
107+
108+
publicstaticfunctionforNumericCode(int$numericCode):array
109+
{
110+
returnself::readEntry(['NumericToAlpha3', (string)$numericCode],'meta');
111+
}
112+
113+
protectedstaticfunctiongetPath():string
114+
{
115+
return Intl::getDataDirectory().'/'.Intl::CURRENCY_DIR;
116+
}
117+
}

‎src/Symfony/Component/Intl/Data/Provider/CurrencyDataProvider.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @author Bernhard Schussek <bschussek@gmail.com>
2222
*
23-
* @internal
23+
* @internal to be removed in 5.0.
2424
*/
2525
class CurrencyDataProvider
2626
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp