class Ip2CountryCacheContext in IP-based Determination of a Visitor's Country 8
Defines the Ip2CountryCacheContext service, for "per country" caching.
Cache context ID: 'ip.country'.
Hierarchy
- class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
- class \Drupal\ip2country\Cache\Context\Ip2CountryCacheContext implements CacheContextInterface
Expanded class hierarchy of Ip2CountryCacheContext
1 string reference to 'Ip2CountryCacheContext'
1 service uses Ip2CountryCacheContext
File
- src/
Cache/ Context/ Ip2CountryCacheContext.php, line 16
Namespace
Drupal\ip2country\Cache\ContextView source
class Ip2CountryCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
/**
* The ip2country.lookup service.
*
* @var \Drupal\ip2country\Ip2CountryLookupInterface
*/
protected $ip2countryLookup;
/**
* Constructs an Ip2CountryCacheContext.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\ip2country\Ip2CountryLookupInterface $ip2countryLookup
* The ip2country.lookup service.
*/
public function __construct(RequestStack $request_stack, Ip2CountryLookupInterface $ip2countryLookup) {
parent::__construct($request_stack);
$this->ip2countryLookup = $ip2countryLookup;
}
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Country based on IP address');
}
/**
* {@inheritdoc}
*/
public function getContext() {
return $this->ip2countryLookup
->getCountry($this->requestStack
->getCurrentRequest()
->getClientIp());
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Ip2CountryCacheContext:: |
protected | property | The ip2country.lookup service. | |
Ip2CountryCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
Ip2CountryCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
Ip2CountryCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
Ip2CountryCacheContext:: |
public | function |
Constructs an Ip2CountryCacheContext. Overrides RequestStackCacheContextBase:: |
|
RequestStackCacheContextBase:: |
protected | property | The request stack. |