src/Entity/Admin.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CreatedAtTrait;
  4. use App\Entity\Traits\UpdatedAtTrait;
  5. use App\Repository\AdminRepository;
  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\HasLifecycleCallbacks]
  10. #[ORM\Entity(repositoryClassAdminRepository::class)]
  11. class Admin implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.     use CreatedAtTrait;
  14.     use UpdatedAtTrait;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(length180uniquetrue)]
  20.     private ?string $username null;
  21.     #[ORM\Column]
  22.     private array $roles = [];
  23.     /**
  24.      * @var string|null The hashed password
  25.      */
  26.     #[ORM\Column]
  27.     private ?string $password null;
  28.     private ?string $plainPassword null;
  29.     public function getId(): ?int
  30.     {
  31.         return $this->id;
  32.     }
  33.     public function getUsername(): ?string
  34.     {
  35.         return $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.      * @see UserInterface
  80.      */
  81.     public function eraseCredentials()
  82.     {
  83.         // If you store any temporary, sensitive data on the user, clear it here
  84.         // $this->plainPassword = null;
  85.     }
  86.     public function __toString(): string{
  87.         return $this->username;
  88.     }
  89.     public function getPlainPassword(): ?string
  90.     {
  91.         return $this->plainPassword;
  92.     }
  93.     public function setPlainPassword(?string $plainPassword): self
  94.     {
  95.         $this->plainPassword $plainPassword;
  96.         return $this;
  97.     }
  98. }