@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | /** |
240 | 240 | * Load the ICU culture data for the specific culture identifier. |
241 | - * @param string $culture the culture identifier. |
|
241 | + * @param string $cultureName the culture identifier. |
|
242 | 242 | */ |
243 | 243 | protected function loadCultureData($cultureName) |
244 | 244 | { |
@@ -282,6 +282,7 @@ discard block |
||
282 | 282 | * currency for "en_AU", you need to use findInfo("Currencies,true);. |
283 | 283 | * @param string $path the data you want to find. |
284 | 284 | * @param bool $merge merge the data from its parents. |
285 | + * @param string $key |
|
285 | 286 | * @return mixed the specific ICU data. |
286 | 287 | */ |
287 | 288 | public function findInfo($path='/', $merge=false, $key = null) |
@@ -487,7 +488,6 @@ discard block |
||
487 | 488 | * Simplify a single element array into its own value. |
488 | 489 | * E.g. <code>array(0 => array('hello'), 1 => 'world');</code> |
489 | 490 | * becomes <code>array(0 => 'hello', 1 => 'world');</code> |
490 | - * @param array $array with single elements arrays |
|
491 | 491 | * @return array simplified array. |
492 | 492 | */ |
493 | 493 | protected function simplify($obj) |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | |
560 | 560 | /** |
561 | 561 | * Get a list of timezones in the language of the localized version. |
562 | - * @return array list of localized timezones. |
|
562 | + * @return string[] list of localized timezones. |
|
563 | 563 | */ |
564 | 564 | public function getTimeZones() |
565 | 565 | { |
@@ -246,24 +246,24 @@ discard block |
||
246 | 246 | $current_part = $culture_parts[0]; |
247 | 247 | |
248 | 248 | $culturesToLoad = [$current_part]; |
249 | - for($i = 1, $k = count($culture_parts); $i < $k; ++$i) |
|
249 | + for ($i = 1, $k = count($culture_parts); $i < $k; ++$i) |
|
250 | 250 | { |
251 | - $current_part .= '_'.$culture_parts[$i]; |
|
251 | + $current_part .= '_' . $culture_parts[$i]; |
|
252 | 252 | $culturesToLoad[] = $current_part; |
253 | 253 | } |
254 | 254 | |
255 | - foreach(self::$bundleNames as $key => $bundleName) |
|
255 | + foreach (self::$bundleNames as $key => $bundleName) |
|
256 | 256 | { |
257 | - if(!array_key_exists($key, $this->data)) |
|
257 | + if (!array_key_exists($key, $this->data)) |
|
258 | 258 | $this->data[$key] = []; |
259 | 259 | } |
260 | - foreach($culturesToLoad as $culture) |
|
260 | + foreach ($culturesToLoad as $culture) |
|
261 | 261 | { |
262 | - if(in_array($culture, $this->resourceBundles)) |
|
262 | + if (in_array($culture, $this->resourceBundles)) |
|
263 | 263 | continue; |
264 | 264 | |
265 | 265 | array_unshift($this->resourceBundles, $culture); |
266 | - foreach(self::$bundleNames as $key => $bundleName) |
|
266 | + foreach (self::$bundleNames as $key => $bundleName) |
|
267 | 267 | { |
268 | 268 | $this->data[$key][$culture] = \ResourceBundle::create($culture, $bundleName, false); |
269 | 269 | } |
@@ -284,17 +284,17 @@ discard block |
||
284 | 284 | * @param bool $merge merge the data from its parents. |
285 | 285 | * @return mixed the specific ICU data. |
286 | 286 | */ |
287 | - public function findInfo($path='/', $merge=false, $key = null) |
|
287 | + public function findInfo($path = '/', $merge = false, $key = null) |
|
288 | 288 | { |
289 | 289 | $result = []; |
290 | 290 | |
291 | - if($key === null) |
|
291 | + if ($key === null) |
|
292 | 292 | { |
293 | 293 | // try to guess the bundle from the path. Always defaults to "Core". |
294 | 294 | $key = 'Core'; |
295 | - foreach(self::$bundleNames as $bundleName => $icuBundleName) |
|
295 | + foreach (self::$bundleNames as $bundleName => $icuBundleName) |
|
296 | 296 | { |
297 | - if(strpos($path, $bundleName) === 0) |
|
297 | + if (strpos($path, $bundleName) === 0) |
|
298 | 298 | { |
299 | 299 | $key = $bundleName; |
300 | 300 | break; |
@@ -302,17 +302,17 @@ discard block |
||
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | - if(!array_key_exists($key, $this->data)) |
|
305 | + if (!array_key_exists($key, $this->data)) |
|
306 | 306 | return $result; |
307 | - foreach($this->resourceBundles as $culture) |
|
307 | + foreach ($this->resourceBundles as $culture) |
|
308 | 308 | { |
309 | 309 | $res = $this->data[$key][$culture]; |
310 | - if($res === null) |
|
310 | + if ($res === null) |
|
311 | 311 | continue; |
312 | 312 | $info = $this->searchResources($res, $path); |
313 | - if($info) |
|
313 | + if ($info) |
|
314 | 314 | { |
315 | - if($merge) |
|
315 | + if ($merge) |
|
316 | 316 | $result = array_merge($result, $info); |
317 | 317 | else |
318 | 318 | return $info; |
@@ -330,16 +330,16 @@ discard block |
||
330 | 330 | * @param string $path slash "/" separated array path. |
331 | 331 | * @return mixed the value array using the path |
332 | 332 | */ |
333 | - private function searchResources($info, $path='/') |
|
333 | + private function searchResources($info, $path = '/') |
|
334 | 334 | { |
335 | 335 | $index = explode('/', $path); |
336 | 336 | |
337 | 337 | $resource = $info; |
338 | - for($i = 0, $k = count($index); $i < $k; ++$i) |
|
338 | + for ($i = 0, $k = count($index); $i < $k; ++$i) |
|
339 | 339 | { |
340 | 340 | |
341 | 341 | $resource = $resource->get($index[$i], false); |
342 | - if($resource === null) |
|
342 | + if ($resource === null) |
|
343 | 343 | return null; |
344 | 344 | } |
345 | 345 | |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | $reg = substr($this->culture, 3, 2); |
378 | 378 | $language = $this->findInfo("Languages/{$lang}"); |
379 | 379 | $region = $this->findInfo("Countries/{$reg}"); |
380 | - if($region) |
|
381 | - return $language.' ('.$region.')'; |
|
380 | + if ($region) |
|
381 | + return $language . ' (' . $region . ')'; |
|
382 | 382 | else |
383 | 383 | return $language; |
384 | 384 | } |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | } |
402 | 402 | |
403 | 403 | $region = $culture->findInfo("Countries/{$reg}"); |
404 | - if($region) |
|
405 | - return $language.' ('.$region.')'; |
|
404 | + if ($region) |
|
405 | + return $language . ' (' . $region . ')'; |
|
406 | 406 | else |
407 | 407 | return $language; |
408 | 408 | } |
@@ -458,25 +458,25 @@ discard block |
||
458 | 458 | * or CultureInfo::SPECIFIC. |
459 | 459 | * @return array list of culture information available. |
460 | 460 | */ |
461 | - public static function getCultures($type=CultureInfo::ALL) |
|
461 | + public static function getCultures($type = CultureInfo::ALL) |
|
462 | 462 | { |
463 | 463 | $all = \ResourceBundle::getLocales(''); |
464 | 464 | |
465 | - switch($type) |
|
465 | + switch ($type) |
|
466 | 466 | { |
467 | 467 | case CultureInfo::ALL : |
468 | 468 | return $all; |
469 | 469 | case CultureInfo::NEUTRAL : |
470 | - foreach($all as $key => $culture) |
|
470 | + foreach ($all as $key => $culture) |
|
471 | 471 | { |
472 | - if(strlen($culture) != 2) |
|
472 | + if (strlen($culture) != 2) |
|
473 | 473 | unset($all[$key]); |
474 | 474 | } |
475 | 475 | return $all; |
476 | 476 | case CultureInfo::SPECIFIC : |
477 | - foreach($all as $key => $culture) |
|
477 | + foreach ($all as $key => $culture) |
|
478 | 478 | { |
479 | - if(strlen($culture) == 2) |
|
479 | + if (strlen($culture) == 2) |
|
480 | 480 | unset($all[$key]); |
481 | 481 | } |
482 | 482 | return $all; |
@@ -492,17 +492,17 @@ discard block |
||
492 | 492 | */ |
493 | 493 | protected function simplify($obj) |
494 | 494 | { |
495 | - if(is_scalar($obj)) { |
|
495 | + if (is_scalar($obj)) { |
|
496 | 496 | return $obj; |
497 | - } elseif($obj instanceof \ResourceBundle) { |
|
497 | + } elseif ($obj instanceof \ResourceBundle) { |
|
498 | 498 | $array = array(); |
499 | - foreach($obj as $k => $v) |
|
499 | + foreach ($obj as $k => $v) |
|
500 | 500 | $array[$k] = $v; |
501 | 501 | } else { |
502 | 502 | $array = $obj; |
503 | 503 | } |
504 | 504 | |
505 | - for($i = 0, $k = count($array); $i<$k; ++$i) |
|
505 | + for ($i = 0, $k = count($array); $i < $k; ++$i) |
|
506 | 506 | { |
507 | 507 | $key = key($array); |
508 | 508 | if (is_array($array[$key]) |
@@ -530,10 +530,10 @@ discard block |
||
530 | 530 | public function getCurrencies() |
531 | 531 | { |
532 | 532 | static $arr; |
533 | - if($arr === null) |
|
533 | + if ($arr === null) |
|
534 | 534 | { |
535 | 535 | $arr = $this->findInfo('Currencies', true, 'Currencies'); |
536 | - foreach($arr as $k => $v) |
|
536 | + foreach ($arr as $k => $v) |
|
537 | 537 | $arr[$k] = $this->simplify($v); |
538 | 538 | } |
539 | 539 | return $arr; |
@@ -564,15 +564,15 @@ discard block |
||
564 | 564 | public function getTimeZones() |
565 | 565 | { |
566 | 566 | static $arr; |
567 | - if($arr === null) |
|
567 | + if ($arr === null) |
|
568 | 568 | { |
569 | 569 | $validPrefixes = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Etc', 'Europe', 'Indian', 'Pacific'); |
570 | 570 | $tmp = $this->findInfo('zoneStrings', true, 'zoneStrings'); |
571 | - foreach($tmp as $k => $v) |
|
571 | + foreach ($tmp as $k => $v) |
|
572 | 572 | { |
573 | - foreach($validPrefixes as $prefix) |
|
573 | + foreach ($validPrefixes as $prefix) |
|
574 | 574 | { |
575 | - if(strpos($k, $prefix) === 0) |
|
575 | + if (strpos($k, $prefix) === 0) |
|
576 | 576 | { |
577 | 577 | $arr[] = str_replace(':', '/', $k); |
578 | 578 | break; |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | */ |
191 | 191 | protected function getFormatter($culture, $datetype, $timetype) |
192 | 192 | { |
193 | - if(!isset(self::$formatters[$culture])) |
|
193 | + if (!isset(self::$formatters[$culture])) |
|
194 | 194 | self::$formatters[$culture] = []; |
195 | - if(!isset(self::$formatters[$culture][$datetype])) |
|
195 | + if (!isset(self::$formatters[$culture][$datetype])) |
|
196 | 196 | self::$formatters[$culture][$datetype] = []; |
197 | - if(!isset(self::$formatters[$culture][$datetype][$timetype])) |
|
197 | + if (!isset(self::$formatters[$culture][$datetype][$timetype])) |
|
198 | 198 | self::$formatters[$culture][$datetype][$timetype] = new \IntlDateFormatter($culture, $datetype, $timetype); |
199 | 199 | |
200 | 200 | return self::$formatters[$culture][$datetype][$timetype]; |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | $timetype = \IntlDateFormatter::LONG; |
231 | 231 | |
232 | 232 | // try the "date time" pattern format |
233 | - if(!empty($pattern)) |
|
233 | + if (!empty($pattern)) |
|
234 | 234 | { |
235 | 235 | $subs = explode(' ', $pattern, 2); |
236 | 236 | if (count($subs) == 2) { |
237 | 237 | $sub0 = $this->getPreset($subs[0]); |
238 | 238 | $sub1 = $this->getPreset($subs[1]); |
239 | 239 | |
240 | - if($sub0 !== null && $sub1 !== null) |
|
240 | + if ($sub0 !== null && $sub1 !== null) |
|
241 | 241 | { |
242 | 242 | $datetype = $sub0; |
243 | 243 | $timetype = $sub1; |
@@ -247,10 +247,10 @@ discard block |
||
247 | 247 | } |
248 | 248 | |
249 | 249 | // try the "date" pattern format |
250 | - if(!empty($pattern)) |
|
250 | + if (!empty($pattern)) |
|
251 | 251 | { |
252 | 252 | $sub = $this->getPreset($pattern); |
253 | - if($sub !== null) |
|
253 | + if ($sub !== null) |
|
254 | 254 | { |
255 | 255 | $datetype = $sub; |
256 | 256 | $timetype = $sub; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | - if(empty($pattern)) |
|
261 | + if (empty($pattern)) |
|
262 | 262 | { |
263 | 263 | $formatter = $this->getFormatter($culture, $datetype, $timetype); |
264 | 264 | } else { |
@@ -79,7 +79,7 @@ |
||
79 | 79 | protected function getIsValidLocale($locale) |
80 | 80 | { |
81 | 81 | static $allLocales; |
82 | - if($allLocales === null) |
|
82 | + if ($allLocales === null) |
|
83 | 83 | { |
84 | 84 | $all = \ResourceBundle::getLocales(''); |
85 | 85 | } |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | */ |
196 | 196 | protected function getFormatter($culture, $type) |
197 | 197 | { |
198 | - if(!isset(self::$formatters[$culture])) |
|
198 | + if (!isset(self::$formatters[$culture])) |
|
199 | 199 | self::$formatters[$culture] = []; |
200 | - if(!isset(self::$formatters[$culture][$type])) |
|
200 | + if (!isset(self::$formatters[$culture][$type])) |
|
201 | 201 | self::$formatters[$culture][$type] = new \NumberFormatter($culture, $type); |
202 | 202 | |
203 | 203 | return self::$formatters[$culture][$type]; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $type = $this->getType(); |
222 | 222 | $pattern = $this->getPattern(); |
223 | 223 | |
224 | - if(empty($pattern)) |
|
224 | + if (empty($pattern)) |
|
225 | 225 | { |
226 | 226 | $formatter = $this->getFormatter($culture, $type); |
227 | 227 | } else { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $formatter->setPattern($pattern); |
230 | 230 | } |
231 | 231 | |
232 | - if($type === \NumberFormatter::CURRENCY) |
|
232 | + if ($type === \NumberFormatter::CURRENCY) |
|
233 | 233 | { |
234 | 234 | $result = $formatter->formatCurrency($value, $this->getCurrency()); |
235 | 235 | } else { |