src/Entity/User.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\ORM\Mapping\Table;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. #[ORM\Entity(repositoryClassUserRepository::class)]
  9. #[Table(name'backend_user')]
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type"integer")]
  15.     private $id;
  16.     #[ORM\Column(type"string"length180uniquetrue)]
  17.     private $username;
  18.     #[ORM\Column(type"json")]
  19.     private $roles = [];
  20.     #[ORM\Column(type"string")]
  21.     private $password;
  22.     private $plainPassword;
  23.     /**
  24.      * @return mixed
  25.      */
  26.     public function getPlainPassword(): mixed
  27.     {
  28.         return $this->plainPassword;
  29.     }
  30.     /**
  31.      * @param mixed $plainPassword
  32.      */
  33.     public function setPlainPassword($plainPassword): void
  34.     {
  35.         $this->plainPassword $plainPassword;
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     /**
  42.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  43.      */
  44.     public function getUsername(): string
  45.     {
  46.         return (string) $this->username;
  47.     }
  48.     public function setUsername(string $username): self
  49.     {
  50.         $this->username $username;
  51.         return $this;
  52.     }
  53.     /**
  54.      * A visual identifier that represents this user.
  55.      *
  56.      * @see UserInterface
  57.      */
  58.     public function getUserIdentifier(): string
  59.     {
  60.         return (string) $this->username;
  61.     }
  62.     /**
  63.      * @see UserInterface
  64.      */
  65.     public function getRoles(): array
  66.     {
  67.         $roles $this->roles;
  68.         // guarantee every user at least has ROLE_USER
  69.         $roles[] = 'ROLE_USER';
  70.         return array_unique($roles);
  71.     }
  72.     public function setRoles(array $roles): self
  73.     {
  74.         $this->roles $roles;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @see PasswordAuthenticatedUserInterface
  79.      */
  80.     public function getPassword(): string
  81.     {
  82.         return $this->password;
  83.     }
  84.     public function setPassword(string $password): self
  85.     {
  86.         $this->password $password;
  87.         return $this;
  88.     }
  89.     /**
  90.      * Returning a salt is only needed, if you are not using a modern
  91.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  92.      *
  93.      * @see UserInterface
  94.      */
  95.     public function getSalt(): ?string
  96.     {
  97.         return null;
  98.     }
  99.     /**
  100.      * @see UserInterface
  101.      */
  102.     public function eraseCredentials()
  103.     {
  104.         // If you store any temporary, sensitive data on the user, clear it here
  105.         $this->plainPassword null;
  106.     }
  107. }