vendor/sylius/sylius/src/Sylius/Bundle/ChannelBundle/Context/FakeChannel/FakeChannelPersister.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ChannelBundle\Context\FakeChannel;
  12. use Symfony\Component\HttpFoundation\Cookie;
  13. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  14. use Symfony\Component\HttpKernel\HttpKernelInterface;
  15. final class FakeChannelPersister
  16. {
  17.     private FakeChannelCodeProviderInterface $fakeChannelCodeProvider;
  18.     public function __construct(FakeChannelCodeProviderInterface $fakeChannelCodeProvider)
  19.     {
  20.         $this->fakeChannelCodeProvider $fakeChannelCodeProvider;
  21.     }
  22.     public function onKernelResponse(ResponseEvent $filterResponseEvent): void
  23.     {
  24.         if (HttpKernelInterface::SUB_REQUEST === $filterResponseEvent->getRequestType()) {
  25.             return;
  26.         }
  27.         $fakeChannelCode $this->fakeChannelCodeProvider->getCode($filterResponseEvent->getRequest());
  28.         if (null === $fakeChannelCode) {
  29.             return;
  30.         }
  31.         $response $filterResponseEvent->getResponse();
  32.         $response->headers->setCookie(new Cookie('_channel_code'$fakeChannelCode));
  33.     }
  34. }