class CurrentLocale in Price 8
Same name and namespace in other branches
- 3.x src/CurrentLocale.php \Drupal\price\CurrentLocale
- 2.0.x src/CurrentLocale.php \Drupal\price\CurrentLocale
- 2.x src/CurrentLocale.php \Drupal\price\CurrentLocale
- 3.0.x src/CurrentLocale.php \Drupal\price\CurrentLocale
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\price\CurrentLocale implements CurrentLocaleInterface
Expanded class hierarchy of CurrentLocale
See also
\Drupal\price\Resolver\ChainLocaleResolver
\Drupal\price\Resolver\DefaultLocaleResolver
1 string reference to 'CurrentLocale'
1 service uses CurrentLocale
File
- src/
CurrentLocale.php, line 19
Namespace
Drupal\priceView source
class CurrentLocale implements CurrentLocaleInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The chain resolver.
*
* @var \Drupal\price\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\price\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. |