src/EventListener/ConfigListener.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XCart\EventListener;
  7. use Symfony\Component\HttpKernel\Event\RequestEvent;
  8. use XCart\Domain\StaticConfigDomain;
  9. final class ConfigListener
  10. {
  11.     private StaticConfigDomain $staticConfigDomain;
  12.     public function __construct(StaticConfigDomain $staticConfigDomain)
  13.     {
  14.         $this->staticConfigDomain $staticConfigDomain;
  15.     }
  16.     public function onKernelRequest(RequestEvent $event): void
  17.     {
  18.         $config $this->staticConfigDomain->getConfig();
  19.         if (
  20.             ($domains $config['host_details']['domains'] ?? [])
  21.             && ($httpHost $event->getRequest()->server->get('HTTP_HOST'))
  22.         ) {
  23.             foreach (['http_host''https_host'] as $host) {
  24.                 if (
  25.                     ($config['host_details'][$host] ?? null) !== $httpHost
  26.                     && in_array($httpHost$domainstrue)
  27.                 ) {
  28.                     $config['host_details'][$host] = $httpHost;
  29.                 }
  30.             }
  31.             $this->staticConfigDomain->setConfig($config);
  32.         }
  33.     }
  34. }