vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/Checkout/CheckoutRedirectListener.php line 41

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\CoreBundle\Checkout;
  12. use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
  13. use Sylius\Component\Core\Model\OrderInterface;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\HttpFoundation\RequestMatcherInterface;
  16. use Symfony\Component\HttpFoundation\RequestStack;
  17. use Webmozart\Assert\Assert;
  18. final class CheckoutRedirectListener
  19. {
  20.     private RequestStack $requestStack;
  21.     private CheckoutStateUrlGeneratorInterface $checkoutStateUrlGenerator;
  22.     private RequestMatcherInterface $requestMatcher;
  23.     public function __construct(
  24.         RequestStack $requestStack,
  25.         CheckoutStateUrlGeneratorInterface $checkoutStateUrlGenerator,
  26.         RequestMatcherInterface $requestMatcher
  27.     ) {
  28.         $this->requestStack $requestStack;
  29.         $this->checkoutStateUrlGenerator $checkoutStateUrlGenerator;
  30.         $this->requestMatcher $requestMatcher;
  31.     }
  32.     public function handleCheckoutRedirect(ResourceControllerEvent $resourceControllerEvent): void
  33.     {
  34.         $request $this->requestStack->getCurrentRequest();
  35.         if (!$this->requestMatcher->matches($request) || isset($request->attributes->get('_sylius')['redirect'])) {
  36.             return;
  37.         }
  38.         $order $resourceControllerEvent->getSubject();
  39.         Assert::isInstanceOf($orderOrderInterface::class);
  40.         $resourceControllerEvent->setResponse(new RedirectResponse($this->checkoutStateUrlGenerator->generateForOrderCheckoutState($order)));
  41.     }
  42. }