src/Entity/User.php line 13

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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. /**
  8.  * @ORM\Entity(repositoryClass=UserRepository::class)
  9.  */
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=180, unique=true)
  20.      */
  21.     private $email;
  22.     /**
  23.      * @ORM\Column(type="json")
  24.      */
  25.     private $roles = [];
  26.     /**
  27.      * @var string The hashed password
  28.      * @ORM\Column(type="string")
  29.      */
  30.     private $password;
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getEmail(): ?string
  36.     {
  37.         return $this->email;
  38.     }
  39.     public function setEmail(string $email): self
  40.     {
  41.         $this->email $email;
  42.         return $this;
  43.     }
  44.     /**
  45.      * A visual identifier that represents this user.
  46.      *
  47.      * @see UserInterface
  48.      */
  49.     public function getUserIdentifier(): string
  50.     {
  51.         return (string) $this->email;
  52.     }
  53.     /**
  54.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  55.      */
  56.     public function getUsername(): string
  57.     {
  58.         return (string) $this->email;
  59.     }
  60.     /**
  61.      * @see UserInterface
  62.      */
  63.     public function getRoles(): array
  64.     {
  65.         $roles $this->roles;
  66.         // guarantee every user at least has ROLE_USER
  67.         $roles[] = 'ROLE_USER';
  68.         return array_unique($roles);
  69.     }
  70.     public function setRoles(array $roles): self
  71.     {
  72.         $this->roles $roles;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @see PasswordAuthenticatedUserInterface
  77.      */
  78.     public function getPassword(): string
  79.     {
  80.         return $this->password;
  81.     }
  82.     public function setPassword(string $password): self
  83.     {
  84.         $this->password $password;
  85.         return $this;
  86.     }
  87.     /**
  88.      * Returning a salt is only needed, if you are not using a modern
  89.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  90.      *
  91.      * @see UserInterface
  92.      */
  93.     public function getSalt(): ?string
  94.     {
  95.         return null;
  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. }