src/Entity/User.php line 15

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. /**
  9.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  10.  */
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'string'length180uniquetrue)]
  19.     private $email;
  20.     #[ORM\Column(type'json')]
  21.     private $roles = [];
  22.     #[ORM\Column(type'string')]
  23.     private $password;
  24.     public function getId(): ?int
  25.     {
  26.         return $this->id;
  27.     }
  28.     public function getEmail(): ?string
  29.     {
  30.         return $this->email;
  31.     }
  32.     public function setEmail(string $email): self
  33.     {
  34.         $this->email $email;
  35.         return $this;
  36.     }
  37.     /**
  38.      * A visual identifier that represents this user.
  39.      *
  40.      * @see UserInterface
  41.      */
  42.     public function getUserIdentifier(): string
  43.     {
  44.         return (string) $this->email;
  45.     }
  46.     /**
  47.      * @see UserInterface
  48.      */
  49.     public function getRoles(): array
  50.     {
  51.         $roles $this->roles;
  52.         // guarantee every user at least has ROLE_USER
  53.         $roles[] = 'ROLE_USER';
  54.         return array_unique($roles);
  55.     }
  56.     public function setRoles(array $roles): self
  57.     {
  58.         $this->roles $roles;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @see PasswordAuthenticatedUserInterface
  63.      */
  64.     public function getPassword(): string
  65.     {
  66.         return $this->password;
  67.     }
  68.     public function setPassword(string $password): self
  69.     {
  70.         $this->password $password;
  71.         return $this;
  72.     }
  73.     /**
  74.      * @see UserInterface
  75.      */
  76.     public function eraseCredentials()
  77.     {
  78.         // If you store any temporary, sensitive data on the user, clear it here
  79.         // $this->plainPassword = null;
  80.     }
  81. }