src/Entity/User.php line 14

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