Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Cache / CacheableResponseTrait.php
1 <?php
2
3 namespace Drupal\Core\Cache;
4
5 /**
6  * Provides an implementation of CacheableResponseInterface.
7  *
8  * @see \Drupal\Core\Cache\CacheableResponseInterface
9  */
10 trait CacheableResponseTrait {
11
12   /**
13    * The cacheability metadata.
14    *
15    * @var \Drupal\Core\Cache\CacheableMetadata
16    */
17   protected $cacheabilityMetadata;
18
19   /**
20    * {@inheritdoc}
21    */
22   public function addCacheableDependency($dependency) {
23     // A trait doesn't have a constructor, so initialize the cacheability
24     // metadata if that hasn't happened yet.
25     if (!isset($this->cacheabilityMetadata)) {
26       $this->cacheabilityMetadata = new CacheableMetadata();
27     }
28
29     $this->cacheabilityMetadata = $this->cacheabilityMetadata->merge(CacheableMetadata::createFromObject($dependency));
30
31     return $this;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function getCacheableMetadata() {
38     // A trait doesn't have a constructor, so initialize the cacheability
39     // metadata if that hasn't happened yet.
40     if (!isset($this->cacheabilityMetadata)) {
41       $this->cacheabilityMetadata = new CacheableMetadata();
42     }
43
44     return $this->cacheabilityMetadata;
45   }
46
47 }