src/Entity/User.php line 16

  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. #[ORM\Table(name'`user`')]
  12. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(length180uniquetrue)]
  20.     private ?string $email null;
  21.     #[ORM\Column]
  22.     private array $roles = [];
  23.     /**
  24.      * @var string The hashed password
  25.      */
  26.     #[ORM\Column]
  27.     private ?string $password null;
  28.     #[ORM\OneToMany(mappedBy'user'targetEntityUserProjets::class)]
  29.     private Collection $userProjets;
  30.     #[ORM\OneToMany(mappedBy'user'targetEntityCommentaires::class)]
  31.     private Collection $commentaires;
  32.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  33.     #[ORM\JoinColumn(nullablefalse)]
  34.     private ?UserInfos $userInfos null;
  35.     public function __construct()
  36.     {
  37.         $this->userProjets = new ArrayCollection();
  38.         $this->commentaires = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getEmail(): ?string
  45.     {
  46.         return $this->email;
  47.     }
  48.     public function setEmail(string $email): static
  49.     {
  50.         $this->email $email;
  51.         return $this;
  52.     }
  53.     /**
  54.      * A visual identifier that represents this user.
  55.      *
  56.      * @see UserInterface
  57.      */
  58.     public function getUserIdentifier(): string
  59.     {
  60.         return (string) $this->email;
  61.     }
  62.     /**
  63.      * @see UserInterface
  64.      */
  65.     public function getRoles(): array
  66.     {
  67.         $roles $this->roles;
  68.         // guarantee every user at least has ROLE_USER
  69.         $roles[] = 'ROLE_USER';
  70.         return array_unique($roles);
  71.     }
  72.     public function setRoles(array $roles): static
  73.     {
  74.         $this->roles $roles;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @see PasswordAuthenticatedUserInterface
  79.      */
  80.     public function getPassword(): string
  81.     {
  82.         return $this->password;
  83.     }
  84.     public function setPassword(string $password): static
  85.     {
  86.         $this->password $password;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @see UserInterface
  91.      */
  92.     public function eraseCredentials(): void
  93.     {
  94.         // If you store any temporary, sensitive data on the user, clear it here
  95.         // $this->plainPassword = null;
  96.     }
  97.     /**
  98.      * @return Collection<int, UserProjets>
  99.      */
  100.     public function getUserProjets(): Collection
  101.     {
  102.         return $this->userProjets;
  103.     }
  104.     public function addUserProjet(UserProjets $userProjet): self
  105.     {
  106.         if (!$this->userProjets->contains($userProjet)) {
  107.             $this->userProjets->add($userProjet);
  108.             $userProjet->setUser($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeUserProjet(UserProjets $userProjet): self
  113.     {
  114.         if ($this->userProjets->removeElement($userProjet)) {
  115.             // set the owning side to null (unless already changed)
  116.             if ($userProjet->getUser() === $this) {
  117.                 $userProjet->setUser(null);
  118.             }
  119.         }
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection<int, Commentaires>
  124.      */
  125.     public function getCommentaires(): Collection
  126.     {
  127.         return $this->commentaires;
  128.     }
  129.     public function addCommentaire(Commentaires $commentaire): self
  130.     {
  131.         if (!$this->commentaires->contains($commentaire)) {
  132.             $this->commentaires->add($commentaire);
  133.             $commentaire->setUser($this);
  134.         }
  135.         return $this;
  136.     }
  137.     public function removeCommentaire(Commentaires $commentaire): self
  138.     {
  139.         if ($this->commentaires->removeElement($commentaire)) {
  140.             // set the owning side to null (unless already changed)
  141.             if ($commentaire->getUser() === $this) {
  142.                 $commentaire->setUser(null);
  143.             }
  144.         }
  145.         return $this;
  146.     }
  147.     public function getUserInfos(): ?UserInfos
  148.     {
  149.         return $this->userInfos;
  150.     }
  151.     public function setUserInfos(UserInfos $userInfos): self
  152.     {
  153.         $this->userInfos $userInfos;
  154.         return $this;
  155.     }
  156. }