Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Lists.php
Go to the documentation of this file.
1 <?php
8 
14 
15 class Lists
16 {
22  protected $allowedLocales;
23 
29  private $allowedCurrencies;
30 
35  {
36  $this->allowedLocales = $localeConfig->getAllowedLocales();
37  $this->allowedCurrencies = $localeConfig->getAllowedCurrencies();
38  }
39 
46  public function getTimezoneList($doSort = true)
47  {
48  $zones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL);
49  $list = [];
50  foreach ($zones as $code) {
51  $list[$code] = \IntlTimeZone::createTimeZone($code)->getDisplayName(
52  false,
53  \IntlTimeZone::DISPLAY_LONG,
55  ) . ' (' . $code . ')';
56  }
57 
58  if ($doSort) {
59  asort($list);
60  }
61 
62  return $list;
63  }
64 
70  public function getCurrencyList()
71  {
72  $currencies = (new CurrencyBundle())->get(Resolver::DEFAULT_LOCALE)['Currencies'];
73  $list = [];
74  foreach ($currencies as $code => $data) {
75  $isAllowedCurrency = array_search($code, $this->allowedCurrencies) !== false;
76  if (!$isAllowedCurrency) {
77  continue;
78  }
79  $list[$code] = $data[1] . ' (' . $code . ')';
80  }
81  asort($list);
82  return $list;
83  }
84 
90  public function getLocaleList()
91  {
92  $languages = (new LanguageBundle())->get(Resolver::DEFAULT_LOCALE)['Languages'];
93  $countries = (new RegionBundle())->get(Resolver::DEFAULT_LOCALE)['Countries'];
94  $locales = \ResourceBundle::getLocales('') ?: [];
95  $list = [];
96  foreach ($locales as $locale) {
97  if (!in_array($locale, $this->allowedLocales)) {
98  continue;
99  }
100  $language = \Locale::getPrimaryLanguage($locale);
101  $country = \Locale::getRegion($locale);
102  if (!$languages[$language] || !$countries[$country]) {
103  continue;
104  }
105  $list[$locale] = $languages[$language] . ' (' . $countries[$country] . ')';
106  }
107  asort($list);
108  return $list;
109  }
110 }
__construct(ConfigInterface $localeConfig)
Definition: Lists.php:34
$locales
Definition: locales.php:14
$localeConfig
Definition: locales.php:13
getTimezoneList($doSort=true)
Definition: Lists.php:46
$code
Definition: info.phtml:12