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

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. public function __construct(private FakeChannelCodeProviderInterface $fakeChannelCodeProvider)
  18. {
  19. }
  20. public function onKernelResponse(ResponseEvent $filterResponseEvent): void
  21. {
  22. if (HttpKernelInterface::SUB_REQUEST === $filterResponseEvent->getRequestType()) {
  23. return;
  24. }
  25. $fakeChannelCode = $this->fakeChannelCodeProvider->getCode($filterResponseEvent->getRequest());
  26. if (null === $fakeChannelCode) {
  27. return;
  28. }
  29. $response = $filterResponseEvent->getResponse();
  30. $response->headers->setCookie(new Cookie('_channel_code', $fakeChannelCode));
  31. }
  32. }