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

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