19cb0f2b7664705dcc8707f1ee9c4f19be57149f
[yaffs-website] / web / core / lib / Drupal / Core / Cache / CacheableDependencyTrait.php
1 <?php
2
3 namespace Drupal\Core\Cache;
4
5 /**
6  * Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
7  */
8 trait CacheableDependencyTrait {
9
10   /**
11    * Cache contexts.
12    *
13    * @var string[]
14    */
15   protected $cacheContexts = [];
16
17   /**
18    * Cache tags.
19    *
20    * @var string[]
21    */
22   protected $cacheTags = [];
23
24   /**
25    * Cache max-age.
26    *
27    * @var int
28    */
29   protected $cacheMaxAge = Cache::PERMANENT;
30
31   /**
32    * Sets cacheability; useful for value object constructors.
33    *
34    * @param \Drupal\Core\Cache\CacheableDependencyInterface $cacheability
35    *   The cacheability to set.
36    *
37    * @return $this
38    */
39   protected function setCacheability(CacheableDependencyInterface $cacheability) {
40     $this->cacheContexts = $cacheability->getCacheContexts();
41     $this->cacheTags = $cacheability->getCacheTags();
42     $this->cacheMaxAge = $cacheability->getCacheMaxAge();
43     return $this;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getCacheTags() {
50     return $this->cacheTags;
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function getCacheContexts() {
57     return $this->cacheContexts;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function getCacheMaxAge() {
64     return $this->cacheMaxAge;
65   }
66
67 }