src/Entity/User.php line 20

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\HasTimestampsTrait;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation\SoftDeleteable;
  10. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. #[ORM\Entity(repositoryClassUserRepository::class)]
  15. #[SoftDeleteable(fieldName'deletedAt'timeAwarefalse)]
  16. #[ORM\Table(uniqueConstraints: [new ORM\UniqueConstraint(columns: ["email""deleted_at"])])]
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     use HasTimestampsTrait;
  20.     use SoftDeleteableEntity;
  21.     public function __toString(): string
  22.     {
  23.         return $this->email;
  24.     }
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     private ?int $id null;
  29.     #[ORM\Column(length180)]
  30.     private ?string $email null;
  31.     #[ORM\Column(length180)]
  32.     private ?string $username null;
  33.     #[ORM\Column]
  34.     private array $roles = [];
  35.     /**
  36.      * @var ?string The hashed password
  37.      */
  38.     #[ORM\Column]
  39.     private ?string $password '';
  40.     #[ORM\Column(type'boolean')]
  41.     private bool $isVerified false;
  42.     #[ORM\OneToMany(mappedBy'user'targetEntityUserFeature::class, cascade: ["persist""remove"])]
  43.     protected Collection $userFeature;
  44.     public function __construct()
  45.     {
  46.         $this->userFeature = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getEmail(): ?string
  53.     {
  54.         return $this->email;
  55.     }
  56.     public function setEmail(string $email): self
  57.     {
  58.         $this->email $email;
  59.         return $this;
  60.     }
  61.     /**
  62.      * A visual identifier that represents this user.
  63.      *
  64.      * @see UserInterface
  65.      */
  66.     public function getUserIdentifier(): string
  67.     {
  68.         return (string) $this->email;
  69.     }
  70.     /**
  71.      * @see UserInterface
  72.      */
  73.     public function getRoles(): array
  74.     {
  75.         $roles $this->roles;
  76.         // guarantee every user at least has ROLE_USER
  77.         $roles[] = 'ROLE_USER';
  78.         return array_unique($roles);
  79.     }
  80.     public function hasRole($role): bool
  81.     {
  82.         return in_array($role$this->getRoles());
  83.     }
  84.     public function setRoles(array $roles): self
  85.     {
  86.         $this->roles $roles;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @see PasswordAuthenticatedUserInterface
  91.      */
  92.     public function getPassword(): ?string
  93.     {
  94.         return $this->password;
  95.     }
  96.     public function setPassword(?string $password): self
  97.     {
  98.         $this->password $password;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function eraseCredentials()
  105.     {
  106.         // If you store any temporary, sensitive data on the user, clear it here
  107.         // $this->plainPassword = null;
  108.     }
  109.     public function isVerified(): bool
  110.     {
  111.         return $this->isVerified;
  112.     }
  113.     public function setIsVerified(bool $isVerified): self
  114.     {
  115.         $this->isVerified $isVerified;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return string|null
  120.      */
  121.     public function getUsername(): ?string
  122.     {
  123.         return $this->username;
  124.     }
  125.     /**
  126.      * @param string|null $username
  127.      */
  128.     public function setUsername(?string $username): void
  129.     {
  130.         $this->username $username;
  131.     }
  132.     public function isIsVerified(): ?bool
  133.     {
  134.         return $this->isVerified;
  135.     }
  136.     /**
  137.      * @return Collection<int, UserFeature>
  138.      */
  139.     public function getUserFeature(): Collection
  140.     {
  141.         return $this->userFeature;
  142.     }
  143.     public function addUserFeature(UserFeature $userFeature): static
  144.     {
  145.         if (!$this->userFeature->contains($userFeature)) {
  146.             $this->userFeature->add($userFeature);
  147.             $userFeature->setUser($this);
  148.         }
  149.         return $this;
  150.     }
  151.     public function removeUserFeature(UserFeature $userFeature): static
  152.     {
  153.         if ($this->userFeature->removeElement($userFeature)) {
  154.             // set the owning side to null (unless already changed)
  155.             if ($userFeature->getUser() === $this) {
  156.                 $userFeature->setUser(null);
  157.             }
  158.         }
  159.         return $this;
  160.     }
  161. }