src/Ship/Entities/UserEntity.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Ship\Entities;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping\MappedSuperclass;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use App\Ship\Utils\FormattingUtil;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[MappedSuperclass// https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/reference/inheritance-mapping.html#association-override
  11. class UserEntity implements UserInterface
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(typeTypes::INTEGER)]
  16.     #[Groups(['read'])]
  17.     private int $id;
  18.     #[ORM\Column(typeTypes::STRINGlength255nullabletrueuniquetrue)]
  19.     #[Groups(['read'])]
  20.     private ?string $externalCode null;
  21.     #[ORM\Column(typeTypes::STRINGlength150nullablefalseuniquetrue)]
  22.     #[Groups(['read'])]
  23.     private string $phone;
  24.     #[ORM\Column(typeTypes::JSON)]
  25.     #[Groups(['read'])]
  26.     protected array $roles = [];
  27.     
  28.     #[Gedmo\Timestampable(on'create')]
  29.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  30.     protected $createdAt;
  31.     #[Gedmo\Timestampable(on'update')]
  32.     #[ORM\Column(typeTypes::DATETIME_IMMUTABLE)]
  33.     protected $updatedAt;
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getExternalCode(): ?string
  39.     {
  40.         return $this->externalCode;
  41.     }
  42.     public function setExternalCode($code)
  43.     {
  44.         $this->externalCode $code;
  45.         return $this;
  46.     }
  47.     public function setPhone($value): self
  48.     {
  49.         if (filter_var($valueFILTER_VALIDATE_EMAIL))
  50.             $this->phone $value;
  51.         else
  52.         {
  53.             $this->phone = (!empty($value))
  54.                 ? FormattingUtil::phoneNumber($value)
  55.                 : $value;
  56.         }
  57.         return $this;
  58.     }
  59.     public function getPhone(): ?string
  60.     {
  61.         return $this->phone;
  62.     }
  63.     public function eraseCredentials()
  64.     {
  65.         // If you store any temporary, sensitive data on the user, clear it here
  66.         // $this->plainPassword = null;
  67.     }
  68.     public function getSalt()
  69.     {
  70.         // not needed for apps that do not check user passwords
  71.     }
  72.     public function getRoles(): array
  73.     {
  74.         $roles $this->roles;
  75.         // guarantee every user at least has ROLE_USER
  76.         $roles[] = 'ROLE_USER';
  77.         return \array_unique($roles);
  78.     }
  79.     public function setRoles(array $roles): void
  80.     {
  81.         $this->roles $roles;
  82.     }
  83.     public function getUserIdentifier(): string
  84.     {
  85.         return $this->phone;
  86.     }
  87. }