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

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.     public function __construct(
  21.         private RequestStack $requestStack,
  22.         private CheckoutStateUrlGeneratorInterface $checkoutStateUrlGenerator,
  23.         private RequestMatcherInterface $requestMatcher,
  24.     ) {
  25.     }
  26.     public function handleCheckoutRedirect(ResourceControllerEvent $resourceControllerEvent): void
  27.     {
  28.         $request $this->requestStack->getCurrentRequest();
  29.         if (!$this->requestMatcher->matches($request) || isset($request->attributes->get('_sylius')['redirect'])) {
  30.             return;
  31.         }
  32.         $order $resourceControllerEvent->getSubject();
  33.         Assert::isInstanceOf($orderOrderInterface::class);
  34.         $resourceControllerEvent->setResponse(new RedirectResponse($this->checkoutStateUrlGenerator->generateForOrderCheckoutState($order)));
  35.     }
  36. }