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