class ExceptionStatusCodeCacheContext

Same name and namespace in other branches
  1. main core/lib/Drupal/Core/Cache/Context/ExceptionStatusCodeCacheContext.php \Drupal\Core\Cache\Context\ExceptionStatusCodeCacheContext

Defines the ExceptionStatusCodeCacheContext service.

Cache context ID: 'exception_status_code'.

Hierarchy

Expanded class hierarchy of ExceptionStatusCodeCacheContext

1 file declares its use of ExceptionStatusCodeCacheContext
ExceptionStatusCodeCacheContextTest.php in core/tests/Drupal/Tests/Core/Cache/Context/ExceptionStatusCodeCacheContextTest.php
1 string reference to 'ExceptionStatusCodeCacheContext'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ExceptionStatusCodeCacheContext
cache_context.exception_status_code in core/core.services.yml
Drupal\Core\Cache\Context\ExceptionStatusCodeCacheContext

File

core/lib/Drupal/Core/Cache/Context/ExceptionStatusCodeCacheContext.php, line 15

Namespace

Drupal\Core\Cache\Context
View source
class ExceptionStatusCodeCacheContext extends RequestStackCacheContextBase {
  
  /**
   * {@inheritdoc}
   */
  public static function getLabel() : \Stringable {
    return t('Exception status code');
  }
  
  /**
   * {@inheritdoc}
   */
  public function getContext() : string {
    $exception = $this->requestStack
      ->getCurrentRequest()->attributes
      ->get('exception');
    if ($exception instanceof HttpExceptionInterface) {
      return (string) $exception->getStatusCode();
    }
    // If there's no exception status code, usually a 200, return '0' because we
    // don't know what might be set by response subscribers.
    return '0';
  }
  
  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() : CacheableMetadata {
    return new CacheableMetadata();
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.