src/Sylius/Bundle/ChannelBundle/Context/FakeChannel/FakeChannelPersister.php line 30

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\FilterResponseEvent;
  14. use Symfony\Component\HttpKernel\HttpKernelInterface;
  15. final class FakeChannelPersister
  16. {
  17.     /** @var FakeChannelCodeProviderInterface */
  18.     private $fakeChannelCodeProvider;
  19.     public function __construct(FakeChannelCodeProviderInterface $fakeChannelCodeProvider)
  20.     {
  21.         $this->fakeChannelCodeProvider $fakeChannelCodeProvider;
  22.     }
  23.     public function onKernelResponse(FilterResponseEvent $filterResponseEvent): void
  24.     {
  25.         if (HttpKernelInterface::SUB_REQUEST === $filterResponseEvent->getRequestType()) {
  26.             return;
  27.         }
  28.         $fakeChannelCode $this->fakeChannelCodeProvider->getCode($filterResponseEvent->getRequest());
  29.         if (null === $fakeChannelCode) {
  30.             return;
  31.         }
  32.         $response $filterResponseEvent->getResponse();
  33.         $response->headers->setCookie(new Cookie('_channel_code'$fakeChannelCode));
  34.     }
  35. }