src/Entity/User.php line 14

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. #[ORM\Table(name'`user`')]
  11. class User implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length180uniquetrue)]
  18.     private ?string $email null;
  19.     #[ORM\Column]
  20.     private array $roles = [];
  21.     #[ORM\Column]
  22.     private ?string $password null;
  23.     #[ORM\Column(length10)]
  24.     private string $lang 'fr';
  25.     #[ORM\Column(length255)]
  26.     private ?string $nom null;
  27.     #[ORM\Column(length255)]
  28.     private ?string $prenom null;
  29.     #[ORM\OneToMany(mappedBy'user'targetEntityUserProject::class, cascade: ['persist''remove'])]
  30.     private Collection $userProjects;
  31.     public function __construct()
  32.     {
  33.         $this->userProjects = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getEmail(): ?string
  40.     {
  41.         return $this->email;
  42.     }
  43.     public function setEmail(string $email): static
  44.     {
  45.         $this->email $email;
  46.         return $this;
  47.     }
  48.     /**
  49.      * A visual identifier that represents this user.
  50.      *
  51.      * @see UserInterface
  52.      */
  53.     public function getUserIdentifier(): string
  54.     {
  55.         return (string) $this->email;
  56.     }
  57.     /**
  58.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  59.      */
  60.     public function getUsername(): string
  61.     {
  62.         return (string) $this->email;
  63.     }
  64.     /**
  65.      * @see UserInterface
  66.      */
  67.     public function getRoles(): array
  68.     {
  69.         $roles $this->roles;
  70.         // guarantee every user at least has ROLE_USER
  71.         $roles[] = 'ROLE_USER';
  72.         return array_unique($roles);
  73.     }
  74.     public function setRoles(array $roles): static
  75.     {
  76.         $this->roles $roles;
  77.         return $this;
  78.     }
  79.     /**
  80.      * @see PasswordAuthenticatedUserInterface
  81.      */
  82.     public function getPassword(): string
  83.     {
  84.         return $this->password;
  85.     }
  86.     public function setPassword(string $password): static
  87.     {
  88.         $this->password $password;
  89.         return $this;
  90.     }
  91.     /**
  92.      * Returning a salt is only needed, if you are not using a modern
  93.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  94.      *
  95.      * @see UserInterface
  96.      */
  97.     public function getSalt(): ?string
  98.     {
  99.         return null;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function eraseCredentials(): void
  105.     {
  106.         // If you store any temporary, sensitive data on the user, clear it here
  107.         // $this->plainPassword = null;
  108.     }
  109.     public function setLang(string $lang): static
  110.     {
  111.         $this->lang $lang;
  112.         return $this;
  113.     }
  114.     public function getLang(): string
  115.     {
  116.         return $this->lang;
  117.     }
  118.     public function getUserProjects(): Collection
  119.     {
  120.         return $this->userProjects;
  121.     }
  122.     public function addProject(Project $project, array $role): self
  123.     {
  124.         foreach ($this->userProjects as $userProject) {
  125.             if ($userProject->getProject() === $project) {
  126.                 return $this;
  127.             }
  128.         }
  129.         $userProject = new UserProject($this$project$role);
  130.         $this->userProjects->add($userProject);
  131.         return $this;
  132.     }
  133.     public function removeProject(Project $project): self
  134.     {
  135.         foreach ($this->userProjects as $userProject) {
  136.             if ($userProject->getProject() === $project) {
  137.                 $this->userProjects->removeElement($userProject);
  138.             }
  139.         }
  140.         return $this;
  141.     }
  142.     public function __toString(): string
  143.     {
  144.         return $this->getUserIdentifier();
  145.     }
  146.     public function addUserProject(UserProject $userProject): static
  147.     {
  148.         if (!$this->userProjects->contains($userProject)) {
  149.             $this->userProjects->add($userProject);
  150.             $userProject->setUser($this);
  151.         }
  152.         return $this;
  153.     }
  154.     public function removeUserProject(UserProject $userProject): static
  155.     {
  156.         if ($this->userProjects->removeElement($userProject)) {
  157.             // set the owning side to null (unless already changed)
  158.             if ($userProject->getUser() === $this) {
  159.                 $userProject->setUser(null);
  160.             }
  161.         }
  162.         return $this;
  163.     }
  164.     public function getNom(): ?string
  165.     {
  166.         return $this->nom;
  167.     }
  168.     public function setNom(string $nom): static
  169.     {
  170.         $this->nom $nom;
  171.         return $this;
  172.     }
  173.     public function getPrenom(): ?string
  174.     {
  175.         return $this->prenom;
  176.     }
  177.     public function setPrenom(string $prenom): static
  178.     {
  179.         $this->prenom $prenom;
  180.         return $this;
  181.     }
  182. }