class ExceptionStatusCodeCacheContext
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Cache/Context/ExceptionStatusCodeCacheContext.php \Drupal\Core\Cache\Context\ExceptionStatusCodeCacheContext
Defines the ExceptionStatusCodeCacheContext service.
Cache context ID: 'exception_status_code'.
Hierarchy
- class \Drupal\Core\Cache\Context\RequestStackCacheContextBase
- class \Drupal\Core\Cache\Context\ExceptionStatusCodeCacheContext extends \Drupal\Core\Cache\Context\RequestStackCacheContextBase
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
File
-
core/
lib/ Drupal/ Core/ Cache/ Context/ ExceptionStatusCodeCacheContext.php, line 15
Namespace
Drupal\Core\Cache\ContextView 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.