vendor/store.shopware.com/tanmarnginfinitescrolling/src/Service/ConfigService.php line 37

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Tanmar\NgInfiniteScrolling\Service;
  4. use Shopware\Core\PlatformRequest;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Tanmar\NgInfiniteScrolling\Components\Config;
  8. class ConfigService {
  9.     /**
  10.      *
  11.      * @var SystemConfigService $systemConfigService
  12.      */
  13.     private $systemConfigService;
  14.     /**
  15.      *
  16.      * @var Config $config
  17.      */
  18.     private $config;
  19.     /**
  20.      *
  21.      * @var array $configs
  22.      */
  23.     private $configs;
  24.     /**
  25.      *
  26.      * @param SystemConfigService $systemConfigService
  27.      * @param RequestStack $requestStack
  28.      */
  29.     public function __construct(SystemConfigService $systemConfigServiceRequestStack $requestStack) {
  30.         $this->systemConfigService $systemConfigService;
  31.         $salesChannelId $this->getSalesChannelId($requestStack);
  32.         $this->configs = [];
  33.         $this->config $this->getSalesChannelConfig($salesChannelId);
  34.     }
  35.     /**
  36.      *
  37.      * @param RequestStack $requestStack
  38.      * @return string
  39.      */
  40.     private function getSalesChannelId(RequestStack $requestStack): string {
  41.         $salesChannelId $requestStack->getCurrentRequest()->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  42.         if (!is_null($salesChannelId)) {
  43.             return $salesChannelId;
  44.         }
  45.         return \Shopware\Core\Defaults::SALES_CHANNEL;
  46.     }
  47.     /**
  48.      *
  49.      * @return Config
  50.      */
  51.     public function getConfig(): Config {
  52.         return $this->config;
  53.     }
  54.     /**
  55.      *
  56.      * @param string $salesChannelId
  57.      * @return Config
  58.      */
  59.     public function getSalesChannelConfig(string $salesChannelId): Config {
  60.         if (!isset($this->configs[$salesChannelId])) {
  61.             $this->configs[$salesChannelId] = new Config($this->systemConfigService$salesChannelId);
  62.         }
  63.         return $this->configs[$salesChannelId];
  64.     }
  65. }