src/Entity/User.php line 15

  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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length180uniquetrue)]
  19.     private ?string $email null;
  20.     #[ORM\Column]
  21.     private array $roles = [];
  22.     /**
  23.      * @var string The hashed password
  24.      */
  25.     #[ORM\Column]
  26.     private ?string $password null;
  27.     #[ORM\OneToMany(mappedBy'user'targetEntityApropos::class)]
  28.     private Collection $apropos;
  29.     public function __construct()
  30.     {
  31.         $this->apropos = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getEmail(): ?string
  38.     {
  39.         return $this->email;
  40.     }
  41.     public function setEmail(string $email): self
  42.     {
  43.         $this->email $email;
  44.         return $this;
  45.     }
  46.     /**
  47.      * A visual identifier that represents this user.
  48.      *
  49.      * @see UserInterface
  50.      */
  51.     public function getUserIdentifier(): string
  52.     {
  53.         return (string) $this->email;
  54.     }
  55.     /**
  56.      * @see UserInterface
  57.      */
  58.     public function getRoles(): array
  59.     {
  60.         $roles $this->roles;
  61.         // guarantee every user at least has ROLE_USER
  62.         $roles[] = 'ROLE_USER';
  63.         return array_unique($roles);
  64.     }
  65.     public function setRoles(array $roles): self
  66.     {
  67.         $this->roles $roles;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @see PasswordAuthenticatedUserInterface
  72.      */
  73.     public function getPassword(): string
  74.     {
  75.         return $this->password;
  76.     }
  77.     public function setPassword(string $password): self
  78.     {
  79.         $this->password $password;
  80.         return $this;
  81.     }
  82.     /**
  83.      * @see UserInterface
  84.      */
  85.     public function eraseCredentials()
  86.     {
  87.         // If you store any temporary, sensitive data on the user, clear it here
  88.         // $this->plainPassword = null;
  89.     }
  90.     /**
  91.      * @return Collection<int, Apropos>
  92.      */
  93.     public function getApropos(): Collection
  94.     {
  95.         return $this->apropos;
  96.     }
  97.     public function addApropo(Apropos $apropo): self
  98.     {
  99.         if (!$this->apropos->contains($apropo)) {
  100.             $this->apropos->add($apropo);
  101.             $apropo->setUser($this);
  102.         }
  103.         return $this;
  104.     }
  105.     public function removeApropo(Apropos $apropo): self
  106.     {
  107.         if ($this->apropos->removeElement($apropo)) {
  108.             // set the owning side to null (unless already changed)
  109.             if ($apropo->getUser() === $this) {
  110.                 $apropo->setUser(null);
  111.             }
  112.         }
  113.         return $this;
  114.     }
  115.     public function __toString()
  116.     {
  117.         return $this->getEmail();
  118.     }
  119. }