src/Entity/User.php line 15

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. #[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\Column(length40nullabletrue)]
  28.     private ?string $nickname null;
  29.     #[ORM\Column(type'boolean')]
  30.     private bool $isVerified false;
  31.     #[ORM\ManyToMany(targetEntitySound::class, inversedBy'users')]
  32.     private Collection $soundsBookmarked;
  33.     public function __construct()
  34.     {
  35.         $this->soundsBookmarked = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getEmail(): ?string
  42.     {
  43.         return $this->email;
  44.     }
  45.     public function setEmail(string $email): self
  46.     {
  47.         $this->email $email;
  48.         return $this;
  49.     }
  50.     /**
  51.      * A visual identifier that represents this user.
  52.      *
  53.      * @see UserInterface
  54.      */
  55.     public function getUserIdentifier(): string
  56.     {
  57.         return (string) $this->email;
  58.     }
  59.     /**
  60.      * @see UserInterface
  61.      */
  62.     public function getRoles(): array
  63.     {
  64.         $roles $this->roles;
  65.         // guarantee every user at least has ROLE_USER
  66.         $roles[] = 'ROLE_USER';
  67.         return array_unique($roles);
  68.     }
  69.     public function setRoles(array $roles): self
  70.     {
  71.         $this->roles $roles;
  72.         return $this;
  73.     }
  74.     /**
  75.      * @see PasswordAuthenticatedUserInterface
  76.      */
  77.     public function getPassword(): string
  78.     {
  79.         return $this->password;
  80.     }
  81.     public function setPassword(string $password): self
  82.     {
  83.         $this->password $password;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @see UserInterface
  88.      */
  89.     public function eraseCredentials(): void
  90.     {
  91.         // If you store any temporary, sensitive data on the user, clear it here
  92.         // $this->plainPassword = null;
  93.     }
  94.     public function getNickname(): ?string
  95.     {
  96.         return $this->nickname;
  97.     }
  98.     public function setNickname(?string $nickname): self
  99.     {
  100.         $this->nickname $nickname;
  101.         return $this;
  102.     }
  103.     public function isVerified(): bool
  104.     {
  105.         return $this->isVerified;
  106.     }
  107.     public function setIsVerified(bool $isVerified): self
  108.     {
  109.         $this->isVerified $isVerified;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection<int, Sound>
  114.      */
  115.     public function getSoundsBookmarked(): Collection
  116.     {
  117.         return $this->soundsBookmarked;
  118.     }
  119.     public function addSoundsBookmarked(Sound $soundsBookmarked): self
  120.     {
  121.         if (!$this->soundsBookmarked->contains($soundsBookmarked)) {
  122.             $this->soundsBookmarked->add($soundsBookmarked);
  123.         }
  124.         return $this;
  125.     }
  126.     public function removeSoundsBookmarked(Sound $soundsBookmarked): self
  127.     {
  128.         $this->soundsBookmarked->removeElement($soundsBookmarked);
  129.         return $this;
  130.     }
  131. }