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. #[ORM\Entity(repositoryClassUserRepository::class)]
  8. #[ORM\Table(name'`user`')]
  9. #[ORM\UniqueConstraint(name'UNIQ_IDENTIFIER_EMAIL'fields: ['email'])]
  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 $email 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.     public function getEmail(): ?string
  30.     {
  31.         return $this->email;
  32.     }
  33.     public function setEmail(string $email): static
  34.     {
  35.         $this->email $email;
  36.         return $this;
  37.     }
  38.     /**
  39.      * A visual identifier that represents this user.
  40.      *
  41.      * @see UserInterface
  42.      */
  43.     public function getUserIdentifier(): string
  44.     {
  45.         return (string) $this->email;
  46.     }
  47.     /**
  48.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  49.      */
  50.     public function getUsername(): string
  51.     {
  52.         return (string) $this->email;
  53.     }
  54.     /**
  55.      * @see UserInterface
  56.      */
  57.     public function getRoles(): array
  58.     {
  59.         $roles $this->roles;
  60.         // guarantee every user at least has ROLE_USER
  61.         $roles[] = 'ROLE_USER';
  62.         return array_unique($roles);
  63.     }
  64.     public function setRoles(array $roles): static
  65.     {
  66.         $this->roles $roles;
  67.         return $this;
  68.     }
  69.     /**
  70.      * @see PasswordAuthenticatedUserInterface
  71.      */
  72.     public function getPassword(): string
  73.     {
  74.         return $this->password;
  75.     }
  76.     public function setPassword(string $password): static
  77.     {
  78.         $this->password $password;
  79.         return $this;
  80.     }
  81.     /**
  82.      * Returning a salt is only needed, if you are not using a modern
  83.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  84.      *
  85.      * @see UserInterface
  86.      */
  87.     public function getSalt(): ?string
  88.     {
  89.         return null;
  90.     }
  91.     /**
  92.      * @see UserInterface
  93.      */
  94.     public function eraseCredentials(): void
  95.     {
  96.         // If you store any temporary, sensitive data on the user, clear it here
  97.         // $this->plainPassword = null;
  98.     }
  99. }