vendor/shopware/core/Framework/Adapter/Cache/CacheTagCollection.php line 46

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Adapter\Cache;
  3. /**
  4.  * @package core
  5.  */
  6. class CacheTagCollection
  7. {
  8.     private array $keys = ['all' => true];
  9.     private array $traces = [];
  10.     public function reset(): void
  11.     {
  12.         $this->traces = [];
  13.         $this->keys = ['all' => true];
  14.     }
  15.     /**
  16.      * @param string|array $tags
  17.      */
  18.     public function add($tags): void
  19.     {
  20.         foreach (array_keys($this->keys) as $trace) {
  21.             if (\is_string($tags)) {
  22.                 $this->traces[$trace][$tags] = true;
  23.             }
  24.             if (\is_array($tags)) {
  25.                 foreach ($tags as $tag) {
  26.                     $this->traces[$trace][$tag] = true;
  27.                 }
  28.             }
  29.         }
  30.     }
  31.     /**
  32.      * @return mixed|null All kind of data could be cached
  33.      */
  34.     public function trace(string $key\Closure $param)
  35.     {
  36.         $this->traces[$key] = [];
  37.         $this->keys[$key] = true;
  38.         $result $param();
  39.         unset($this->keys[$key]);
  40.         return $result;
  41.     }
  42.     public function getTrace(string $key): array
  43.     {
  44.         $trace = isset($this->traces[$key]) ? array_keys($this->traces[$key]) : [];
  45.         unset($this->traces[$key]);
  46.         return $trace;
  47.     }
  48. }