11
11
12
12
namespace Symfony \Component \Intl \Data \Generator ;
13
13
14
+ use Symfony \Component \Filesystem \Filesystem ;
14
15
use Symfony \Component \Intl \Data \Bundle \Compiler \BundleCompilerInterface ;
15
16
use Symfony \Component \Intl \Data \Bundle \Reader \BundleEntryReaderInterface ;
16
- use Symfony \Component \Intl \Data \Provider \RegionDataProvider ;
17
17
use Symfony \Component \Intl \Data \Util \ArrayAccessibleResourceBundle ;
18
18
use Symfony \Component \Intl \Data \Util \LocaleScanner ;
19
19
use Symfony \Component \Intl \Exception \MissingResourceException ;
@@ -34,14 +34,6 @@ class TimezoneDataGenerator extends AbstractDataGenerator
34
34
* @var string[]
35
35
*/
36
36
private $ zoneIds = [];
37
- private $ regionDataProvider ;
38
-
39
- public function __construct (BundleCompilerInterface $ compiler , string $ dirName , RegionDataProvider $ regionDataProvider )
40
- {
41
- parent ::__construct ($ compiler , $ dirName );
42
-
43
- $ this ->regionDataProvider = $ regionDataProvider ;
44
- }
45
37
46
38
/**
47
39
* {@inheritdoc}
@@ -56,6 +48,9 @@ protected function scanLocales(LocaleScanner $scanner, $sourceDir)
56
48
*/
57
49
protected function compileTemporaryBundles (BundleCompilerInterface $ compiler , $ sourceDir , $ tempDir )
58
50
{
51
+ $ filesystem = new Filesystem ();
52
+ $ filesystem ->mkdir ($ tempDir .'/region ' );
53
+ $ compiler ->compile ($ sourceDir .'/region ' , $ tempDir .'/region ' );
59
54
$ compiler ->compile ($ sourceDir .'/zone ' , $ tempDir );
60
55
$ compiler ->compile ($ sourceDir .'/misc/timezoneTypes.txt ' , $ tempDir );
61
56
$ compiler ->compile ($ sourceDir .'/misc/metaZones.txt ' , $ tempDir );
@@ -83,17 +78,13 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, $te
83
78
while (null !== ($ fallback = Locale::getFallback ($ fallback ))) {
84
79
$ localeBundles [] = $ reader ->read ($ tempDir , $ fallback );
85
80
}
86
- if ('root ' !== $ displayLocale ) {
87
- $ localeBundles [] = $ reader ->read ($ tempDir , 'root ' );
88
- }
89
81
$ metadata = [];
90
82
$ data = [
91
83
'Version ' => $ localeBundle ['Version ' ],
92
84
'Names ' => $ this ->generateZones (
85
+ $ reader ,
86
+ $ tempDir ,
93
87
$ displayLocale ,
94
- $ reader ->read ($ tempDir , 'timezoneTypes ' ),
95
- $ reader ->read ($ tempDir , 'metaZones ' ),
96
- $ reader ->read ($ tempDir , 'windowsZones ' ),
97
88
$ localeBundles ,
98
89
$ metadata
99
90
),
@@ -143,8 +134,11 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, $temp
143
134
/**
144
135
* @param ArrayAccessibleResourceBundle[] $localeBundles
145
136
*/
146
- private function generateZones (string $ locale , ArrayAccessibleResourceBundle $ typeBundle , ArrayAccessibleResourceBundle $ metaBundle , ArrayAccessibleResourceBundle $ windowsZonesBundle , array $ localeBundles , array &$ metadata = []): array
137
+ private function generateZones (BundleEntryReaderInterface $ reader , string $ tempDir , string $ locale , array $ localeBundles , array &$ metadata = []): array
147
138
{
139
+ $ typeBundle = $ reader ->read ($ tempDir , 'timezoneTypes ' );
140
+ $ metaBundle = $ reader ->read ($ tempDir , 'metaZones ' );
141
+ $ windowsZonesBundle = $ reader ->read ($ tempDir , 'windowsZones ' );
148
142
$ accessor = static function (ArrayAccessibleResourceBundle $ resourceBundle , array $ indices ) {
149
143
$ result = $ resourceBundle ;
150
144
foreach ($ indices as $ indice ) {
@@ -167,15 +161,15 @@ private function generateZones(string $locale, ArrayAccessibleResourceBundle $ty
167
161
168
162
return null ;
169
163
};
170
- $ regionFormat = $ accessor ( ['zoneStrings ' , 'regionFormat ' ]) ?? ' {0} ' ;
171
- $ fallbackFormat = $ accessor ( ['zoneStrings ' , 'fallbackFormat ' ]) ?? ' {1} ({0}) ' ;
164
+ $ regionFormat = $ reader -> readEntry ( $ tempDir , $ locale , ['zoneStrings ' , 'regionFormat ' ]);
165
+ $ fallbackFormat = $ reader -> readEntry ( $ tempDir , $ locale , ['zoneStrings ' , 'fallbackFormat ' ]);
172
166
$ zoneToCountry = self ::generateZoneToCountryMapping ($ windowsZonesBundle );
173
- $ resolveName = function (string $ id , string $ city = null ) use ($ locale , $ regionFormat , $ fallbackFormat , $ zoneToCountry ): string {
167
+ $ resolveName = function (string $ id , string $ city = null ) use ($ reader , $ tempDir , $ locale , $ regionFormat , $ fallbackFormat , $ zoneToCountry ): ? string {
174
168
if (isset ($ zoneToCountry [$ id ])) {
175
169
try {
176
- $ country = $ this -> regionDataProvider -> getName ( $ zoneToCountry [$ id ], $ locale );
170
+ $ country = $ reader -> readEntry ( $ tempDir . ' /region ' , $ locale , [ ' Countries ' , $ zoneToCountry [$ id ]] );
177
171
} catch (MissingResourceException $ e ) {
178
- $ country = $ this -> regionDataProvider -> getName ( $ zoneToCountry [ $ id ], ' en ' ) ;
172
+ return null ;
179
173
}
180
174
181
175
return null === $ city ? str_replace ('{0} ' , $ country , $ regionFormat ) : str_replace (['{0} ' , '{1} ' ], [$ city , $ country ], $ fallbackFormat );
@@ -260,10 +254,9 @@ private static function generateZoneToCountryMapping(ArrayAccessibleResourceBund
260
254
261
255
foreach ($ windowsZoneBundle ['mapTimezones ' ] as $ zoneInfo ) {
262
256
foreach ($ zoneInfo as $ region => $ zones ) {
263
- if (\in_array ($ region, [ ' 001 ' , ' ZZ ' ], true )) {
264
- continue ;
257
+ if (RegionDataGenerator:: isValidCountryCode ($ region )) {
258
+ $ mapping += array_fill_keys ( explode ( ' ' , $ zones ), $ region ) ;
265
259
}
266
- $ mapping += array_fill_keys (explode (' ' , $ zones ), $ region );
267
260
}
268
261
}
269
262
0 commit comments