|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------------+ |
|
4
|
|
|
// | This file is part of the Agavi package. | |
|
5
|
|
|
// | Copyright (c) 2005-2011 the Agavi Project. | |
|
6
|
|
|
// | | |
|
7
|
|
|
// | For the full copyright and license information, please view the LICENSE | |
|
8
|
|
|
// | file that was distributed with this source code. You can also view the | |
|
9
|
|
|
// | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
|
10
|
|
|
// | vi: set noexpandtab: | |
|
11
|
|
|
// | Local Variables: | |
|
12
|
|
|
// | indent-tabs-mode: t | |
|
13
|
|
|
// | End: | |
|
14
|
|
|
// +---------------------------------------------------------------------------+ |
|
15
|
|
|
|
|
16
|
|
|
namespace Agavi\Config; |
|
17
|
|
|
|
|
18
|
|
|
use Agavi\Date\DateDefinitions; |
|
19
|
|
|
use Agavi\Exception\AgaviException; |
|
20
|
|
|
use Agavi\Translation\Locale; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* AgaviLdmlConfigHandler allows you to parse ldml files into an array. |
|
24
|
|
|
* |
|
25
|
|
|
* @package agavi |
|
26
|
|
|
* @subpackage config |
|
27
|
|
|
* |
|
28
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
29
|
|
|
* @copyright Authors |
|
30
|
|
|
* @copyright The Agavi Project |
|
31
|
|
|
* |
|
32
|
|
|
* @since 0.11.0 |
|
33
|
|
|
* |
|
34
|
|
|
* @version $Id$ |
|
35
|
|
|
*/ |
|
36
|
|
|
class LdmlConfigHandler extends ConfigHandler |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
protected $nodeRefs = array(); |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Execute this configuration handler. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $config An absolute filesystem path to a configuration file. |
|
44
|
|
|
* @param string $context An optional context in which we are currently running. |
|
45
|
|
|
* |
|
46
|
|
|
* @return string Data to be written to a cache file. |
|
47
|
|
|
* |
|
48
|
|
|
* @throws <b>AgaviUnreadableException</b> If a requested configuration |
|
49
|
|
|
* file does not exist or is not |
|
50
|
|
|
* readable. |
|
51
|
|
|
* @throws <b>AgaviParseException</b> If a requested configuration file is |
|
52
|
|
|
* improperly formatted. |
|
53
|
|
|
* |
|
54
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
55
|
|
|
* @since 0.11.0 |
|
56
|
|
|
*/ |
|
57
|
|
|
public function execute($config, $context = null) |
|
58
|
|
|
{ |
|
59
|
|
|
$pathParts = pathinfo($config); |
|
60
|
|
|
// unlike basename, filename does not contain the extension, which is what we need there |
|
61
|
|
|
$lookupPaths = Locale::getLookupPath($pathParts['filename']); |
|
62
|
|
|
$lookupPaths[] = 'root'; |
|
63
|
|
|
|
|
64
|
|
|
$data = array( |
|
65
|
|
|
'layout' => array('orientation' => array('lines' => 'top-to-bottom', 'characters' => 'left-to-right')), |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
foreach (array_reverse($lookupPaths) as $basename) { |
|
69
|
|
|
$filePath = $pathParts['dirname'] . '/' . $basename . '.' . $pathParts['extension']; |
|
70
|
|
|
if (is_readable($filePath)) { |
|
71
|
|
|
$ldmlTree = ConfigCache::parseConfig($filePath, false, $this->getValidationFile(), $this->parser); |
|
|
|
|
|
|
72
|
|
|
$this->prepareParentInformation($ldmlTree); |
|
73
|
|
|
$this->parseLdmlTree($ldmlTree->ldml, $data); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$dayMap = array( |
|
78
|
|
|
'sun' => DateDefinitions::SUNDAY, |
|
79
|
|
|
'mon' => DateDefinitions::MONDAY, |
|
80
|
|
|
'tue' => DateDefinitions::TUESDAY, |
|
81
|
|
|
'wed' => DateDefinitions::WEDNESDAY, |
|
82
|
|
|
'thu' => DateDefinitions::THURSDAY, |
|
83
|
|
|
'fri' => DateDefinitions::FRIDAY, |
|
84
|
|
|
'sat' => DateDefinitions::SATURDAY, |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
// fix the day indices for all day fields |
|
88
|
|
|
foreach ($data['calendars'] as $calKey => &$calValue) { |
|
89
|
|
|
// skip the 'default' => '' key => value pair |
|
90
|
|
|
if (is_array($calValue)) { |
|
91
|
|
View Code Duplication |
if (isset($calValue['days']['format'])) { |
|
|
|
|
|
|
92
|
|
|
foreach ($calValue['days']['format'] as $formatKey => &$formatValue) { |
|
93
|
|
|
if (is_array($formatValue)) { |
|
94
|
|
|
$newData = array(); |
|
95
|
|
|
foreach ($formatValue as $day => $value) { |
|
96
|
|
|
$newData[$dayMap[$day]] = $value; |
|
97
|
|
|
} |
|
98
|
|
|
$formatValue = $newData; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
View Code Duplication |
if (isset($calValue['days']['stand-alone'])) { |
|
|
|
|
|
|
104
|
|
|
foreach ($calValue['days']['stand-alone'] as $formatKey => &$formatValue) { |
|
105
|
|
|
if (is_array($formatValue)) { |
|
106
|
|
|
$newData = array(); |
|
107
|
|
|
foreach ($formatValue as $day => $value) { |
|
108
|
|
|
$newData[$dayMap[$day]] = $value; |
|
109
|
|
|
} |
|
110
|
|
|
$formatValue = $newData; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$code = array(); |
|
118
|
|
|
$code[] = 'return ' . var_export($data, true) . ';'; |
|
119
|
|
|
|
|
120
|
|
|
return $this->generate($code, $config); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Prepares the parent information for the given ldml tree. |
|
125
|
|
|
* |
|
126
|
|
|
* @param ConfigValueHolder $ldmlTree The ldml tree. |
|
127
|
|
|
* |
|
128
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
129
|
|
|
* @since 0.11.0 |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function prepareParentInformation($ldmlTree) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->nodeRefs = array(); |
|
134
|
|
|
$i = 0; |
|
135
|
|
|
$ldmlTree->setAttribute('__agavi_node_id', $i); |
|
136
|
|
|
$ldmlTree->setAttribute('__agavi_parent_id', null); |
|
137
|
|
|
$this->nodeRefs[$i] = $ldmlTree; |
|
138
|
|
|
++$i; |
|
139
|
|
|
if ($ldmlTree->hasChildren()) { |
|
140
|
|
|
$this->generateParentInformation($ldmlTree->getChildren(), $i, 0); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Generates the parent information for the given ldml subtree. |
|
146
|
|
|
* |
|
147
|
|
|
* @param ConfigValueHolder[] $childList The ldml node. |
|
148
|
|
|
* @param int $nextId |
|
149
|
|
|
* @param int $parentId |
|
150
|
|
|
* |
|
151
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
152
|
|
|
* @since 0.11.0 |
|
153
|
|
|
*/ |
|
154
|
|
|
protected function generateParentInformation($childList, &$nextId, $parentId) |
|
155
|
|
|
{ |
|
156
|
|
|
/** @var ConfigValueHolder $child */ |
|
157
|
|
|
foreach ($childList as $child) { |
|
158
|
|
|
$child->setAttribute('__agavi_node_id', $nextId); |
|
159
|
|
|
$child->setAttribute('__agavi_parent_id', $parentId); |
|
160
|
|
|
$this->nodeRefs[$nextId] = $child; |
|
161
|
|
|
++$nextId; |
|
162
|
|
|
if ($child->hasChildren()) { |
|
163
|
|
|
$this->generateParentInformation($child->getChildren(), $nextId, $child->getAttribute('__agavi_node_id')); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/* |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
array data format |
|
172
|
|
|
|
|
173
|
|
|
|
|
174
|
|
|
locale = |
|
175
|
|
|
language = de|en|fr|.. |
|
176
|
|
|
territory = DE|AT|CH|.. |
|
177
|
|
|
script = Latn|... |
|
178
|
|
|
variant = NYNORSK|... |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
display Names = |
|
182
|
|
|
languages = |
|
183
|
|
|
[lId] = localized language |
|
184
|
|
|
scripts = |
|
185
|
|
|
[sId] = localized script name |
|
186
|
|
|
territories = |
|
187
|
|
|
[tId] = localized territory name |
|
188
|
|
|
variants = |
|
189
|
|
|
[vId] = localized variant name |
|
190
|
|
|
keys = |
|
191
|
|
|
[key] = localized key name |
|
192
|
|
|
measurementSystemNames= |
|
193
|
|
|
[mId] = localized measurement system name |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
layout = |
|
197
|
|
|
orientation = |
|
198
|
|
|
lines = top-to-bottom|bottom-to-top |
|
199
|
|
|
characters = left-to-right|right-to-left |
|
200
|
|
|
|
|
201
|
|
|
delimiters = |
|
202
|
|
|
quotationStart = The quotation start symbol |
|
203
|
|
|
quotationEnd = The quotation end symbol |
|
204
|
|
|
altQuotationStart = The alternative quotation start symbol |
|
205
|
|
|
altQuotationEnd = The alternative quotation end symbol |
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
calendars = |
|
209
|
|
|
default = The default calendar |
|
210
|
|
|
[cId] = |
|
211
|
|
|
months = |
|
212
|
|
|
default = format|stand-alone |
|
213
|
|
|
format = |
|
214
|
|
|
default = wide|abbreviated|narrow |
|
215
|
|
|
wide = |
|
216
|
|
|
1|2|3|... = The wide month name |
|
217
|
|
|
abbreviated = |
|
218
|
|
|
1|2|3|... = The abbreviated month name |
|
219
|
|
|
narrow = |
|
220
|
|
|
1|2|3|... = The narrow month name |
|
221
|
|
|
stand-alone = |
|
222
|
|
|
default = wide|abbreviated|narrow |
|
223
|
|
|
wide = |
|
224
|
|
|
1|2|3|... = The wide month name |
|
225
|
|
|
abbreviated = |
|
226
|
|
|
1|2|3|... = The abbreviated month name |
|
227
|
|
|
narrow = |
|
228
|
|
|
1|2|3|... = The narrow month name |
|
229
|
|
|
days = |
|
230
|
|
|
default = format|stand-alone |
|
231
|
|
|
format = |
|
232
|
|
|
default = wide|abbreviated|narrow |
|
233
|
|
|
wide = |
|
234
|
|
|
mon|tue|... = The wide day name |
|
235
|
|
|
abbreviated = |
|
236
|
|
|
... |
|
237
|
|
|
quarters = |
|
238
|
|
|
default = format|stand-alone |
|
239
|
|
|
format = |
|
240
|
|
|
default = wide|abbreviated|narrow |
|
241
|
|
|
wide = |
|
242
|
|
|
1|2|3|4 = The wide quarter name |
|
243
|
|
|
abbreviated = |
|
244
|
|
|
... |
|
245
|
|
|
am = The locale string for am |
|
246
|
|
|
pm = The locale string for pm |
|
247
|
|
|
eras = |
|
248
|
|
|
wide = |
|
249
|
|
|
1|2|3|... = The wide era name |
|
250
|
|
|
abbreviated = |
|
251
|
|
|
1|2|3|... = The abbreviated era name |
|
252
|
|
|
narrow = |
|
253
|
|
|
1|2|3|... = The narrow era name |
|
254
|
|
|
dateFormats = |
|
255
|
|
|
default = full|long|medium|short |
|
256
|
|
|
[dfId] = |
|
257
|
|
|
pattern = The date pattern |
|
258
|
|
|
displayName = An optional format name |
|
259
|
|
|
timeFormats = |
|
260
|
|
|
default = full|long|medium|short |
|
261
|
|
|
[tfId] = |
|
262
|
|
|
pattern = The time pattern |
|
263
|
|
|
displayName = An optional format name |
|
264
|
|
|
|
|
265
|
|
|
dateTimeFormats = |
|
266
|
|
|
default = full|long|medium|short |
|
267
|
|
|
formats = |
|
268
|
|
|
[fId] = pattern |
|
269
|
|
|
availableFormats = |
|
270
|
|
|
[afId] = The datetime pattern |
|
271
|
|
|
appendItems = |
|
272
|
|
|
[aiId] = pattern |
|
273
|
|
|
|
|
274
|
|
|
fields = |
|
275
|
|
|
[fId] = |
|
276
|
|
|
displayName = The localized name for this field |
|
277
|
|
|
relatives = |
|
278
|
|
|
[rId] = The localized relative of this field |
|
279
|
|
|
|
|
280
|
|
|
timeZoneNames |
|
281
|
|
|
hourFormat = |
|
282
|
|
|
hoursFormat = |
|
283
|
|
|
gmtFormat = |
|
284
|
|
|
regionFormat = |
|
285
|
|
|
fallbackFormat = |
|
286
|
|
|
abbreviationFallback = standard|...? |
|
287
|
|
|
singleCountries = |
|
288
|
|
|
[id] = timezone |
|
289
|
|
|
zones = |
|
290
|
|
|
[tzId] = |
|
291
|
|
|
long = |
|
292
|
|
|
generic = |
|
293
|
|
|
standard = |
|
294
|
|
|
daylight = |
|
295
|
|
|
short |
|
296
|
|
|
generic = |
|
297
|
|
|
standard = |
|
298
|
|
|
daylight = |
|
299
|
|
|
exemplarCity = |
|
300
|
|
|
|
|
301
|
|
|
numbers = |
|
302
|
|
|
symbols = |
|
303
|
|
|
decimal = . |
|
304
|
|
|
group = , |
|
305
|
|
|
list = ; |
|
306
|
|
|
percentSign = % |
|
307
|
|
|
nativeZeroDigit = 0 |
|
308
|
|
|
patternDigit = # |
|
309
|
|
|
plusSign = + |
|
310
|
|
|
minusSign = - |
|
311
|
|
|
exponential = E |
|
312
|
|
|
perMille = ‰ |
|
313
|
|
|
infinity = ∞ |
|
314
|
|
|
nan = ☹ |
|
315
|
|
|
decimalFormats = |
|
316
|
|
|
[dfId] = pattern |
|
317
|
|
|
scientificFormats = |
|
318
|
|
|
[sfId] = pattern |
|
319
|
|
|
percentFormats = |
|
320
|
|
|
[pfId] = pattern |
|
321
|
|
|
currencyFormats = |
|
322
|
|
|
[cfId] = pattern |
|
323
|
|
|
currencySpacing = |
|
324
|
|
|
beforeCurrency = |
|
325
|
|
|
currencyMatch = |
|
326
|
|
|
surroundingMatch = |
|
327
|
|
|
insertBetween = |
|
328
|
|
|
afterCurrency = |
|
329
|
|
|
currencyMatch = |
|
330
|
|
|
surroundingMatch = |
|
331
|
|
|
insertBetween = |
|
332
|
|
|
currencies = |
|
333
|
|
|
[cId] = |
|
334
|
|
|
displayName = The locale display name |
|
335
|
|
|
symbol = The symbol (or array when its a choice) |
|
336
|
|
|
|
|
337
|
|
|
|
|
338
|
|
|
*/ |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Generates the array used by AgaviLocale from an LDML tree. |
|
342
|
|
|
* |
|
343
|
|
|
* @param ConfigValueHolder $ldmlTree The ldml tree. |
|
344
|
|
|
* @param array $data The array to store the parsed data to. |
|
345
|
|
|
* |
|
346
|
|
|
* @return array The array with the data. |
|
347
|
|
|
* |
|
348
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
349
|
|
|
* @since 0.11.0 |
|
350
|
|
|
*/ |
|
351
|
|
|
public function parseLdmlTree($ldmlTree, &$data) |
|
352
|
|
|
{ |
|
353
|
|
|
|
|
354
|
|
|
if (isset($ldmlTree->identity)) { |
|
355
|
|
|
$data['locale']['language'] = $ldmlTree->identity->language->getAttribute('type'); |
|
|
|
|
|
|
356
|
|
View Code Duplication |
if (isset($ldmlTree->identity->territory)) { |
|
|
|
|
|
|
357
|
|
|
$data['locale']['territory'] = $ldmlTree->identity->territory->getAttribute('type'); |
|
|
|
|
|
|
358
|
|
|
} |
|
359
|
|
View Code Duplication |
if (isset($ldmlTree->identity->script)) { |
|
|
|
|
|
|
360
|
|
|
$data['locale']['script'] = $ldmlTree->identity->script->getAttribute('type'); |
|
|
|
|
|
|
361
|
|
|
} |
|
362
|
|
View Code Duplication |
if (isset($ldmlTree->identity->variant)) { |
|
|
|
|
|
|
363
|
|
|
$data['locale']['variant'] = $ldmlTree->identity->variant->getAttribute('type'); |
|
|
|
|
|
|
364
|
|
|
} |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
if (isset($ldmlTree->localeDisplayNames)) { |
|
368
|
|
|
$ldn = $ldmlTree->localeDisplayNames; |
|
|
|
|
|
|
369
|
|
|
|
|
370
|
|
View Code Duplication |
if (isset($ldn->languages)) { |
|
|
|
|
|
|
371
|
|
|
$data['displayNames']['languages'] = isset($data['displayNames']['languages']) ? $data['displayNames']['languages'] : array(); |
|
372
|
|
|
$this->getTypeList($ldn->languages, $data['displayNames']['languages']); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
View Code Duplication |
if (isset($ldn->scripts)) { |
|
|
|
|
|
|
376
|
|
|
$data['displayNames']['scripts'] = isset($data['displayNames']['scripts']) ? $data['displayNames']['scripts'] : array(); |
|
377
|
|
|
$this->getTypeList($ldn->scripts, $data['displayNames']['scripts']); |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
View Code Duplication |
if (isset($ldn->territories)) { |
|
|
|
|
|
|
381
|
|
|
$data['displayNames']['territories'] = isset($data['displayNames']['territories']) ? $data['displayNames']['territories'] : array(); |
|
382
|
|
|
$this->getTypeList($ldn->territories, $data['displayNames']['territories']); |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
View Code Duplication |
if (isset($ldn->variants)) { |
|
|
|
|
|
|
386
|
|
|
$data['displayNames']['variants'] = isset($data['displayNames']['variants']) ? $data['displayNames']['variants'] : array(); |
|
387
|
|
|
$this->getTypeList($ldn->variants, $data['displayNames']['variants']); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
View Code Duplication |
if (isset($ldn->keys)) { |
|
|
|
|
|
|
391
|
|
|
$data['displayNames']['keys'] = isset($data['displayNames']['keys']) ? $data['displayNames']['keys'] : array(); |
|
392
|
|
|
$this->getTypeList($ldn->keys, $data['displayNames']['keys']); |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
/* |
|
|
|
|
|
|
396
|
|
|
// not needed right now |
|
397
|
|
|
if(isset($ldn->types)) { |
|
398
|
|
|
} |
|
399
|
|
|
*/ |
|
400
|
|
|
|
|
401
|
|
View Code Duplication |
if (isset($ldn->measurementSystemNames)) { |
|
|
|
|
|
|
402
|
|
|
$data['displayNames']['measurementSystemNames'] = isset($data['displayNames']['measurementSystemNames']) ? $data['displayNames']['measurementSystemNames'] : array(); |
|
403
|
|
|
$this->getTypeList($ldn->measurementSystemNames, $data['displayNames']['measurementSystemNames']); |
|
404
|
|
|
} |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
if (isset($ldmlTree->layout->orientation)) { |
|
|
|
|
|
|
408
|
|
|
$ori = $ldmlTree->layout->orientation; |
|
|
|
|
|
|
409
|
|
|
|
|
410
|
|
|
$data['layout']['orientation']['lines'] = $ori->getAttribute('lines', $data['layout']['orientation']['lines']); |
|
411
|
|
|
$data['layout']['orientation']['characters'] = $ori->getAttribute('characters', $data['layout']['orientation']['characters']); |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
if (isset($ldmlTree->delimiters)) { |
|
415
|
|
|
$delims = $ldmlTree->delimiters; |
|
|
|
|
|
|
416
|
|
|
|
|
417
|
|
|
if (isset($delims->quotationStart)) { |
|
418
|
|
|
$data['delimiters']['quotationStart'] = $this->unescape($delims->quotationStart->getValue()); |
|
419
|
|
|
} |
|
420
|
|
|
if (isset($delims->quotationEnd)) { |
|
421
|
|
|
$data['delimiters']['quotationEnd'] = $this->unescape($delims->quotationEnd->getValue()); |
|
422
|
|
|
} |
|
423
|
|
|
if (isset($delims->alternateQuotationStart)) { |
|
424
|
|
|
$data['delimiters']['alternateQuotationStart'] = $this->unescape($delims->alternateQuotationStart->getValue()); |
|
425
|
|
|
} |
|
426
|
|
|
if (isset($delims->alternateQuotationEnd)) { |
|
427
|
|
|
$data['delimiters']['alternateQuotationEnd'] = $this->unescape($delims->alternateQuotationEnd->getValue()); |
|
428
|
|
|
} |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
if (isset($ldmlTree->dates)) { |
|
432
|
|
|
$dates = $ldmlTree->dates; |
|
|
|
|
|
|
433
|
|
|
|
|
434
|
|
|
if (isset($dates->calendars)) { |
|
435
|
|
|
$cals = $dates->calendars; |
|
436
|
|
|
|
|
437
|
|
|
foreach ($cals as $calendar) { |
|
438
|
|
|
if ($calendar->getName() == 'default') { |
|
439
|
|
|
$data['calendars']['default'] = $calendar->getAttribute('choice'); |
|
440
|
|
|
} elseif ($calendar->getName() == 'calendar') { |
|
441
|
|
|
$calendarName = $calendar->getAttribute('type'); |
|
442
|
|
|
|
|
443
|
|
|
if (!isset($data['calendars'][$calendarName])) { |
|
444
|
|
|
$data['calendars'][$calendarName] = array(); |
|
445
|
|
|
} |
|
446
|
|
|
|
|
447
|
|
|
if (isset($calendar->months)) { |
|
448
|
|
|
$this->getCalendarWidth($calendar->months, 'month', $data['calendars'][$calendarName]); |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
if (isset($calendar->days)) { |
|
452
|
|
|
$this->getCalendarWidth($calendar->days, 'day', $data['calendars'][$calendarName]); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
if (isset($calendar->quarters)) { |
|
456
|
|
|
$this->getCalendarWidth($calendar->quarters, 'quarter', $data['calendars'][$calendarName]); |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
View Code Duplication |
if (isset($calendar->am)) { |
|
|
|
|
|
|
460
|
|
|
$data['calendars'][$calendarName]['am'] = $this->unescape($calendar->am->getValue()); |
|
461
|
|
|
} |
|
462
|
|
View Code Duplication |
if (isset($calendar->pm)) { |
|
|
|
|
|
|
463
|
|
|
$data['calendars'][$calendarName]['pm'] = $this->unescape($calendar->pm->getValue()); |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
if (isset($calendar->eras)) { |
|
467
|
|
View Code Duplication |
if (isset($calendar->eras->eraNames)) { |
|
|
|
|
|
|
468
|
|
|
foreach ($this->getChildsOrAlias($calendar->eras->eraNames) as $era) { |
|
469
|
|
|
$data['calendars'][$calendarName]['eras']['wide'][$era->getAttribute('type')] = $this->unescape($era->getValue()); |
|
470
|
|
|
} |
|
471
|
|
|
} |
|
472
|
|
View Code Duplication |
if (isset($calendar->eras->eraAbbr)) { |
|
|
|
|
|
|
473
|
|
|
foreach ($this->getChildsOrAlias($calendar->eras->eraAbbr) as $era) { |
|
474
|
|
|
$data['calendars'][$calendarName]['eras']['abbreviated'][$era->getAttribute('type')] = $this->unescape($era->getValue()); |
|
475
|
|
|
} |
|
476
|
|
|
} |
|
477
|
|
View Code Duplication |
if (isset($calendar->eras->eraNarrow)) { |
|
|
|
|
|
|
478
|
|
|
foreach ($this->getChildsOrAlias($calendar->eras->eraNarrow) as $era) { |
|
479
|
|
|
$data['calendars'][$calendarName]['eras']['narrow'][$era->getAttribute('type')] = $this->unescape($era->getValue()); |
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
if (isset($calendar->dateFormats)) { |
|
485
|
|
|
$this->getDateOrTimeFormats($calendar->dateFormats, 'dateFormat', $data['calendars'][$calendarName]); |
|
486
|
|
|
} |
|
487
|
|
|
if (isset($calendar->timeFormats)) { |
|
488
|
|
|
$this->getDateOrTimeFormats($calendar->timeFormats, 'timeFormat', $data['calendars'][$calendarName]); |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
if (isset($calendar->dateTimeFormats)) { |
|
492
|
|
|
$dtf = $calendar->dateTimeFormats; |
|
493
|
|
|
$data['calendars'][$calendarName]['dateTimeFormats']['default'] = isset($dtf->default) ? $dtf->default->getAttribute('choice') : '__default'; |
|
494
|
|
|
|
|
495
|
|
|
$dtfItems = $this->getChildsOrAlias($dtf); |
|
496
|
|
|
foreach ($dtfItems as $item) { |
|
497
|
|
|
if ($item->getName() == 'dateTimeFormatLength') { |
|
498
|
|
|
if (isset($item->dateTimeFormat->pattern)) { |
|
499
|
|
|
$data['calendars'][$calendarName]['dateTimeFormats']['formats'][$item->getAttribute('type', '__default')] = $this->unescape($item->dateTimeFormat->pattern->getValue(), true); |
|
500
|
|
|
} else { |
|
501
|
|
|
throw new AgaviException('unknown child content in dateTimeFormatLength tag'); |
|
502
|
|
|
} |
|
503
|
|
|
} elseif ($item->getName() == 'availableFormats') { |
|
504
|
|
View Code Duplication |
foreach ($item as $dateFormatItem) { |
|
|
|
|
|
|
505
|
|
|
if ($dateFormatItem->getName() != 'dateFormatItem') { |
|
506
|
|
|
throw new AgaviException('unknown childtag "' . $dateFormatItem->getName() . '" in availableFormats tag'); |
|
507
|
|
|
} |
|
508
|
|
|
$data['calendars'][$calendarName]['dateTimeFormats']['availableFormats'][$dateFormatItem->getAttribute('id')] = $this->unescape($dateFormatItem->getValue(), true); |
|
509
|
|
|
} |
|
510
|
|
|
} elseif ($item->getName() == 'appendItems') { |
|
511
|
|
View Code Duplication |
foreach ($item as $appendItem) { |
|
|
|
|
|
|
512
|
|
|
if ($appendItem->getName() != 'appendItem') { |
|
513
|
|
|
throw new AgaviException('unknown childtag "' . $appendItem->getName() . '" in appendItems tag'); |
|
514
|
|
|
} |
|
515
|
|
|
$data['calendars'][$calendarName]['dateTimeFormats']['appendItems'][$appendItem->getAttribute('request')] = $this->unescape($appendItem->getValue(), true); |
|
516
|
|
|
} |
|
517
|
|
|
} elseif ($item->getName() != 'default') { |
|
518
|
|
|
throw new AgaviException('unknown childtag "' . $item->getName() . '" in dateTimeFormats tag'); |
|
519
|
|
|
} |
|
520
|
|
|
} |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
if (isset($calendar->fields)) { |
|
524
|
|
|
foreach ($this->getChildsOrAlias($calendar->fields) as $field) { |
|
525
|
|
|
$type = $field->getAttribute('type'); |
|
526
|
|
|
if (isset($field->displayName)) { |
|
527
|
|
|
$data['calendars'][$calendarName]['fields'][$type]['displayName'] = $this->unescape($field->displayName->getValue()); |
|
528
|
|
|
} |
|
529
|
|
|
if (isset($field->relative)) { |
|
530
|
|
|
foreach ($field as $relative) { |
|
531
|
|
|
if ($relative->getName() == 'relative') { |
|
532
|
|
|
$data['calendars'][$calendarName]['fields'][$type]['relatives'][$relative->getAttribute('type')] = $this->unescape($relative->getValue()); |
|
533
|
|
|
} |
|
534
|
|
|
} |
|
535
|
|
|
} |
|
536
|
|
|
} |
|
537
|
|
|
} |
|
538
|
|
|
} else { |
|
539
|
|
|
throw new AgaviException('unknown childtag "' . $calendar->getName() . '" in calendars tag'); |
|
540
|
|
|
} |
|
541
|
|
|
} |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
|
|
if (isset($dates->timeZoneNames)) { |
|
545
|
|
|
$tzn = $dates->timeZoneNames; |
|
546
|
|
|
if (isset($tzn->hourFormat)) { |
|
547
|
|
|
$data['timeZoneNames']['hourFormat'] = $this->unescape($tzn->hourFormat->getValue()); |
|
548
|
|
|
} |
|
549
|
|
|
if (isset($tzn->hoursFormat)) { |
|
550
|
|
|
$data['timeZoneNames']['hoursFormat'] = $this->unescape($tzn->hoursFormat->getValue()); |
|
551
|
|
|
} |
|
552
|
|
|
if (isset($tzn->gmtFormat)) { |
|
553
|
|
|
$data['timeZoneNames']['gmtFormat'] = $this->unescape($tzn->gmtFormat->getValue()); |
|
554
|
|
|
} |
|
555
|
|
|
if (isset($tzn->regionFormat)) { |
|
556
|
|
|
$data['timeZoneNames']['regionFormat'] = $this->unescape($tzn->regionFormat->getValue()); |
|
557
|
|
|
} |
|
558
|
|
|
if (isset($tzn->fallbackFormat)) { |
|
559
|
|
|
$data['timeZoneNames']['fallbackFormat'] = $this->unescape($tzn->fallbackFormat->getValue()); |
|
560
|
|
|
} |
|
561
|
|
|
if (isset($tzn->abbreviationFallback)) { |
|
562
|
|
|
$data['timeZoneNames']['abbreviationFallback'] = $tzn->abbreviationFallback->getAttribute('choice'); |
|
563
|
|
|
} |
|
564
|
|
|
if (isset($tzn->singleCountries)) { |
|
565
|
|
|
$data['timeZoneNames']['singleCountries'] = explode(' ', $tzn->singleCountries->getAttribute('list')); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
foreach ($tzn as $zone) { |
|
569
|
|
|
$zoneName = $zone->getAttribute('type'); |
|
570
|
|
|
if ($zone->getName() == 'zone') { |
|
571
|
|
|
if (isset($zone->long->generic)) { |
|
572
|
|
|
$data['timeZoneNames']['zones'][$zoneName]['long']['generic'] = $this->unescape($zone->long->generic->getValue()); |
|
573
|
|
|
} |
|
574
|
|
View Code Duplication |
if (isset($zone->long->standard)) { |
|
|
|
|
|
|
575
|
|
|
$data['timeZoneNames']['zones'][$zoneName]['long']['standard'] = $this->unescape($zone->long->standard->getValue()); |
|
576
|
|
|
} |
|
577
|
|
|
if (isset($zone->long->daylight)) { |
|
578
|
|
|
$data['timeZoneNames']['zones'][$zoneName]['long']['daylight'] = $this->unescape($zone->long->daylight->getValue()); |
|
579
|
|
|
} |
|
580
|
|
View Code Duplication |
if (isset($zone->short->generic)) { |
|
|
|
|
|
|
581
|
|
|
$data['timeZoneNames']['zones'][$zoneName]['short']['generic'] = $this->unescape($zone->short->generic->getValue()); |
|
582
|
|
|
} |
|
583
|
|
View Code Duplication |
if (isset($zone->short->standard)) { |
|
|
|
|
|
|
584
|
|
|
$data['timeZoneNames']['zones'][$zoneName]['short']['standard'] = $this->unescape($zone->short->standard->getValue()); |
|
585
|
|
|
} |
|
586
|
|
View Code Duplication |
if (isset($zone->short->daylight)) { |
|
|
|
|
|
|
587
|
|
|
$data['timeZoneNames']['zones'][$zoneName]['short']['daylight'] = $this->unescape($zone->short->daylight->getValue()); |
|
588
|
|
|
} |
|
589
|
|
|
if (isset($zone->exemplarCity)) { |
|
590
|
|
|
$data['timeZoneNames']['zones'][$zoneName]['exemplarCity'] = $this->unescape($zone->exemplarCity->getValue()); |
|
591
|
|
|
} |
|
592
|
|
|
} |
|
593
|
|
|
} |
|
594
|
|
|
} |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
if (isset($ldmlTree->numbers)) { |
|
598
|
|
|
$nums = $ldmlTree->numbers; |
|
|
|
|
|
|
599
|
|
|
if (!isset($data['numbers'])) { |
|
600
|
|
|
$data['numbers'] = array(); |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
if (isset($nums->symbols)) { |
|
604
|
|
|
$syms = $nums->symbols; |
|
605
|
|
View Code Duplication |
if (isset($syms->decimal)) { |
|
|
|
|
|
|
606
|
|
|
$data['numbers']['symbols']['decimal'] = $this->unescape($syms->decimal->getValue()); |
|
607
|
|
|
} |
|
608
|
|
View Code Duplication |
if (isset($syms->group)) { |
|
|
|
|
|
|
609
|
|
|
$data['numbers']['symbols']['group'] = $this->unescape($syms->group->getValue()); |
|
610
|
|
|
} |
|
611
|
|
View Code Duplication |
if (isset($syms->list)) { |
|
|
|
|
|
|
612
|
|
|
$data['numbers']['symbols']['list'] = $this->unescape($syms->list->getValue()); |
|
613
|
|
|
} |
|
614
|
|
View Code Duplication |
if (isset($syms->percentSign)) { |
|
|
|
|
|
|
615
|
|
|
$data['numbers']['symbols']['percentSign'] = $this->unescape($syms->percentSign->getValue()); |
|
616
|
|
|
} |
|
617
|
|
View Code Duplication |
if (isset($syms->nativeZeroDigit)) { |
|
|
|
|
|
|
618
|
|
|
$data['numbers']['symbols']['nativeZeroDigit'] = $this->unescape($syms->nativeZeroDigit->getValue()); |
|
619
|
|
|
} |
|
620
|
|
View Code Duplication |
if (isset($syms->patternDigit)) { |
|
|
|
|
|
|
621
|
|
|
$data['numbers']['symbols']['patternDigit'] = $this->unescape($syms->patternDigit->getValue()); |
|
622
|
|
|
} |
|
623
|
|
View Code Duplication |
if (isset($syms->plusSign)) { |
|
|
|
|
|
|
624
|
|
|
$data['numbers']['symbols']['plusSign'] = $this->unescape($syms->plusSign->getValue()); |
|
625
|
|
|
} |
|
626
|
|
View Code Duplication |
if (isset($syms->minusSign)) { |
|
|
|
|
|
|
627
|
|
|
$data['numbers']['symbols']['minusSign'] = $this->unescape($syms->minusSign->getValue()); |
|
628
|
|
|
} |
|
629
|
|
View Code Duplication |
if (isset($syms->exponential)) { |
|
|
|
|
|
|
630
|
|
|
$data['numbers']['symbols']['exponential'] = $this->unescape($syms->exponential->getValue()); |
|
631
|
|
|
} |
|
632
|
|
View Code Duplication |
if (isset($syms->perMille)) { |
|
|
|
|
|
|
633
|
|
|
$data['numbers']['symbols']['perMille'] = $this->unescape($syms->perMille->getValue()); |
|
634
|
|
|
} |
|
635
|
|
View Code Duplication |
if (isset($syms->infinity)) { |
|
|
|
|
|
|
636
|
|
|
$data['numbers']['symbols']['infinity'] = $this->unescape($syms->infinity->getValue()); |
|
637
|
|
|
} |
|
638
|
|
View Code Duplication |
if (isset($syms->nan)) { |
|
|
|
|
|
|
639
|
|
|
$data['numbers']['symbols']['nan'] = $this->unescape($syms->nan->getValue()); |
|
640
|
|
|
} |
|
641
|
|
|
} |
|
642
|
|
|
if (isset($nums->decimalFormats)) { |
|
643
|
|
|
$this->getNumberFormats($nums->decimalFormats, 'decimalFormat', $data['numbers']); |
|
644
|
|
|
} |
|
645
|
|
|
if (isset($nums->scientificFormats)) { |
|
646
|
|
|
$this->getNumberFormats($nums->scientificFormats, 'scientificFormat', $data['numbers']); |
|
647
|
|
|
} |
|
648
|
|
|
if (isset($nums->percentFormats)) { |
|
649
|
|
|
$this->getNumberFormats($nums->percentFormats, 'percentFormat', $data['numbers']); |
|
650
|
|
|
} |
|
651
|
|
|
if (isset($nums->currencyFormats)) { |
|
652
|
|
|
$cf = $nums->currencyFormats; |
|
653
|
|
|
|
|
654
|
|
|
foreach ($this->getChildsOrAlias($cf) as $itemLength) { |
|
655
|
|
|
if ($itemLength->getName() == 'default') { |
|
656
|
|
|
$data['numbers']['currencyFormats']['default'] = $itemLength->getAttribute('choice'); |
|
657
|
|
|
} elseif ($itemLength->getName() == 'currencyFormatLength') { |
|
658
|
|
|
$itemLengthName = $itemLength->getAttribute('type', '__default'); |
|
659
|
|
|
|
|
660
|
|
|
foreach ($this->getChildsOrAlias($itemLength) as $itemFormat) { |
|
661
|
|
|
if ($itemFormat->getName() == 'currencyFormat') { |
|
662
|
|
|
if (isset($itemFormat->pattern)) { |
|
663
|
|
|
$data['numbers']['currencyFormats'][$itemLengthName] = $this->unescape($itemFormat->pattern->getValue()); |
|
664
|
|
|
} |
|
665
|
|
|
} else { |
|
666
|
|
|
throw new AgaviException('unknown childtag "' . $itemFormat->getName() . '" in currencyFormatLength tag'); |
|
667
|
|
|
} |
|
668
|
|
|
} |
|
669
|
|
|
} elseif ($itemLength->getName() == 'currencySpacing') { |
|
670
|
|
View Code Duplication |
if (isset($itemLength->beforeCurrency->currencyMatch)) { |
|
|
|
|
|
|
671
|
|
|
$data['numbers']['currencySpacing']['beforeCurrency']['currencyMatch'] = $this->unescape($itemLength->beforeCurrency->currencyMatch->getValue()); |
|
672
|
|
|
} |
|
673
|
|
View Code Duplication |
if (isset($itemLength->beforeCurrency->surroundingMatch)) { |
|
|
|
|
|
|
674
|
|
|
$data['numbers']['currencySpacing']['beforeCurrency']['surroundingMatch'] = $this->unescape($itemLength->beforeCurrency->surroundingMatch->getValue()); |
|
675
|
|
|
} |
|
676
|
|
View Code Duplication |
if (isset($itemLength->beforeCurrency->insertBetween)) { |
|
|
|
|
|
|
677
|
|
|
$data['numbers']['currencySpacing']['beforeCurrency']['insertBetween'] = $this->unescape($itemLength->beforeCurrency->insertBetween->getValue()); |
|
678
|
|
|
} |
|
679
|
|
View Code Duplication |
if (isset($itemLength->afterCurrency->currencyMatch)) { |
|
|
|
|
|
|
680
|
|
|
$data['numbers']['currencySpacing']['afterCurrency']['currencyMatch'] = $this->unescape($itemLength->afterCurrency->currencyMatch->getValue()); |
|
681
|
|
|
} |
|
682
|
|
View Code Duplication |
if (isset($itemLength->afterCurrency->surroundingMatch)) { |
|
|
|
|
|
|
683
|
|
|
$data['numbers']['currencySpacing']['afterCurrency']['surroundingMatch'] = $this->unescape($itemLength->afterCurrency->surroundingMatch->getValue()); |
|
684
|
|
|
} |
|
685
|
|
View Code Duplication |
if (isset($itemLength->afterCurrency->insertBetween)) { |
|
|
|
|
|
|
686
|
|
|
$data['numbers']['currencySpacing']['afterCurrency']['insertBetween'] = $this->unescape($itemLength->afterCurrency->insertBetween->getValue()); |
|
687
|
|
|
} |
|
688
|
|
|
} else { |
|
689
|
|
|
throw new AgaviException('unknown childtag "' . $itemLength->getName() . '" in currencyFormats tag'); |
|
690
|
|
|
} |
|
691
|
|
|
} |
|
692
|
|
|
} |
|
693
|
|
|
if (isset($nums->currencies)) { |
|
694
|
|
|
foreach ($nums->currencies as $currency) { |
|
695
|
|
|
$name = $currency->getAttribute('type'); |
|
696
|
|
|
if (isset($currency->displayName)) { |
|
697
|
|
|
$data['numbers']['currencies'][$name]['displayName'] = $this->unescape($currency->displayName->getValue()); |
|
698
|
|
|
} |
|
699
|
|
|
if (isset($currency->symbol)) { |
|
700
|
|
|
$symbolValue = $this->unescape($currency->symbol->getValue()); |
|
701
|
|
|
if ($currency->symbol->getAttribute('choice') == 'true') { |
|
702
|
|
|
$symbolValue = explode('|', $symbolValue); |
|
703
|
|
|
} |
|
704
|
|
|
$data['numbers']['currencies'][$name]['symbol'] = $symbolValue; |
|
705
|
|
|
} |
|
706
|
|
|
} |
|
707
|
|
|
} |
|
708
|
|
|
} |
|
709
|
|
|
|
|
710
|
|
|
return $data; |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
|
|
/** |
|
714
|
|
|
* Gets the value of each node with a type attribute. |
|
715
|
|
|
* |
|
716
|
|
|
* @param array $list List of ConfigValueHolder items. |
|
717
|
|
|
* @param array $data The array to store the parsed data to. |
|
718
|
|
|
* |
|
719
|
|
|
* @return array The array with the data. |
|
720
|
|
|
* |
|
721
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
722
|
|
|
* @since 0.11.0 |
|
723
|
|
|
*/ |
|
724
|
|
|
protected function getTypeList($list, &$data) |
|
725
|
|
|
{ |
|
726
|
|
|
// debug stuff to check if we missed any tags (lc = loop count) |
|
727
|
|
|
$lc = 0; |
|
728
|
|
|
foreach ($list as $listItem) { |
|
729
|
|
|
$type = $listItem->getAttribute('type'); |
|
730
|
|
|
|
|
731
|
|
|
if (!$listItem->hasAttribute('alt')) { |
|
732
|
|
|
$data[$type] = $this->unescape($listItem->getValue()); |
|
733
|
|
|
} |
|
734
|
|
|
|
|
735
|
|
|
++$lc; |
|
736
|
|
|
} |
|
737
|
|
|
|
|
738
|
|
|
if ($lc != count($list->getChildren())) { |
|
|
|
|
|
|
739
|
|
|
throw new AgaviException('wrong tagcount'); |
|
740
|
|
|
} |
|
741
|
|
|
|
|
742
|
|
|
return $data; |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
/** |
|
746
|
|
|
* Gets the calendar widths for the given item. |
|
747
|
|
|
* |
|
748
|
|
|
* @param ConfigValueHolder $item The item. |
|
749
|
|
|
* @param string $name The name of item. |
|
750
|
|
|
* @param array $data The array to store the parsed data to. |
|
751
|
|
|
* |
|
752
|
|
|
* @return array The array with the data. |
|
753
|
|
|
* |
|
754
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
755
|
|
|
* @since 0.11.0 |
|
756
|
|
|
*/ |
|
757
|
|
|
protected function getCalendarWidth(ConfigValueHolder $item, $name, &$data) |
|
758
|
|
|
{ |
|
759
|
|
|
$dataIdxName = $name . 's'; |
|
760
|
|
|
|
|
761
|
|
|
$items = $this->getChildsOrAlias($item); |
|
762
|
|
|
foreach ($items as $itemContext) { |
|
763
|
|
|
if ($itemContext->getName() == 'default') { |
|
764
|
|
|
$data[$dataIdxName]['default'] = $itemContext->getAttribute('choice'); |
|
765
|
|
|
} elseif ($itemContext->getName() == $name . 'Context') { |
|
766
|
|
|
$itemContextName = $itemContext->getAttribute('type'); |
|
767
|
|
|
|
|
768
|
|
|
foreach ($itemContext as $itemWidths) { |
|
769
|
|
|
if ($itemWidths->getName() == 'default') { |
|
770
|
|
|
$data[$dataIdxName][$itemContextName]['default'] = $itemWidths->getAttribute('choice'); |
|
771
|
|
|
} elseif ($itemWidths->getName() == $name . 'Width') { |
|
772
|
|
|
$itemWidthName = $itemWidths->getAttribute('type'); |
|
773
|
|
|
|
|
774
|
|
|
$widthChildItems = $this->getChildsOrAlias($itemWidths); |
|
775
|
|
|
foreach ($widthChildItems as $item) { |
|
776
|
|
|
if ($item->getName() != $name) { |
|
777
|
|
|
throw new AgaviException('unknown childtag "' . $item->getName() . '" in ' . $name . 'Widths tag'); |
|
778
|
|
|
} |
|
779
|
|
|
|
|
780
|
|
|
if (!$item->hasAttribute('alt')) { |
|
781
|
|
|
$itemName = $item->getAttribute('type'); |
|
782
|
|
|
$data[$dataIdxName][$itemContextName][$itemWidthName][$itemName] = $this->unescape($item->getValue()); |
|
783
|
|
|
} |
|
784
|
|
|
} |
|
785
|
|
|
} else { |
|
786
|
|
|
throw new AgaviException('unknown childtag "' . $itemWidths->getName() . '" in ' . $name . 'Context tag'); |
|
787
|
|
|
} |
|
788
|
|
|
} |
|
789
|
|
|
} else { |
|
790
|
|
|
throw new AgaviException('unknown childtag "' . $itemContext->getName() . '" in ' . $name . 's tag'); |
|
791
|
|
|
} |
|
792
|
|
|
} |
|
793
|
|
|
} |
|
794
|
|
|
|
|
795
|
|
|
/** |
|
796
|
|
|
* Gets the date or time formats the given item. |
|
797
|
|
|
* |
|
798
|
|
|
* @param ConfigValueHolder $item The item. |
|
799
|
|
|
* @param string $name The name of item. |
|
800
|
|
|
* @param array $data The array to store the parsed data to. |
|
801
|
|
|
* |
|
802
|
|
|
* @return array The array with the data. |
|
803
|
|
|
* |
|
804
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
805
|
|
|
* @since 0.11.0 |
|
806
|
|
|
*/ |
|
807
|
|
|
protected function getDateOrTimeFormats(ConfigValueHolder $item, $name, &$data) |
|
808
|
|
|
{ |
|
809
|
|
|
$dataIdxName = $name . 's'; |
|
810
|
|
|
|
|
811
|
|
|
$items = $this->getChildsOrAlias($item); |
|
812
|
|
|
foreach ($items as $itemLength) { |
|
813
|
|
|
if ($itemLength->getName() == 'default') { |
|
814
|
|
|
$data[$dataIdxName]['default'] = $itemLength->getAttribute('choice'); |
|
815
|
|
|
} elseif ($itemLength->getName() == $name . 'Length') { |
|
816
|
|
|
$itemLengthName = $itemLength->getAttribute('type', '__default'); |
|
817
|
|
|
|
|
818
|
|
|
$aliasedItemLength = $this->getChildsOrAlias($itemLength); |
|
819
|
|
|
foreach ($aliasedItemLength as $itemFormat) { |
|
820
|
|
|
if ($itemFormat->getName() == $name) { |
|
821
|
|
View Code Duplication |
if (isset($itemFormat->pattern)) { |
|
|
|
|
|
|
822
|
|
|
$data[$dataIdxName][$itemLengthName]['pattern'] = $this->unescape($itemFormat->pattern->getValue(), true); |
|
823
|
|
|
} |
|
824
|
|
View Code Duplication |
if (isset($itemFormat->displayName)) { |
|
|
|
|
|
|
825
|
|
|
$data[$dataIdxName][$itemLengthName]['displayName'] = $this->unescape($itemFormat->displayName->getValue()); |
|
826
|
|
|
} |
|
827
|
|
|
} else { |
|
828
|
|
|
throw new AgaviException('unknown childtag "' . $itemFormat->getName() . '" in ' . $name . 'Length tag'); |
|
829
|
|
|
} |
|
830
|
|
|
} |
|
831
|
|
|
} else { |
|
832
|
|
|
throw new AgaviException('unknown childtag "' . $itemLength->getName() . '" in ' . $name . 's tag'); |
|
833
|
|
|
} |
|
834
|
|
|
} |
|
835
|
|
|
} |
|
836
|
|
|
|
|
837
|
|
|
/** |
|
838
|
|
|
* Gets the number formats the given item. |
|
839
|
|
|
* |
|
840
|
|
|
* @param ConfigValueHolder The item. |
|
841
|
|
|
* @param string The name of item. |
|
842
|
|
|
* @param array The array to store the parsed data to. |
|
843
|
|
|
* |
|
844
|
|
|
* @return array The array with the data. |
|
845
|
|
|
* |
|
846
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
847
|
|
|
* @since 0.11.0 |
|
848
|
|
|
*/ |
|
849
|
|
|
protected function getNumberFormats($item, $name, &$data) |
|
850
|
|
|
{ |
|
851
|
|
|
$dataIdxName = $name . 's'; |
|
852
|
|
|
|
|
853
|
|
|
$items = $this->getChildsOrAlias($item); |
|
854
|
|
|
foreach ($items as $itemLength) { |
|
855
|
|
|
if ($itemLength->getName() == 'default') { |
|
856
|
|
|
$data[$dataIdxName]['default'] = $itemLength->getAttribute('choice'); |
|
857
|
|
|
} elseif ($itemLength->getName() == $name . 'Length') { |
|
858
|
|
|
$itemLengthName = $itemLength->getAttribute('type', '__default'); |
|
859
|
|
|
|
|
860
|
|
|
foreach ($this->getChildsOrAlias($itemLength) as $itemFormat) { |
|
861
|
|
|
if ($itemFormat->getName() == $name) { |
|
862
|
|
|
if (isset($itemFormat->pattern)) { |
|
863
|
|
|
$data[$dataIdxName][$itemLengthName] = $this->unescape($itemFormat->pattern->getValue()); |
|
864
|
|
|
} |
|
865
|
|
|
} else { |
|
866
|
|
|
throw new AgaviException('unknown childtag "' . $itemFormat->getName() . '" in ' . $name . 'Length tag'); |
|
867
|
|
|
} |
|
868
|
|
|
} |
|
869
|
|
|
} else { |
|
870
|
|
|
throw new AgaviException('unknown childtag "' . $itemLength->getName() . '" in ' . $name . 's tag'); |
|
871
|
|
|
} |
|
872
|
|
|
} |
|
873
|
|
|
} |
|
874
|
|
|
|
|
875
|
|
|
/** |
|
876
|
|
|
* Resolves the alias LDML tag. |
|
877
|
|
|
* |
|
878
|
|
|
* @param ConfigValueHolder $item The item. |
|
879
|
|
|
* |
|
880
|
|
|
* @return mixed Either the item if there is no alias or the resolved |
|
881
|
|
|
* alias. |
|
882
|
|
|
* |
|
883
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
884
|
|
|
* @since 0.11.0 |
|
885
|
|
|
*/ |
|
886
|
|
|
protected function getChildsOrAlias(ConfigValueHolder $item) |
|
887
|
|
|
{ |
|
888
|
|
|
if (isset($item->alias)) { |
|
889
|
|
|
$alias = $item->alias; |
|
|
|
|
|
|
890
|
|
|
if ($alias->getAttribute('source') != 'locale') { |
|
891
|
|
|
throw new AgaviException('The alias handling doesn\'t support any source except locale (' . $alias->getAttribute('source') . ' was given)'); |
|
892
|
|
|
} |
|
893
|
|
|
|
|
894
|
|
|
$pathParts = explode('/', $alias->getAttribute('path')); |
|
895
|
|
|
|
|
896
|
|
|
$currentNodeId = $item->getAttribute('__agavi_node_id'); |
|
897
|
|
|
|
|
898
|
|
|
foreach ($pathParts as $part) { |
|
899
|
|
|
// select the parent node |
|
900
|
|
|
if ($part == '..') { |
|
901
|
|
|
$currentNodeId = $this->nodeRefs[$currentNodeId]->getAttribute('__agavi_parent_id'); |
|
902
|
|
|
} else { |
|
903
|
|
|
$predicates = array(); |
|
904
|
|
|
if (preg_match('#([^\[]+)\[([^\]]+)\]#', $part, $match)) { |
|
905
|
|
|
if (!preg_match('#@([^=]+)=\'([^\']+)\'#', $match[2], $predMatch)) { |
|
906
|
|
|
throw new AgaviException('Unknown predicate ' . $match[2] . ' in alias xpath spec'); |
|
907
|
|
|
} |
|
908
|
|
|
$tagName = $match[1]; |
|
909
|
|
|
$predicates[$predMatch[1]] = $predMatch[2]; |
|
910
|
|
|
} else { |
|
911
|
|
|
$tagName = $part; |
|
912
|
|
|
} |
|
913
|
|
|
foreach ($this->nodeRefs[$currentNodeId]->getChildren() as $childNode) { |
|
914
|
|
|
$isSearchedNode = false; |
|
915
|
|
|
if ($childNode->getName() == $tagName) { |
|
916
|
|
|
$predMatches = 0; |
|
917
|
|
|
foreach ($predicates as $attrib => $value) { |
|
918
|
|
|
if ($childNode->getAttribute($attrib) == $value) { |
|
919
|
|
|
++$predMatches; |
|
920
|
|
|
} |
|
921
|
|
|
} |
|
922
|
|
|
if ($predMatches == count($predicates)) { |
|
923
|
|
|
$isSearchedNode = true; |
|
924
|
|
|
} |
|
925
|
|
|
} |
|
926
|
|
|
|
|
927
|
|
|
if ($isSearchedNode) { |
|
928
|
|
|
$currentNodeId = $childNode->getAttribute('__agavi_node_id'); |
|
929
|
|
|
} |
|
930
|
|
|
} |
|
931
|
|
|
} |
|
932
|
|
|
} |
|
933
|
|
|
|
|
934
|
|
|
return $this->nodeRefs[$currentNodeId]->getChildren(); |
|
935
|
|
|
} else { |
|
936
|
|
|
return $item; |
|
937
|
|
|
} |
|
938
|
|
|
} |
|
939
|
|
|
|
|
940
|
|
|
/** |
|
941
|
|
|
* Unescapes unicode escapes |
|
942
|
|
|
* |
|
943
|
|
|
* @link http://unicode.org/reports/tr35/#Unicode_Sets |
|
944
|
|
|
* |
|
945
|
|
|
* @param string $input The string to unescape. |
|
946
|
|
|
* @param bool $handleQuotes Whether the string needs to handle quoting behaviour |
|
947
|
|
|
* |
|
948
|
|
|
* @return string The unescaped string. |
|
949
|
|
|
* |
|
950
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
951
|
|
|
* @since 0.11.0 |
|
952
|
|
|
*/ |
|
953
|
|
|
protected function unescape($input, $handleQuotes = false) |
|
954
|
|
|
{ |
|
955
|
|
|
$output = ''; |
|
|
|
|
|
|
956
|
|
|
$hex = '[0-9A-Fa-f]'; |
|
957
|
|
|
$rx = '\\\\(\\\\|u' . $hex . '{4}|U' . $hex . '{8}|x' . $hex .'{1,2}|[0-7]{1,3}|.)'; |
|
958
|
|
|
if ($handleQuotes) { |
|
959
|
|
|
// needs to be < -1 to not confuse the algorithm in the first run |
|
960
|
|
|
$lastClose = -2; |
|
|
|
|
|
|
961
|
|
|
if (preg_match_all("#'(?:''|[^'])+'|" . $rx . "#", $input, $matches, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE)) { |
|
962
|
|
|
$output = $input; |
|
963
|
|
|
$offsetMod = 0; |
|
964
|
|
|
$ml = $matches[0]; |
|
965
|
|
|
$len = count($ml); |
|
966
|
|
|
for ($i = 0; $i < $len; ++ $i) { |
|
967
|
|
|
$match = $ml[$i]; |
|
968
|
|
|
if ($match[0][0] != '\'') { |
|
969
|
|
|
// we check if there is a quoted string directly before or directly after the escape sequence |
|
970
|
|
|
// by using the string lengths and the offset of the matches. Since an escape sequence directly before |
|
971
|
|
|
// this sequence results in an quoted string we only check if its really a quoted string and not an |
|
972
|
|
|
// escape sequence for parts coming after this sequence |
|
973
|
|
|
$quoteBefore = ($i > 0 && (strlen($ml[$i - 1][0]) + $ml[$i - 1][1]) == $match[1]); |
|
974
|
|
|
$quoteAfter = ($i + 1 < $len && $ml[$i + 1][0][0] == '\'' && (strlen($match[0]) + $match[1]) == $ml[$i + 1][1]); |
|
975
|
|
|
$oldLen = strlen($output); |
|
976
|
|
|
$unescaped = $this->unescapeCallback(array($match[0], substr($match[0], 1))); |
|
977
|
|
|
$unescaped = ($quoteBefore ? '' : '\'') . $unescaped . ($quoteAfter ? '' : '\''); |
|
978
|
|
|
$replacedPartLen = strlen($match[0]) + ((int) $quoteBefore) + ((int) $quoteAfter); |
|
979
|
|
|
// replace the matched escape sequence with the unescaped one. we also replace the opening or closing quote |
|
980
|
|
|
// from the quoted part before or after this escape sequence to include the unescaped string into the closed part |
|
981
|
|
|
$output = substr_replace($output, $unescaped, $offsetMod + $match[1] + ($quoteBefore ? -1 : 0), $replacedPartLen); |
|
982
|
|
|
// since the string length gets changed, we have to track the size change so we can adjust the offset from the match |
|
983
|
|
|
$offsetMod += strlen($output) - $oldLen; |
|
984
|
|
|
} |
|
985
|
|
|
} |
|
986
|
|
|
} else { |
|
987
|
|
|
$output = $input; |
|
988
|
|
|
} |
|
989
|
|
|
} else { |
|
990
|
|
|
$output = preg_replace_callback('#' . $rx . '#', array($this, 'unescapeCallback'), $input); |
|
991
|
|
|
} |
|
992
|
|
|
|
|
993
|
|
|
return $output; |
|
994
|
|
|
} |
|
995
|
|
|
|
|
996
|
|
|
/** |
|
997
|
|
|
* Unescapes a single unicode escape sequence. This is designed to be a |
|
998
|
|
|
* preg_replace_callback callback function. |
|
999
|
|
|
* |
|
1000
|
|
|
* @param array $matches The match. |
|
1001
|
|
|
* |
|
1002
|
|
|
* @return string The unescaped sequence. |
|
1003
|
|
|
* |
|
1004
|
|
|
* @author Dominik del Bondio <[email protected]> |
|
1005
|
|
|
* @since 0.11.0 |
|
1006
|
|
|
*/ |
|
1007
|
|
|
protected function unescapeCallback($matches) |
|
1008
|
|
|
{ |
|
1009
|
|
|
static $map = array( |
|
1010
|
|
|
'a' => "\x07", |
|
1011
|
|
|
'b' => "\x08", |
|
1012
|
|
|
't' => "\x09", |
|
1013
|
|
|
'n' => "\x0A", |
|
1014
|
|
|
'v' => "\x0B", |
|
1015
|
|
|
'f' => "\x0C", |
|
1016
|
|
|
'r' => "\x0D", |
|
1017
|
|
|
'\\' => '\\', |
|
1018
|
|
|
); |
|
1019
|
|
|
|
|
1020
|
|
|
|
|
1021
|
|
|
$res = ''; |
|
|
|
|
|
|
1022
|
|
|
|
|
1023
|
|
|
$char = $matches[1][0]; |
|
1024
|
|
|
$seq = substr($matches[1], 1); |
|
1025
|
|
|
if ($char == 'u' || $char == 'U' || $char == 'x') { |
|
1026
|
|
|
$res = html_entity_decode('&#x' . $seq . ';', ENT_QUOTES, 'utf-8'); |
|
1027
|
|
|
} elseif (is_numeric($char)) { |
|
1028
|
|
|
$res = html_entity_decode('&#' . octdec($matches[1]) . ';', ENT_QUOTES, 'utf-8'); |
|
1029
|
|
|
} elseif (isset($map[$char])) { |
|
1030
|
|
|
$res = $map[$char]; |
|
1031
|
|
|
} else { |
|
1032
|
|
|
$res = $char; // something like \s or \0 or so, just return the character ("s" or "0") |
|
1033
|
|
|
} |
|
1034
|
|
|
|
|
1035
|
|
|
return $res; |
|
1036
|
|
|
} |
|
1037
|
|
|
} |
|
1038
|
|
|
|