vendor/shopware/core/System/SystemConfig/Store/MemoizedSystemConfigStore.php line 28

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\System\SystemConfig\Store;
  3. use Shopware\Core\System\SystemConfig\Event\SystemConfigChangedEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Contracts\Service\ResetInterface;
  6. /**
  7.  * @internal
  8.  */
  9. final class MemoizedSystemConfigStore implements EventSubscriberInterfaceResetInterface
  10. {
  11.     /**
  12.      * @var array[]
  13.      */
  14.     private array $configs = [];
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             SystemConfigChangedEvent::class => [
  19.                 ['onValueChanged'1500],
  20.             ],
  21.         ];
  22.     }
  23.     public function onValueChanged(SystemConfigChangedEvent $event): void
  24.     {
  25.         $this->removeConfig($event->getSalesChannelId());
  26.     }
  27.     public function setConfig(?string $salesChannelId, array $config): void
  28.     {
  29.         $this->configs[$this->getKey($salesChannelId)] = $config;
  30.     }
  31.     public function getConfig(?string $salesChannelId): ?array
  32.     {
  33.         return $this->configs[$this->getKey($salesChannelId)] ?? null;
  34.     }
  35.     public function removeConfig(?string $salesChannelId): void
  36.     {
  37.         if ($salesChannelId === null) {
  38.             $this->reset();
  39.             return;
  40.         }
  41.         unset($this->configs[$this->getKey($salesChannelId)]);
  42.     }
  43.     public function reset(): void
  44.     {
  45.         $this->configs = [];
  46.     }
  47.     private function getKey(?string $salesChannelId): string
  48.     {
  49.         return $salesChannelId ?? '_global_';
  50.     }
  51. }