QueryArgsCacheContext.php 871 Bytes
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Cache\Context\QueryArgsCacheContext.
6 7
 */

8
namespace Drupal\Core\Cache\Context;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

/**
 * Defines the QueryArgsCacheContext service, for "per query args" caching.
 *
 * A "host" is defined as the combination of URI scheme, domain name and port.
 *
 * @see Symfony\Component\HttpFoundation::getSchemeAndHttpHost()
 */
class QueryArgsCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {

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

  /**
   * {@inheritdoc}
   */
  public function getContext($query_arg = NULL) {
    if ($query_arg === NULL) {
      return $this->requestStack->getCurrentRequest()->getQueryString();
    }
    else {
      return $this->requestStack->getCurrentRequest()->query->get($query_arg);
    }
  }

}