vendor/sylius/sylius/src/Sylius/Component/Core/Model/ShopUser.php line 20

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\Component\Core\Model;
  12. use Sylius\Component\Customer\Model\CustomerInterface as BaseCustomerInterface;
  13. use Sylius\Component\Resource\Exception\UnexpectedTypeException;
  14. use Sylius\Component\User\Model\User as BaseUser;
  15. class ShopUser extends BaseUser implements ShopUserInterface
  16. {
  17.     /** @var BaseCustomerInterface|null */
  18.     protected $customer;
  19.     /**
  20.      * {@inheritdoc}
  21.      */
  22.     public function getCustomer(): ?BaseCustomerInterface
  23.     {
  24.         return $this->customer;
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function setCustomer(?BaseCustomerInterface $customer): void
  30.     {
  31.         if ($this->customer === $customer) {
  32.             return;
  33.         }
  34.         $previousCustomer $this->customer;
  35.         $this->customer $customer;
  36.         if ($previousCustomer instanceof CustomerInterface) {
  37.             $previousCustomer->setUser(null);
  38.         }
  39.         if ($customer instanceof CustomerInterface) {
  40.             $customer->setUser($this);
  41.         }
  42.     }
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     public function getEmail(): ?string
  47.     {
  48.         if (null === $this->customer) {
  49.             return null;
  50.         }
  51.         return $this->customer->getEmail();
  52.     }
  53.     /**
  54.      * {@inheritdoc}
  55.      */
  56.     public function setEmail(?string $email): void
  57.     {
  58.         if (null === $this->customer) {
  59.             throw new UnexpectedTypeException($this->customerBaseCustomerInterface::class);
  60.         }
  61.         $this->customer->setEmail($email);
  62.     }
  63.     /**
  64.      * {@inheritdoc}
  65.      */
  66.     public function getEmailCanonical(): ?string
  67.     {
  68.         if (null === $this->customer) {
  69.             return null;
  70.         }
  71.         return $this->customer->getEmailCanonical();
  72.     }
  73.     /**
  74.      * {@inheritdoc}
  75.      */
  76.     public function setEmailCanonical(?string $emailCanonical): void
  77.     {
  78.         if (null === $this->customer) {
  79.             throw new UnexpectedTypeException($this->customerBaseCustomerInterface::class);
  80.         }
  81.         $this->customer->setEmailCanonical($emailCanonical);
  82.     }
  83. }