src/Entity/User/AppUser.php line 24

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  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 App\Entity\User;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Monofony\Contracts\Core\Model\User\AppUserInterface;
  14. use Sylius\Component\Customer\Model\CustomerInterface;
  15. use Sylius\Component\Resource\Exception\UnexpectedTypeException;
  16. use Sylius\Component\User\Model\User as BaseUser;
  17. #[ORM\Entity]
  18. #[ORM\Table(name'sylius_app_user')]
  19. class AppUser extends BaseUser implements AppUserInterface
  20. {
  21.     #[ORM\OneToOne(inversedBy'user'targetEntityCustomerInterface::class, cascade: ['persist'])]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private ?CustomerInterface $customer null;
  24.     public function getCustomer(): ?CustomerInterface
  25.     {
  26.         return $this->customer;
  27.     }
  28.     public function setCustomer($customer): void
  29.     {
  30.         $this->customer $customer;
  31.     }
  32.     public function getEmail(): ?string
  33.     {
  34.         if (null === $this->customer) {
  35.             return null;
  36.         }
  37.         return $this->customer->getEmail();
  38.     }
  39.     public function setEmail(?string $email): void
  40.     {
  41.         if (null === $this->customer) {
  42.             throw new UnexpectedTypeException($this->customerCustomerInterface::class);
  43.         }
  44.         $this->customer->setEmail($email);
  45.     }
  46.     public function getEmailCanonical(): ?string
  47.     {
  48.         if (null === $this->customer) {
  49.             return null;
  50.         }
  51.         return $this->customer->getEmailCanonical();
  52.     }
  53.     public function setEmailCanonical(?string $emailCanonical): void
  54.     {
  55.         if (null === $this->customer) {
  56.             throw new UnexpectedTypeException($this->customerCustomerInterface::class);
  57.         }
  58.         $this->customer->setEmailCanonical($emailCanonical);
  59.     }
  60. }