Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataBundle.php
Go to the documentation of this file.
1 <?php
7 
8 class DataBundle
9 {
13  protected $path = 'ICUDATA';
14 
18  protected static $bundles = [];
19 
26  public function get($locale)
27  {
28  $locale = $this->cleanLocale($locale);
29  $class = get_class($this);
30  if (!isset(static::$bundles[$class][$locale])) {
31  $bundle = $this->createResourceBundle($locale, $this->path);
32  if (!$bundle && $this->path != 'ICUDATA') {
33  $bundle = $this->createResourceBundle($locale, 'ICUDATA');
34  }
35  static::$bundles[$class][$locale] = $bundle;
36  }
37  return static::$bundles[$class][$locale];
38  }
39 
45  protected function createResourceBundle($locale, $path)
46  {
47  try {
48  $bundle = new \ResourceBundle($locale, $path);
49  } catch (\Exception $e) {
50  // HHVM compatibility: constructor throws on invalid resource
51  $bundle = null;
52  }
53  return $bundle;
54  }
55 
62  protected function cleanLocale($locale)
63  {
64  $localeParts = \Locale::parseLocale($locale);
65  $cleanLocaleParts = [];
66  if (isset($localeParts['language'])) {
67  $cleanLocaleParts['language'] = $localeParts['language'];
68  }
69  if (isset($localeParts['script'])) {
70  $cleanLocaleParts['script'] = $localeParts['script'];
71  }
72  return \Locale::composeLocale($cleanLocaleParts);
73  }
74 }
$_option $_optionId $class
Definition: date.phtml:13