Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Resolver Class Reference
Inheritance diagram for Resolver:
ResolverInterface Resolver

Public Member Functions

 __construct (ScopeConfigInterface $scopeConfig, $defaultLocalePath, $scopeType, $locale=null)
 
 getDefaultLocalePath ()
 
 setDefaultLocale ($locale)
 
 getDefaultLocale ()
 
 setLocale ($locale=null)
 
 getLocale ()
 
 emulate ($scopeId)
 
 revert ()
 

Data Fields

const DEFAULT_LOCALE = 'en_US'
 

Protected Attributes

 $defaultLocale
 
 $scopeType
 
 $locale
 
 $scopeConfig
 
 $emulatedLocales = []
 

Detailed Description

Definition at line 10 of file Resolver.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ScopeConfigInterface  $scopeConfig,
  $defaultLocalePath,
  $scopeType,
  $locale = null 
)
Parameters
ScopeConfigInterface$scopeConfig
string$defaultLocalePath
string$scopeType
mixed$locale

Definition at line 61 of file Resolver.php.

66  {
67  $this->scopeConfig = $scopeConfig;
68  $this->defaultLocalePath = $defaultLocalePath;
69  $this->scopeType = $scopeType;
70  $this->setLocale($locale);
71  }

Member Function Documentation

◆ emulate()

emulate (   $scopeId)

{Push current locale to stack and replace with locale from specified scope

Parameters
int$scopeId
Returns
string|null
}

Implements ResolverInterface.

Definition at line 132 of file Resolver.php.

133  {
134  $result = null;
135  if ($scopeId) {
136  $this->emulatedLocales[] = $this->getLocale();
137  $this->locale = $this->scopeConfig->getValue(
138  $this->getDefaultLocalePath(),
139  $this->scopeType,
140  $scopeId
141  );
143  } else {
144  $this->emulatedLocales[] = false;
145  }
146  return $result;
147  }

◆ getDefaultLocale()

getDefaultLocale ( )

{Retrieve default locale code

Returns
string
}

Implements ResolverInterface.

Definition at line 93 of file Resolver.php.

94  {
95  if (!$this->defaultLocale) {
96  $locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
97  if (!$locale) {
99  }
100  $this->defaultLocale = $locale;
101  }
102  return $this->defaultLocale;
103  }

◆ getDefaultLocalePath()

getDefaultLocalePath ( )

{Return path to default locale

Returns
string
}

Implements ResolverInterface.

Definition at line 76 of file Resolver.php.

77  {
78  return $this->defaultLocalePath;
79  }

◆ getLocale()

getLocale ( )

{Retrieve locale

Returns
string
}

Implements ResolverInterface.

Definition at line 121 of file Resolver.php.

122  {
123  if ($this->locale === null) {
124  $this->setLocale();
125  }
126  return $this->locale;
127  }

◆ revert()

revert ( )

{Get last locale, used before last emulation

Returns
string|null
}

Implements ResolverInterface.

Definition at line 152 of file Resolver.php.

153  {
154  $result = null;
155  $localeCode = array_pop($this->emulatedLocales);
156  if ($localeCode) {
157  $this->locale = $localeCode;
159  }
160  return $result;
161  }

◆ setDefaultLocale()

setDefaultLocale (   $locale)

{Set default locale code

Parameters
string$locale
Returns
self
}

Implements ResolverInterface.

Definition at line 84 of file Resolver.php.

85  {
86  $this->defaultLocale = $locale;
87  return $this;
88  }

◆ setLocale()

setLocale (   $locale = null)

{Set locale

Parameters
string$locale
Returns
self
}

Implements ResolverInterface.

Definition at line 108 of file Resolver.php.

109  {
110  if ($locale !== null && is_string($locale)) {
111  $this->locale = $locale;
112  } else {
113  $this->locale = $this->getDefaultLocale();
114  }
115  return $this;
116  }

Field Documentation

◆ $defaultLocale

$defaultLocale
protected

Definition at line 22 of file Resolver.php.

◆ $emulatedLocales

$emulatedLocales = []
protected

Definition at line 48 of file Resolver.php.

◆ $locale

$locale
protected

Definition at line 36 of file Resolver.php.

◆ $scopeConfig

$scopeConfig
protected

Definition at line 41 of file Resolver.php.

◆ $scopeType

$scopeType
protected

Definition at line 29 of file Resolver.php.

◆ DEFAULT_LOCALE

const DEFAULT_LOCALE = 'en_US'

Default locale

Definition at line 15 of file Resolver.php.


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