src/Entity/User.php line 12

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