src/Entity/User.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\UserRepository;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. #[ORM\Entity(repositoryClassUserRepository::class)]
  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.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  26.     private ?\DateTimeInterface $lastLogin null;
  27.     public function __construct()
  28.     {
  29.         $this->lastLogin = new \DateTimeImmutable();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getUsername(): ?string
  36.     {
  37.         return $this->username;
  38.     }
  39.     public function setUsername(string $username): self
  40.     {
  41.         $this->username $username;
  42.         return $this;
  43.     }
  44.     /**
  45.      * A visual identifier that represents this user.
  46.      *
  47.      * @see UserInterface
  48.      */
  49.     public function getUserIdentifier(): string
  50.     {
  51.         return (string) $this->username;
  52.     }
  53.     /**
  54.      * @see UserInterface
  55.      */
  56.     public function getRoles(): array
  57.     {
  58.         $roles $this->roles;
  59.         // guarantee every user at least has ROLE_USER
  60.         $roles[] = 'ROLE_USER';
  61.         return array_unique($roles);
  62.     }
  63.     public function setRoles(array $roles): self
  64.     {
  65.         $this->roles $roles;
  66.         return $this;
  67.     }
  68.     /**
  69.      * @see PasswordAuthenticatedUserInterface
  70.      */
  71.     public function getPassword(): string
  72.     {
  73.         return $this->password;
  74.     }
  75.     public function setPassword(string $password): self
  76.     {
  77.         $this->password $password;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @see UserInterface
  82.      */
  83.     public function eraseCredentials()
  84.     {
  85.         // If you store any temporary, sensitive data on the user, clear it here
  86.         // $this->plainPassword = null;
  87.     }
  88.     public function getLastLogin(): ?\DateTimeInterface
  89.     {
  90.         return $this->lastLogin;
  91.     }
  92.     public function setLastLogin(\DateTimeInterface $lastLogin): self
  93.     {
  94.         $this->lastLogin $lastLogin;
  95.         return $this;
  96.     }
  97. }