src/Entity/User.php line 18

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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="Un compte existe déjà avec cet e-mail")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      * @Assert\NotBlank()
  26.      * @Assert\Email()
  27.      */
  28.     private $email;
  29.     /**
  30.      * @ORM\Column(type="json", nullable=true)
  31.      */
  32.     private $roles = [];
  33.     /**
  34.      * @var string The hashed password
  35.      * @ORM\Column(type="string", nullable=true)
  36.      */
  37.     private $password;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      * @Assert\NotBlank()
  41.      */
  42.     private $name;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity=Log::class, mappedBy="user")
  45.      */
  46.     private $logs;
  47.     public function __construct()
  48.     {
  49.         $this->logs = new ArrayCollection();
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getEmail(): ?string
  56.     {
  57.         return $this->email;
  58.     }
  59.     public function setEmail(string $email): self
  60.     {
  61.         $this->email $email;
  62.         return $this;
  63.     }
  64.     /**
  65.      * A visual identifier that represents this user.
  66.      *
  67.      * @see UserInterface
  68.      */
  69.     public function getUserIdentifier(): string
  70.     {
  71.         return (string) $this->email;
  72.     }
  73.     /**
  74.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  75.      */
  76.     public function getUsername(): string
  77.     {
  78.         return (string) $this->email;
  79.     }
  80.     /**
  81.      * @see UserInterface
  82.      */
  83.     public function getRoles(): array
  84.     {
  85.         $roles $this->roles;
  86.         return array_unique($roles);
  87.     }
  88.     public function setRoles(array $roles): self
  89.     {
  90.         $this->roles $roles;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @see PasswordAuthenticatedUserInterface
  95.      */
  96.     public function getPassword(): ?string
  97.     {
  98.         return $this->password;
  99.     }
  100.     public function setPassword(string $password): self
  101.     {
  102.         $this->password $password;
  103.         return $this;
  104.     }
  105.     /**
  106.      * Returning a salt is only needed, if you are not using a modern
  107.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  108.      *
  109.      * @see UserInterface
  110.      */
  111.     public function getSalt(): ?string
  112.     {
  113.         return null;
  114.     }
  115.     /**
  116.      * @see UserInterface
  117.      */
  118.     public function eraseCredentials()
  119.     {
  120.         // If you store any temporary, sensitive data on the user, clear it here
  121.         // $this->plainPassword = null;
  122.     }
  123.     public function getName(): ?string
  124.     {
  125.         return $this->name;
  126.     }
  127.     public function setName(?string $name): self
  128.     {
  129.         $this->name $name;
  130.         return $this;
  131.     }
  132.     /**
  133.      * @return Collection<int, Log>
  134.      */
  135.     public function getLogs(): Collection
  136.     {
  137.         return $this->logs;
  138.     }
  139.     public function addLog(Log $log): self
  140.     {
  141.         if (!$this->logs->contains($log)) {
  142.             $this->logs[] = $log;
  143.             $log->setUser($this);
  144.         }
  145.         return $this;
  146.     }
  147.     public function removeLog(Log $log): self
  148.     {
  149.         if ($this->logs->removeElement($log)) {
  150.             // set the owning side to null (unless already changed)
  151.             if ($log->getUser() === $this) {
  152.                 $log->setUser(null);
  153.             }
  154.         }
  155.         return $this;
  156.     }
  157. }