trait CacheableResponseTrait in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Cache/CacheableResponseTrait.php \Drupal\Core\Cache\CacheableResponseTrait
Provides an implementation of CacheableResponseInterface.
Hierarchy
- trait \Drupal\Core\Cache\CacheableResponseTrait
See also
\Drupal\Core\Cache\CacheableResponseInterface
6 files declare their use of CacheableResponseTrait
- CacheableSecuredRedirectResponse.php in core/
lib/ Drupal/ Core/ Routing/ CacheableSecuredRedirectResponse.php - CacheableTestResponse.php in core/
modules/ system/ tests/ modules/ early_rendering_controller_test/ src/ CacheableTestResponse.php - HtmlResponse.php in core/
lib/ Drupal/ Core/ Render/ HtmlResponse.php - ResourceResponse.php in core/
modules/ jsonapi/ src/ ResourceResponse.php - ResourceResponse.php in core/
modules/ rest/ src/ ResourceResponse.php
File
- core/
lib/ Drupal/ Core/ Cache/ CacheableResponseTrait.php, line 10
Namespace
Drupal\Core\CacheView source
trait CacheableResponseTrait {
/**
* The cacheability metadata.
*
* @var \Drupal\Core\Cache\CacheableMetadata
*/
protected $cacheabilityMetadata;
/**
* {@inheritdoc}
*/
public function addCacheableDependency($dependency) {
// A trait doesn't have a constructor, so initialize the cacheability
// metadata if that hasn't happened yet.
if (!isset($this->cacheabilityMetadata)) {
$this->cacheabilityMetadata = new CacheableMetadata();
}
$this->cacheabilityMetadata = $this->cacheabilityMetadata
->merge(CacheableMetadata::createFromObject($dependency));
return $this;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
// A trait doesn't have a constructor, so initialize the cacheability
// metadata if that hasn't happened yet.
if (!isset($this->cacheabilityMetadata)) {
$this->cacheabilityMetadata = new CacheableMetadata();
}
return $this->cacheabilityMetadata;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableResponseTrait:: |
protected | property | The cacheability metadata. | |
CacheableResponseTrait:: |
public | function | ||
CacheableResponseTrait:: |
public | function |