src/Entity/Admin.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AdminRepository;
  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(repositoryClassAdminRepository::class)]
  9. #[ORM\Table(name'`admin`')]
  10. #[UniqueEntity(fields: ['username'], message'There is already an account with this username')]
  11. class Admin 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.     public function getUsername(): ?string
  31.     {
  32.         return $this->username;
  33.     }
  34.     public function setUsername(string $username): self
  35.     {
  36.         $this->username $username;
  37.         return $this;
  38.     }
  39.     /**
  40.      * A visual identifier that represents this user.
  41.      *
  42.      * @see UserInterface
  43.      */
  44.     public function getUserIdentifier(): string
  45.     {
  46.         return (string) $this->username;
  47.     }
  48.     /**
  49.      * @see UserInterface
  50.      */
  51.     public function getRoles(): array
  52.     {
  53.         $roles $this->roles;
  54.         // guarantee every user at least has ROLE_USER
  55.         $roles[] = 'ROLE_ADMIN';
  56.         return array_unique($roles);
  57.     }
  58.     public function setRoles(array $roles): self
  59.     {
  60.         $this->roles $roles;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @see PasswordAuthenticatedUserInterface
  65.      */
  66.     public function getPassword(): string
  67.     {
  68.         return $this->password;
  69.     }
  70.     public function setPassword(string $password): self
  71.     {
  72.         $this->password $password;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @see UserInterface
  77.      */
  78.     public function eraseCredentials()
  79.     {
  80.         // If you store any temporary, sensitive data on the user, clear it here
  81.         // $this->plainPassword = null;
  82.     }
  83. }