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

  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.     public function add(string|array $tags): void
  15.     {
  16.         foreach (array_keys($this->keys) as $trace) {
  17.             if (\is_string($tags)) {
  18.                 $this->traces[$trace][$tags] = true;
  19.             }
  20.             if (\is_array($tags)) {
  21.                 foreach ($tags as $tag) {
  22.                     $this->traces[$trace][$tag] = true;
  23.                 }
  24.             }
  25.         }
  26.     }
  27.     /**
  28.      * @return mixed|null All kind of data could be cached
  29.      */
  30.     public function trace(string $key\Closure $param)
  31.     {
  32.         $this->traces[$key] = [];
  33.         $this->keys[$key] = true;
  34.         $result $param();
  35.         unset($this->keys[$key]);
  36.         return $result;
  37.     }
  38.     public function getTrace(string $key): array
  39.     {
  40.         $trace = isset($this->traces[$key]) ? array_keys($this->traces[$key]) : [];
  41.         unset($this->traces[$key]);
  42.         return $trace;
  43.     }
  44. }