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(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length180uniquetrue)]
  17.     private $email;
  18.     #[ORM\Column(type'json')]
  19.     private array $roles = [];
  20.     #[ORM\Column(type'string')]
  21.     private $password;
  22.     #[ORM\OneToMany(mappedBy'user'targetEntityCreation::class)]
  23.     private $creations;
  24.     public function __construct()
  25.     {
  26.         $this->creations = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getEmail(): ?string
  33.     {
  34.         return $this->email;
  35.     }
  36.     public function setEmail(string $email): self
  37.     {
  38.         $this->email $email;
  39.         return $this;
  40.     }
  41.     /**
  42.      * A visual identifier that represents this user.
  43.      *
  44.      * @see UserInterface
  45.      */
  46.     public function getUserIdentifier(): string
  47.     {
  48.         return (string) $this->email;
  49.     }
  50.     /**
  51.      * @see UserInterface
  52.      */
  53.     public function getRoles(): array
  54.     {
  55.         $roles $this->roles;
  56.         // guarantee every user at least has ROLE_USER
  57.         $roles[] = 'ROLE_USER';
  58.         return array_unique($roles);
  59.     }
  60.     public function setRoles(array $roles): self
  61.     {
  62.         $this->roles $roles;
  63.         return $this;
  64.     }
  65.     /**
  66.      * @see PasswordAuthenticatedUserInterface
  67.      */
  68.     public function getPassword(): string
  69.     {
  70.         return $this->password;
  71.     }
  72.     public function setPassword(string $password): self
  73.     {
  74.         $this->password $password;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @see UserInterface
  79.      */
  80.     public function eraseCredentials()
  81.     {
  82.         // If you store any temporary, sensitive data on the user, clear it here
  83.         // $this->plainPassword = null;
  84.     }
  85.     /**
  86.      * @return Collection<int, Creation>
  87.      */
  88.     public function getCreations(): Collection
  89.     {
  90.         return $this->creations;
  91.     }
  92.     public function addCreation(Creation $creation): self
  93.     {
  94.         if (!$this->creations->contains($creation)) {
  95.             $this->creations[] = $creation;
  96.             $creation->setUser($this);
  97.         }
  98.         return $this;
  99.     }
  100.     public function removeCreation(Creation $creation): self
  101.     {
  102.         if ($this->creations->removeElement($creation)) {
  103.             // set the owning side to null (unless already changed)
  104.             if ($creation->getUser() === $this) {
  105.                 $creation->setUser(null);
  106.             }
  107.         }
  108.         return $this;
  109.     }
  110. }