src/Entity/User.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. #[ORM\Entity(repositoryClassUserRepository::class)]
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length180uniquetrue)]
  17.     private ?string $email null;
  18.     #[ORM\Column]
  19.     private array $roles = [];
  20.     /**
  21.      * @var string The hashed password
  22.      */
  23.     #[ORM\Column]
  24.     private ?string $password null;
  25.     #[ORM\OneToMany(mappedBy'user'targetEntityPasswordRecovery::class, orphanRemovaltrue)]
  26.     private Collection $passwordRecoveries;
  27.     public function __construct()
  28.     {
  29.         $this->passwordRecoveries = new ArrayCollection();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getEmail(): ?string
  36.     {
  37.         return $this->email;
  38.     }
  39.     public function setEmail(string $email): static
  40.     {
  41.         $this->email $email;
  42.         return $this;
  43.     }
  44.     /**
  45.      * A visual identifier that represents this user.
  46.      *
  47.      * @see UserInterface
  48.      */
  49.     public function getUserIdentifier(): string
  50.     {
  51.         return (string) $this->email;
  52.     }
  53.     /**
  54.      * @see UserInterface
  55.      */
  56.     public function getRoles(): array
  57.     {
  58.         $roles $this->roles;
  59.         // guarantee every user at least has ROLE_USER
  60.         $roles[] = 'ROLE_USER';
  61.         return array_unique($roles);
  62.     }
  63.     public function setRoles(array $roles): static
  64.     {
  65.         $this->roles $roles;
  66.         return $this;
  67.     }
  68.     /**
  69.      * @see PasswordAuthenticatedUserInterface
  70.      */
  71.     public function getPassword(): string
  72.     {
  73.         return $this->password;
  74.     }
  75.     public function setPassword(string $password): static
  76.     {
  77.         $this->password $password;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @see UserInterface
  82.      */
  83.     public function eraseCredentials(): void
  84.     {
  85.         // If you store any temporary, sensitive data on the user, clear it here
  86.         // $this->plainPassword = null;
  87.     }
  88.     /**
  89.      * @return Collection<int, PasswordRecovery>
  90.      */
  91.     public function getPasswordRecoveries(): Collection
  92.     {
  93.         return $this->passwordRecoveries;
  94.     }
  95.     public function addPasswordRecovery(PasswordRecovery $passwordRecovery): static
  96.     {
  97.         if (!$this->passwordRecoveries->contains($passwordRecovery)) {
  98.             $this->passwordRecoveries->add($passwordRecovery);
  99.             $passwordRecovery->setUser($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removePasswordRecovery(PasswordRecovery $passwordRecovery): static
  104.     {
  105.         if ($this->passwordRecoveries->removeElement($passwordRecovery)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($passwordRecovery->getUser() === $this) {
  108.                 $passwordRecovery->setUser(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113. }