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