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.     function __toString() {
  45.         return $this->email;
  46.     }
  47.     /**
  48.      * A visual identifier that represents this user.
  49.      *
  50.      * @see UserInterface
  51.      */
  52.     public function getUserIdentifier(): string
  53.     {
  54.         return (string) $this->email;
  55.     }
  56.     /**
  57.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  58.      */
  59.     public function getUsername(): string
  60.     {
  61.         return (string) $this->email;
  62.     }
  63.     /**
  64.      * @see UserInterface
  65.      */
  66.     public function getRoles(): array
  67.     {
  68.         $roles $this->roles;
  69.         // guarantee every user at least has ROLE_USER
  70.         $roles[] = 'ROLE_USER';
  71.         return array_unique($roles);
  72.     }
  73.     public function setRoles(array $roles): self
  74.     {
  75.         $this->roles $roles;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @see PasswordAuthenticatedUserInterface
  80.      */
  81.     public function getPassword(): string
  82.     {
  83.         return $this->password;
  84.     }
  85.     public function setPassword(string $password): self
  86.     {
  87.         $this->password $password;
  88.         return $this;
  89.     }
  90.     /**
  91.      * Returning a salt is only needed, if you are not using a modern
  92.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  93.      *
  94.      * @see UserInterface
  95.      */
  96.     public function getSalt(): ?string
  97.     {
  98.         return null;
  99.     }
  100.     /**
  101.      * @see UserInterface
  102.      */
  103.     public function eraseCredentials()
  104.     {
  105.         // If you store any temporary, sensitive data on the user, clear it here
  106.         // $this->plainPassword = null;
  107.     }
  108. }