src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints\Email;
  9. use Symfony\Component\Validator\Constraints\Length;
  10. use Symfony\Component\Validator\Constraints\Type;
  11. /**
  12.  * Represents a user in the system
  13.  */
  14. #[ORM\Entity(repositoryClassUserRepository::class)]
  15. #[UniqueEntity(fields'email'message"There is already an account with this email")]
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     /**
  19.      * @var int The unique and automatically generated ID. Not to be modified.
  20.      */
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column(type"integer")]
  24.     private readonly int $id;
  25.     /**
  26.      * @var string The email address
  27.      */
  28.     #[ORM\Column(type"string"length180uniquetrue)]
  29.     #[Email]
  30.     private string $email;
  31.     /**
  32.      * @var array The list of access roles
  33.      */
  34.     #[ORM\Column(type"json")]
  35.     private array $roles = [];
  36.     /**
  37.      * @var string The hashed password
  38.      */
  39.     #[ORM\Column(type"string")]
  40.     private string $password;
  41.     /**
  42.      * @var boolean True if the user's email has been verified
  43.      */
  44.     #[ORM\Column(type"boolean")]
  45.     private bool $isVerified false;
  46.     #[ORM\Column(type'string'length255nullabletrue)]
  47.     private $googleId;
  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 setRoles(array $roles): self
  81.     {
  82.         $this->roles $roles;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @see PasswordAuthenticatedUserInterface
  87.      */
  88.     public function getPassword(): string
  89.     {
  90.         return $this->password;
  91.     }
  92.     public function setPassword(string $password): self
  93.     {
  94.         $this->password $password;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @see UserInterface
  99.      */
  100.     public function eraseCredentials()
  101.     {
  102.         // If you store any temporary, sensitive data on the user, clear it here
  103.         // $this->plainPassword = null;
  104.     }
  105.     public function isVerified(): bool
  106.     {
  107.         return $this->isVerified;
  108.     }
  109.     public function setIsVerified(bool $isVerified): self
  110.     {
  111.         $this->isVerified $isVerified;
  112.         return $this;
  113.     }
  114.     public function getGoogleId(): ?string
  115.     {
  116.         return $this->googleId;
  117.     }
  118.     public function setGoogleId(?string $googleId): self
  119.     {
  120.         $this->googleId $googleId;
  121.         return $this;
  122.     }
  123. }