33
33
*/
34
34
class Intl
35
35
{
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
-
46
36
/**
47
37
* The number of resource bundles to buffer. Loading the same resource
48
38
* bundle for n locales takes up n spots in the buffer.
49
39
*/
50
40
const BUFFER_SIZE = 10 ;
51
41
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
-
67
42
/**
68
43
* @var ResourceBundle\CurrencyBundleInterface
69
44
*/
@@ -97,12 +72,7 @@ class Intl
97
72
/**
98
73
* @var ResourceBundle\Reader\StructuredBundleReaderInterface
99
74
*/
100
- private static $ phpReader ;
101
-
102
- /**
103
- * @var ResourceBundle\Reader\StructuredBundleReaderInterface
104
- */
105
- private static $ binaryReader ;
75
+ private static $ bundleReader ;
106
76
107
77
/**
108
78
* Returns whether the intl extension is installed.
@@ -111,66 +81,7 @@ class Intl
111
81
*/
112
82
public static function isExtensionLoaded ()
113
83
{
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 ' );
174
85
}
175
86
176
87
/**
@@ -181,9 +92,7 @@ public static function getDataSource()
181
92
public static function getCurrencyBundle ()
182
93
{
183
94
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 ());
187
96
}
188
97
189
98
return self ::$ currencyBundle ;
@@ -197,9 +106,7 @@ public static function getCurrencyBundle()
197
106
public static function getLanguageBundle ()
198
107
{
199
108
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 ());
203
110
}
204
111
205
112
return self ::$ languageBundle ;
@@ -213,9 +120,7 @@ public static function getLanguageBundle()
213
120
public static function getLocaleBundle ()
214
121
{
215
122
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 ());
219
124
}
220
125
221
126
return self ::$ localeBundle ;
@@ -229,9 +134,7 @@ public static function getLocaleBundle()
229
134
public static function getRegionBundle ()
230
135
{
231
136
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 ());
235
138
}
236
139
237
140
return self ::$ regionBundle ;
@@ -275,9 +178,7 @@ public static function getIcuVersion()
275
178
public static function getIcuDataVersion ()
276
179
{
277
180
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 ();
281
182
}
282
183
283
184
return self ::$ icuDataVersion ;
@@ -298,33 +199,16 @@ public static function getIcuStubVersion()
298
199
*
299
200
* @return ResourceBundle\Reader\StructuredBundleReaderInterface The resource reader.
300
201
*/
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 ()
319
203
{
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 (),
323
207
self ::BUFFER_SIZE
324
208
));
325
209
}
326
210
327
- return self ::$ binaryReader ;
211
+ return self ::$ bundleReader ;
328
212
}
329
213
330
214
/**
0 commit comments