class CurrentLocale in Commerce Core 8.2
Holds a reference to the current locale, resolved on demand.
The ChainLocaleResolver runs the registered locale resolvers one by one until one of them returns the locale. The DefaultLocaleResolver runs last, and contains the default logic which assembles the locale based on the current language and country.
Hierarchy
- class \Drupal\commerce\CurrentLocale implements CurrentLocaleInterface
Expanded class hierarchy of CurrentLocale
See also
\Drupal\commerce\Resolver\ChainLocaleResolver
\Drupal\commerce\Resolver\DefaultLocaleResolver
1 string reference to 'CurrentLocale'
1 service uses CurrentLocale
File
- src/
CurrentLocale.php, line 19
Namespace
Drupal\commerceView source
class CurrentLocale implements CurrentLocaleInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The chain resolver.
*
* @var \Drupal\commerce\Resolver\ChainLocaleResolverInterface
*/
protected $chainResolver;
/**
* Static cache of resolved locales. One per request.
*
* @var \SplObjectStorage
*/
protected $locales;
/**
* Constructs a new CurrentLocale object.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\commerce\Resolver\ChainLocaleResolverInterface $chain_resolver
* The chain resolver.
*/
public function __construct(RequestStack $request_stack, ChainLocaleResolverInterface $chain_resolver) {
$this->requestStack = $request_stack;
$this->chainResolver = $chain_resolver;
$this->locales = new \SplObjectStorage();
}
/**
* {@inheritdoc}
*/
public function getLocale() {
$request = $this->requestStack
->getCurrentRequest();
if (!$this->locales
->contains($request)) {
$this->locales[$request] = $this->chainResolver
->resolve();
}
return $this->locales[$request];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentLocale:: |
protected | property | The chain resolver. | |
CurrentLocale:: |
protected | property | Static cache of resolved locales. One per request. | |
CurrentLocale:: |
protected | property | The request stack. | |
CurrentLocale:: |
public | function |
Gets the locale for the current request. Overrides CurrentLocaleInterface:: |
|
CurrentLocale:: |
public | function | Constructs a new CurrentLocale object. |