src/Core/Entities/UserEntity.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Core\Entities;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\ORM\Mapping\MappedSuperclass;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Gedmo\Mapping\Annotation\Timestampable;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. // #[ORM\Entity(repositoryClass: UserRepository::class)]
  11. #[MappedSuperclass// https://www.doctrine-project.org/projects/doctrine-orm/en/2.13/reference/inheritance-mapping.html#association-override
  12. class UserEntity implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(typeTypes::INTEGER)]
  17.     #[Groups(['read'])]
  18.     private int $id;
  19.     
  20.     #[Groups(['read'])]
  21.     #[ORM\Column(typeTypes::STRINGlength255uniquetrue)]
  22.     private string $email;
  23.     #[ORM\Column(typeTypes::STRINGlength255)]
  24.     private string $password;
  25.     #[ORM\Column(typeTypes::JSON)]
  26.     protected array $roles = [];
  27.     
  28.     #[Timestampable(on'create')]
  29.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  30.     protected $createdAt;
  31.     #[Timestampable(on'update')]
  32.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  33.     protected $updatedAt;
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     /**
  39.      * Set email
  40.      *
  41.      * @param [type] $email
  42.      * @return self
  43.      */
  44.     public function setEmail($email): self
  45.     {
  46.         $this->email $email;
  47.         return $this;
  48.     }
  49.     /**
  50.      * Get email
  51.      *
  52.      * @return string|null
  53.      */
  54.     public function getEmail(): ?string
  55.     {
  56.         return $this->email;
  57.     }
  58.     /**
  59.      * {@inheritdoc}
  60.      */
  61.     public function eraseCredentials(): void
  62.     {
  63.         // if you store any temporary, sensitive data on the user, clear it here
  64.         // $this->plainPassword = null;
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      */
  69.     public function getPassword(): string
  70.     {
  71.         return (string) $this->password;
  72.     }
  73.     public function setPassword(string $password): void
  74.     {
  75.         $this->password $password;
  76.     }
  77.     /**
  78.      * @return array<int, string>
  79.      */
  80.     public function getRoles(): array
  81.     {
  82.         $roles $this->roles;
  83.         // guarantee every user at least has ROLE_USER
  84.         $roles[] = 'ROLE_USER';
  85.         return \array_unique($roles);
  86.     }
  87.     /**
  88.      * @param array<int, string> $roles
  89.      */
  90.     public function setRoles(array $roles): void
  91.     {
  92.         $this->roles $roles;
  93.     }
  94.     /**
  95.      * {@inheritdoc}
  96.      */
  97.     public function getSalt(): ?string
  98.     {
  99.         return null;
  100.     }
  101.     /**
  102.      * {@inheritdoc}
  103.      */
  104.     public function getUsername(): string
  105.     {
  106.         return (string) $this->email;
  107.     }
  108.     public function getUserIdentifier(): string
  109.     {
  110.         return (string) $this->email;
  111.     }
  112. }