Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/Cache/RefinableCacheableDependencyTrait.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children | 1fec387a4317 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Core\Cache; |
Chris@0 | 4 |
Chris@0 | 5 /** |
Chris@0 | 6 * Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface. |
Chris@0 | 7 */ |
Chris@0 | 8 trait RefinableCacheableDependencyTrait { |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * Cache contexts. |
Chris@0 | 12 * |
Chris@0 | 13 * @var string[] |
Chris@0 | 14 */ |
Chris@0 | 15 protected $cacheContexts = []; |
Chris@0 | 16 |
Chris@0 | 17 /** |
Chris@0 | 18 * Cache tags. |
Chris@0 | 19 * |
Chris@0 | 20 * @var string[] |
Chris@0 | 21 */ |
Chris@0 | 22 protected $cacheTags = []; |
Chris@0 | 23 |
Chris@0 | 24 /** |
Chris@0 | 25 * Cache max-age. |
Chris@0 | 26 * |
Chris@0 | 27 * @var int |
Chris@0 | 28 */ |
Chris@0 | 29 protected $cacheMaxAge = Cache::PERMANENT; |
Chris@0 | 30 |
Chris@0 | 31 /** |
Chris@0 | 32 * {@inheritdoc} |
Chris@0 | 33 */ |
Chris@0 | 34 public function getCacheTags() { |
Chris@0 | 35 return $this->cacheTags; |
Chris@0 | 36 } |
Chris@0 | 37 |
Chris@0 | 38 /** |
Chris@0 | 39 * {@inheritdoc} |
Chris@0 | 40 */ |
Chris@0 | 41 public function getCacheContexts() { |
Chris@0 | 42 return $this->cacheContexts; |
Chris@0 | 43 } |
Chris@0 | 44 |
Chris@0 | 45 /** |
Chris@0 | 46 * {@inheritdoc} |
Chris@0 | 47 */ |
Chris@0 | 48 public function getCacheMaxAge() { |
Chris@0 | 49 return $this->cacheMaxAge; |
Chris@0 | 50 } |
Chris@0 | 51 |
Chris@0 | 52 /** |
Chris@0 | 53 * {@inheritdoc} |
Chris@0 | 54 */ |
Chris@0 | 55 public function addCacheableDependency($other_object) { |
Chris@0 | 56 if ($other_object instanceof CacheableDependencyInterface) { |
Chris@0 | 57 $this->addCacheContexts($other_object->getCacheContexts()); |
Chris@0 | 58 $this->addCacheTags($other_object->getCacheTags()); |
Chris@0 | 59 $this->mergeCacheMaxAge($other_object->getCacheMaxAge()); |
Chris@0 | 60 } |
Chris@0 | 61 else { |
Chris@0 | 62 // Not a cacheable dependency, this can not be cached. |
Chris@0 | 63 $this->cacheMaxAge = 0; |
Chris@0 | 64 } |
Chris@0 | 65 return $this; |
Chris@0 | 66 } |
Chris@0 | 67 |
Chris@0 | 68 /** |
Chris@0 | 69 * {@inheritdoc} |
Chris@0 | 70 */ |
Chris@0 | 71 public function addCacheContexts(array $cache_contexts) { |
Chris@0 | 72 if ($cache_contexts) { |
Chris@0 | 73 $this->cacheContexts = Cache::mergeContexts($this->cacheContexts, $cache_contexts); |
Chris@0 | 74 } |
Chris@0 | 75 return $this; |
Chris@0 | 76 } |
Chris@0 | 77 |
Chris@0 | 78 /** |
Chris@0 | 79 * {@inheritdoc} |
Chris@0 | 80 */ |
Chris@0 | 81 public function addCacheTags(array $cache_tags) { |
Chris@0 | 82 if ($cache_tags) { |
Chris@0 | 83 $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags); |
Chris@0 | 84 } |
Chris@0 | 85 return $this; |
Chris@0 | 86 } |
Chris@0 | 87 |
Chris@0 | 88 /** |
Chris@0 | 89 * {@inheritdoc} |
Chris@0 | 90 */ |
Chris@0 | 91 public function mergeCacheMaxAge($max_age) { |
Chris@0 | 92 $this->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $max_age); |
Chris@0 | 93 return $this; |
Chris@0 | 94 } |
Chris@0 | 95 |
Chris@0 | 96 } |