Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Cache / CacheTagsInvalidator.php
1 <?php
2
3 namespace Drupal\Core\Cache;
4
5 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
6
7 /**
8  * Passes cache tag events to classes that wish to respond to them.
9  */
10 class CacheTagsInvalidator implements CacheTagsInvalidatorInterface {
11
12   use ContainerAwareTrait;
13
14   /**
15    * Holds an array of cache tags invalidators.
16    *
17    * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface[]
18    */
19   protected $invalidators = [];
20
21   /**
22    * {@inheritdoc}
23    */
24   public function invalidateTags(array $tags) {
25     assert('Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache tags must be strings.');
26
27     // Notify all added cache tags invalidators.
28     foreach ($this->invalidators as $invalidator) {
29       $invalidator->invalidateTags($tags);
30     }
31
32     // Additionally, notify each cache bin if it implements the service.
33     foreach ($this->getInvalidatorCacheBins() as $bin) {
34       $bin->invalidateTags($tags);
35     }
36   }
37
38   /**
39    * Reset statically cached tags in all cache tag checksum services.
40    *
41    * This is only used by tests.
42    */
43   public function resetChecksums() {
44     foreach ($this->invalidators as $invalidator) {
45       if ($invalidator instanceof CacheTagsChecksumInterface) {
46         $invalidator->reset();
47       }
48     }
49   }
50
51   /**
52    * Adds a cache tags invalidator.
53    *
54    * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $invalidator
55    *   A cache invalidator.
56    */
57   public function addInvalidator(CacheTagsInvalidatorInterface $invalidator) {
58     $this->invalidators[] = $invalidator;
59   }
60
61   /**
62    * Returns all cache bins that need to be notified about invalidations.
63    *
64    * @return \Drupal\Core\Cache\CacheTagsInvalidatorInterface[]
65    *   An array of cache backend objects that implement the invalidator
66    *   interface, keyed by their cache bin.
67    */
68   protected function getInvalidatorCacheBins() {
69     $bins = [];
70     foreach ($this->container->getParameter('cache_bins') as $service_id => $bin) {
71       $service = $this->container->get($service_id);
72       if ($service instanceof CacheTagsInvalidatorInterface) {
73         $bins[$bin] = $service;
74       }
75     }
76     return $bins;
77   }
78
79 }