8000 [Intl] Moved stub data to Icu component 1.0.x · symfony/symfony@0160fd5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0160fd5

Browse files
committed
[Intl] Moved stub data to Icu component 1.0.x
1 parent dbca3b7 commit 0160fd5

File tree

8 files changed

+16
-3254
lines changed

8 files changed

+16
-3254
lines changed

src/Symfony/Component/Intl/Intl.php

Lines changed: 12 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,12 @@
3333
*/
3434
class Intl
3535
{
36-
/**
37-
* Load data from the Icu component.
38-
*/
39-
const ICU = 0;
40-
41-
/**
42-
* Load data from the stub files of the Intl component.
43-
*/
44-
const STUB = 1;
45-
4636
/**
4737
* The number of resource bundles to buffer. Loading the same resource
4838
* bundle for n locales takes up n spots in the buffer.
4939
*/
5040
const BUFFER_SIZE = 10;
5141

52-
/**
53-
* The accepted values for the {@link $dataSource} property.
54-
*
55-
* @var array
56-
*/
57-
private static $allowedDataSources = array(
58-
self::ICU => 'Intl::ICU',
59-
self::STUB => 'Intl::STUB',
60-
);
61-
62-
/**
63-
* @var integer
64-
*/
65-
private static $dataSource;
66-
6742
/**
6843
* @var ResourceBundle\CurrencyBundleInterface
6944
*/
@@ -97,12 +72,7 @@ class Intl
9772
/**
9873
* @var ResourceBundle\Reader\StructuredBundleReaderInterface
9974
*/
100-
private static $phpReader;
101-
102-
/**
103-
* @var ResourceBundle\Reader\StructuredBundleReaderInterface
104-
*/
105-
private static $binaryReader;
75+
private static $bundleReader;
10676

10777
/**
10878
* Returns whether the intl extension is installed.
@@ -111,66 +81,7 @@ class Intl
11181
*/
11282
public static function isExtensionLoaded()
11383
{
114-
return IcuData::isLoadable();
115-
}
116-
117-
/**
118-
* Sets the data source from which to load the resource bundles.
119-
*
120-
* @param integer $dataSource One of the constants {@link Intl::ICU} or
121-
* {@link Intl::STUB}.
122-
*
123-
* @throws InvalidArgumentException If the data source is invalid.
124-
*
125-
* @see getData>Source
126-
*/
127-
public static function setDataSource($dataSource)
128-
{
129-
if (!isset(self::$allowedDataSources[$dataSource])) {
130-
throw new InvalidArgumentException(sprintf(
131-
'The data sources should be one of %s',
132-
implode(', ', self::$allowedDataSources)
133-
));
134-
}
135-
136-
if (self::ICU === $dataSource && !IcuData::isLoadable()) {
137-
throw new InvalidArgumentException(
138-
'The data source cannot be set to Intl::ICU if the intl ' .
139-
'extension is not installed.'
140-
);
141-
}
142-
143-
if ($dataSource !== self::$dataSource) {
144-
self::$currencyBundle = null;
145-
self::$languageBundle = null;
146-
self::$localeBundle = null;
147-
self::$regionBundle = null;
148-
}
149-
150-
self::$dataSource = $dataSource;
151-
}
152-
153-
/**
154-
* Returns the data source from which to load the resource bundles.
155-
*
156-
* If {@link setDataSource()} has not been called, the data source will be
157-
* chosen depending on whether the intl extension is installed or not:
158-
*
159-
* * If the extension is present, the bundles will be loaded from the Icu
160-
* component;
161-
* * Otherwise, the bundles will be loaded from the stub files in the
162-
* Intl component.
163-
*
164-
* @return integer One of the constants {@link Intl::ICU} or
165-
* {@link Intl::STUB}.
166-
*/
167-
public static function getDataSource()
168-
{
169-
if (null === self::$dataSource) {
170-
self::$dataSource = IcuData::isLoadable() ? self::ICU : self::STUB;
171-
}
172-
173-
return self::$dataSource;
84+
return class_exists('\ResourceBundle');
17485
}
17586

17687
/**
@@ -181,9 +92,7 @@ public static function getDataSource()
18192
public static function getCurrencyBundle()
18293
{
18394
if (null === self::$currencyBundle) {
184-
self::$currencyBundle = self::ICU === self::getDataSource()
185-
? new IcuCurrencyBundle(self::getBinaryReader())
186-
: new StubCurrencyBundle(self::getPhpReader());
95+
self::$currencyBundle = new IcuCurrencyBundle(self::getBundleReader());
18796
}
18897

18998
return self::$currencyBundle;
@@ -197,9 +106,7 @@ public static function getCurrencyBundle()
197106
public static function getLanguageBundle()
198107
{
199108
if (null === self::$languageBundle) {
200-
self::$languageBundle = self::ICU === self::getDataSource()
201-
? new IcuLanguageBundle(self::getBinaryReader())
202-
: new StubLanguageBundle(self::getPhpReader());
109+
self::$languageBundle = new IcuLanguageBundle(self::getBundleReader());
203110
}
204111

205112
return self::$languageBundle;
@@ -213,9 +120,7 @@ public static function getLanguageBundle()
213120
public static function getLocaleBundle()
214121
{
215122
if (null === self::$localeBundle) {
216-
self::$localeBundle = self::ICU === self::getDataSource()
217-
? new IcuLocaleBundle(self::getBinaryReader())
218-
: new StubLocaleBundle(self::getPhpReader());
123+
self::$localeBundle = new IcuLocaleBundle(self::getBundleReader());
219124
}
220125

221126
return self::$localeBundle;
@@ -229,9 +134,7 @@ public static function getLocaleBundle()
229134
public static function getRegionBundle()
230135
{
231136
if (null === self::$regionBundle) {
232-
self::$regionBundle = self::ICU === self::getDataSource()
233-
? new IcuRegionBundle(self::getBinaryReader())
234-
: new StubRegionBundle(self::getPhpReader());
137+
self::$regionBundle = new IcuRegionBundle(self::getBundleReader());
235138
}
236139

237140
return self::$regionBundle;
@@ -275,9 +178,7 @@ public static function getIcuVersion()
275178
public static function getIcuDataVersion()
276179
{
277180
if (false === self::$icuDataVersion) {
278-
self::$icuDataVersion = self::ICU === self::getDataSource()
279-
? IcuData::getVersion()
280-
: file_get_contents(__DIR__ . '/Resources/version.txt');
181+
self::$icuDataVersion = IcuData::getVersion();
281182
}
282183

283184
return self::$icuDataVersion;
@@ -298,33 +199,16 @@ public static function getIcuStubVersion()
298199
*
299200
* @return ResourceBundle\Reader\StructuredBundleReaderInterface The resource reader.
300201
*/
301-
private static function getPhpReader()
302-
{
303-
if (null === self::$phpReader) {
304-
self::$phpReader = new StructuredBundleReader(new BufferedBundleReader(
305-
new PhpBundleReader(),
306-
self::BUFFER_SIZE
307-
));
308-
}
309-
310-
return self::$phpReader;
311-
}
312-
313-
/**
314-
* Returns a resource bundle reader for binary .res resource bundle files.
315-
*
316-
* @return ResourceBundle\Reader\StructuredBundleReaderInterface The resource reader.
317-
*/
318-
private static function getBinaryReader()
202+
private static function getBundleReader()
319203
{
320-
if (null === self::$binaryReader) {
321-
self::$binaryReader = new StructuredBundleReader(new BufferedBundleReader(
322-
new BinaryBundleReader(),
204+
if (null === self::$bundleReader) {
205+
self::$bundleReader = new StructuredBundleReader(new BufferedBundleReader(
206+
IcuData::isLoadable() ? new BinaryBundleReader() : new PhpBundleReader(),
323207
self::BUFFER_SIZE
324208
));
325209
}
326210

327-
return self::$binaryReader;
211+
return self::$bundleReader;
328212
}
329213

330214
/**

0 commit comments

Comments
 (0)
0