HeadersCacheContext.php 699 Bytes
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Cache\Context\HeadersCacheContext.
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

/**
 * Defines the HeadersCacheContext service, for "per header" caching.
 */
class HeadersCacheContext extends RequestStackCacheContextBase implements CalculatedCacheContextInterface {

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

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

}