src/EventListener/UserAutoLoginListener.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Sylius\Bundle\UserBundle\Security\UserLoginInterface;
  4. use Sylius\Component\Core\Model\CustomerInterface;
  5. use Sylius\Component\Resource\Exception\UnexpectedTypeException;
  6. use Symfony\Component\EventDispatcher\GenericEvent;
  7. use Symfony\Component\Security\Core\Exception\AccountStatusException;
  8. use function Sentry\captureException;
  9. final class UserAutoLoginListener
  10. {
  11.     /**
  12.      * @var UserLoginInterface
  13.      */
  14.     private $userLogin;
  15.     /**
  16.      * @param UserLoginInterface $userLogin
  17.      */
  18.     public function __construct(UserLoginInterface $userLogin)
  19.     {
  20.         $this->userLogin $userLogin;
  21.     }
  22.     /**
  23.      * @param GenericEvent $event
  24.      */
  25.     public function login(GenericEvent $event)
  26.     {
  27.         $customer $event->getSubject();
  28.         if (!$customer instanceof CustomerInterface) {
  29.             throw new UnexpectedTypeException(
  30.                 $customer,
  31.                 CustomerInterface::class
  32.             );
  33.         }
  34.         if (null === $user $customer->getUser()) {
  35.             return;
  36.         }
  37.         try {
  38.             $this->userLogin->login($user'shop');
  39.         } catch (\Throwable $exception) {
  40.             captureException($exception);
  41.         }
  42.     }
  43. }