src/Sylius/Bundle/CoreBundle/Checkout/CheckoutRedirectListener.php line 44

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