Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Lists Class Reference

Public Member Functions

 __construct (ConfigInterface $localeConfig)
 
 getTimezoneList ($doSort=true)
 
 getCurrencyList ()
 
 getLocaleList ()
 

Protected Attributes

 $allowedLocales
 

Detailed Description

Definition at line 15 of file Lists.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ConfigInterface  $localeConfig)
Parameters
ConfigInterface$localeConfig

Definition at line 34 of file Lists.php.

35  {
36  $this->allowedLocales = $localeConfig->getAllowedLocales();
37  $this->allowedCurrencies = $localeConfig->getAllowedCurrencies();
38  }
$localeConfig
Definition: locales.php:13

Member Function Documentation

◆ getCurrencyList()

getCurrencyList ( )

Retrieve list of currencies

Returns
array

Definition at line 70 of file Lists.php.

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  }
$code
Definition: info.phtml:12

◆ getLocaleList()

getLocaleList ( )

Retrieve list of locales

Returns
array

Definition at line 90 of file Lists.php.

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  }
$locales
Definition: locales.php:14

◆ getTimezoneList()

getTimezoneList (   $doSort = true)

Retrieve list of timezones

Parameters
bool$doSort
Returns
array

Definition at line 46 of file Lists.php.

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  }
$code
Definition: info.phtml:12

Field Documentation

◆ $allowedLocales

$allowedLocales
protected

Definition at line 22 of file Lists.php.


The documentation for this class was generated from the following file: