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. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     use TimestampableEntity;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null;
  20.     #[ORM\Column(length180uniquetrue)]
  21.     private ?string $email null;
  22.     #[ORM\Column]
  23.     private array $roles = [];
  24.     /**
  25.      * @var string The hashed password
  26.      */
  27.     #[ORM\Column]
  28.     private ?string $password null;
  29.     #[ORM\Column(type'boolean')]
  30.     private $isVerified false;
  31.     #[ORM\Column]
  32.     private ?bool $enabled null;
  33.     #[ORM\OneToMany(mappedBy'user'targetEntityNotification::class, orphanRemovaltrue)]
  34.     private Collection $notifications;
  35.     public function __construct()
  36.     {
  37.         $this->notifications = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getEmail(): ?string
  44.     {
  45.         return $this->email;
  46.     }
  47.     public function setEmail(string $email): self
  48.     {
  49.         $this->email $email;
  50.         return $this;
  51.     }
  52.     /**
  53.      * A visual identifier that represents this user.
  54.      *
  55.      * @see UserInterface
  56.      */
  57.     public function getUserIdentifier(): string
  58.     {
  59.         return (string) $this->email;
  60.     }
  61.     /**
  62.      * @see UserInterface
  63.      */
  64.     public function getRoles(): array
  65.     {
  66.         $roles $this->roles;
  67.         // guarantee every user at least has ROLE_USER
  68.         $roles[] = 'ROLE_USER';
  69.         return array_unique($roles);
  70.     }
  71.     public function setRoles(array $roles): self
  72.     {
  73.         $this->roles $roles;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @see PasswordAuthenticatedUserInterface
  78.      */
  79.     public function getPassword(): string
  80.     {
  81.         return $this->password;
  82.     }
  83.     public function setPassword(string $password): self
  84.     {
  85.         $this->password $password;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @see UserInterface
  90.      */
  91.     public function eraseCredentials()
  92.     {
  93.         // If you store any temporary, sensitive data on the user, clear it here
  94.         // $this->plainPassword = null;
  95.     }
  96.     public function isVerified(): bool
  97.     {
  98.         return $this->isVerified;
  99.     }
  100.     public function setIsVerified(bool $isVerified): self
  101.     {
  102.         $this->isVerified $isVerified;
  103.         return $this;
  104.     }
  105.     public function isEnabled(): ?bool
  106.     {
  107.         return $this->enabled;
  108.     }
  109.     public function setEnabled(bool $enabled): self
  110.     {
  111.         $this->enabled $enabled;
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return Collection<int, Notification>
  116.      */
  117.     public function getNotifications(): Collection
  118.     {
  119.         return $this->notifications;
  120.     }
  121.     public function addNotification(Notification $notification): self
  122.     {
  123.         if (!$this->notifications->contains($notification)) {
  124.             $this->notifications->add($notification);
  125.             $notification->setUser($this);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removeNotification(Notification $notification): self
  130.     {
  131.         if ($this->notifications->removeElement($notification)) {
  132.             // set the owning side to null (unless already changed)
  133.             if ($notification->getUser() === $this) {
  134.                 $notification->setUser(null);
  135.             }
  136.         }
  137.         return $this;
  138.     }
  139. }