vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/EventListener/OrderCustomerIpListener.php line 28

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\ShopBundle\EventListener;
  12. use Sylius\Bundle\CoreBundle\Assigner\IpAssignerInterface;
  13. use Sylius\Component\Core\Model\OrderInterface;
  14. use Symfony\Component\EventDispatcher\GenericEvent;
  15. use Symfony\Component\HttpFoundation\RequestStack;
  16. use Webmozart\Assert\Assert;
  17. final class OrderCustomerIpListener
  18. {
  19.     public function __construct(private IpAssignerInterface $ipAssigner, private RequestStack $requestStack)
  20.     {
  21.     }
  22.     public function assignCustomerIpToOrder(GenericEvent $event): void
  23.     {
  24.         $subject $event->getSubject();
  25.         Assert::isInstanceOf($subjectOrderInterface::class);
  26.         if (method_exists($this->requestStack'getMainRequest')) {
  27.             $request $this->requestStack->getMainRequest();
  28.         } else {
  29.             $request $this->requestStack->getMasterRequest();
  30.         }
  31.         Assert::notNull($request);
  32.         $this->ipAssigner->assign($subject$request);
  33.     }
  34. }