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.     public function getCustomer(): ?BaseCustomerInterface
  20.     {
  21.         return $this->customer;
  22.     }
  23.     public function setCustomer(?BaseCustomerInterface $customer): void
  24.     {
  25.         if ($this->customer === $customer) {
  26.             return;
  27.         }
  28.         $previousCustomer $this->customer;
  29.         $this->customer $customer;
  30.         if ($previousCustomer instanceof CustomerInterface) {
  31.             $previousCustomer->setUser(null);
  32.         }
  33.         if ($customer instanceof CustomerInterface) {
  34.             $customer->setUser($this);
  35.         }
  36.     }
  37.     public function getEmail(): ?string
  38.     {
  39.         if (null === $this->customer) {
  40.             return null;
  41.         }
  42.         return $this->customer->getEmail();
  43.     }
  44.     public function setEmail(?string $email): void
  45.     {
  46.         if (null === $this->customer) {
  47.             throw new UnexpectedTypeException($this->customerBaseCustomerInterface::class);
  48.         }
  49.         $this->customer->setEmail($email);
  50.     }
  51.     public function getEmailCanonical(): ?string
  52.     {
  53.         if (null === $this->customer) {
  54.             return null;
  55.         }
  56.         return $this->customer->getEmailCanonical();
  57.     }
  58.     public function setEmailCanonical(?string $emailCanonical): void
  59.     {
  60.         if (null === $this->customer) {
  61.             throw new UnexpectedTypeException($this->customerBaseCustomerInterface::class);
  62.         }
  63.         $this->customer->setEmailCanonical($emailCanonical);
  64.     }
  65. }