vendor/coreshop/core-shop/src/CoreShop/Bundle/StoreBundle/Context/Debug/DebugStorePersister.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * CoreShop
  5.  *
  6.  * This source file is available under two different licenses:
  7.  *  - GNU General Public License version 3 (GPLv3)
  8.  *  - CoreShop Commercial License (CCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) CoreShop GmbH (https://www.coreshop.org)
  13.  * @license    https://www.coreshop.org/license     GPLv3 and CCL
  14.  *
  15.  */
  16. namespace CoreShop\Bundle\StoreBundle\Context\Debug;
  17. use Symfony\Component\HttpFoundation\Cookie;
  18. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  19. use Symfony\Component\HttpKernel\HttpKernelInterface;
  20. final class DebugStorePersister
  21. {
  22.     public function __construct(
  23.         private DebugStoreProviderInterface $debugStoreProvider,
  24.     ) {
  25.     }
  26.     public function onKernelResponse(ResponseEvent $filterResponseEvent): void
  27.     {
  28.         if (HttpKernelInterface::SUB_REQUEST === $filterResponseEvent->getRequestType()) {
  29.             return;
  30.         }
  31.         $debugStoreCode $this->debugStoreProvider->getStoreId($filterResponseEvent->getRequest());
  32.         if (null === $debugStoreCode) {
  33.             return;
  34.         }
  35.         $response $filterResponseEvent->getResponse();
  36.         $response->headers->setCookie(new Cookie('_store_id'$debugStoreCode));
  37.     }
  38. }