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