class CurrentCountry in Price 8
Same name and namespace in other branches
- 3.x src/CurrentCountry.php \Drupal\price\CurrentCountry
- 2.0.x src/CurrentCountry.php \Drupal\price\CurrentCountry
- 2.x src/CurrentCountry.php \Drupal\price\CurrentCountry
- 3.0.x src/CurrentCountry.php \Drupal\price\CurrentCountry
Holds a reference to the current country, resolved on demand.
The ChainCountryResolver runs the registered country resolvers one by one until one of them returns the country. The DefaultCountryResolver runs last, and will select the site's default country. Custom resolvers can choose based on the user profile, GeoIP, etc.
Hierarchy
- class \Drupal\price\CurrentCountry implements CurrentCountryInterface
Expanded class hierarchy of CurrentCountry
See also
\Drupal\price\Resolver\ChainCountryResolver
\Drupal\price\Resolver\DefaultCountryResolver
1 file declares its use of CurrentCountry
- CountryCacheContext.php in src/
Cache/ Context/ CountryCacheContext.php
1 string reference to 'CurrentCountry'
1 service uses CurrentCountry
File
- src/
CurrentCountry.php, line 19
Namespace
Drupal\priceView source
class CurrentCountry implements CurrentCountryInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The chain resolver.
*
* @var \Drupal\price\Resolver\ChainCountryResolverInterface
*/
protected $chainResolver;
/**
* Static cache of resolved countries. One per request.
*
* @var \SplObjectStorage
*/
protected $countries;
/**
* Constructs a new CurrentCountry object.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\price\Resolver\ChainCountryResolverInterface $chain_resolver
* The chain resolver.
*/
public function __construct(RequestStack $request_stack, ChainCountryResolverInterface $chain_resolver) {
$this->requestStack = $request_stack;
$this->chainResolver = $chain_resolver;
$this->countries = new \SplObjectStorage();
}
/**
* {@inheritdoc}
*/
public function getCountry() {
$request = $this->requestStack
->getCurrentRequest();
if (!$this->countries
->contains($request)) {
$this->countries[$request] = $this->chainResolver
->resolve();
}
return $this->countries[$request];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentCountry:: |
protected | property | The chain resolver. | |
CurrentCountry:: |
protected | property | Static cache of resolved countries. One per request. | |
CurrentCountry:: |
protected | property | The request stack. | |
CurrentCountry:: |
public | function |
Gets the country for the current request. Overrides CurrentCountryInterface:: |
|
CurrentCountry:: |
public | function | Constructs a new CurrentCountry object. |