You are here

class CountryCacheContext in Commerce Core 8.2

Defines the country cache context, for "per country" caching.

Cache context ID: 'country'.

Hierarchy

Expanded class hierarchy of CountryCacheContext

1 string reference to 'CountryCacheContext'
commerce.services.yml in ./commerce.services.yml
commerce.services.yml
1 service uses CountryCacheContext
cache_context.country in ./commerce.services.yml
Drupal\commerce\Cache\Context\CountryCacheContext

File

src/Cache/Context/CountryCacheContext.php, line 14

Namespace

Drupal\commerce\Cache\Context
View source
class CountryCacheContext implements CacheContextInterface {

  /**
   * The current country.
   *
   * @var \Drupal\commerce\CurrentCountry
   */
  protected $currentCountry;

  /**
   * Constructs a new CountryCacheContext object.
   *
   * @param \Drupal\commerce\CurrentCountry $country
   *   The current country.
   */
  public function __construct(CurrentCountry $country) {
    $this->currentCountry = $country;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Country');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return $this->currentCountry
      ->getCountry()
      ->getCountryCode();
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CountryCacheContext::$currentCountry protected property The current country.
CountryCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
CountryCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
CountryCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
CountryCacheContext::__construct public function Constructs a new CountryCacheContext object.