src/Entity/SuperAdmin.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. /**
  6.  * @ORM\Entity(repositoryClass="App\Repository\SuperAdminRepository")
  7.  * @ORM\HasLifecycleCallbacks()
  8.  */
  9. class SuperAdmin extends BaseEntity implements UserInterface
  10. {
  11.     /**
  12.      * @ORM\Column(type="string", length=255,unique=true)
  13.      */
  14.     private $email;
  15.     /**
  16.      * @ORM\Column(type="string", length=255)
  17.      */
  18.     private $username;
  19.     /**
  20.      * @var string The hashed password
  21.      * @ORM\Column(type="string", nullable=true)
  22.      */
  23.     private $password;
  24.     /**
  25.      * @ORM\Column(type="json")
  26.      */
  27.     private $roles = [];
  28.     /**
  29.      * @see UserInterface
  30.      */
  31.     public function getPassword(): string
  32.     {
  33.         return (string) $this->password;
  34.     }
  35.     public function setPassword(?string $password): self
  36.     {
  37.         $this->password $password;
  38.         return $this;
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getEmail(): ?string
  45.     {
  46.         return $this->email;
  47.     }
  48.     public function setEmail(?string $email): self
  49.     {
  50.         $this->email $email;
  51.         return $this;
  52.     }
  53.     public function getUsername(): ?string
  54.     {
  55.         return $this->username;
  56.     }
  57.     /**
  58.      * Stable identifier used by Symfony's authenticator manager.
  59.      */
  60.     public function getUserIdentifier(): string
  61.     {
  62.         return (string) $this->email;
  63.     }
  64.     public function setUsername(?string $username): self
  65.     {
  66.         $this->username $username;
  67.         return $this;
  68.     }
  69.     /**
  70.      * @see UserInterface
  71.      */
  72.     public function getRoles(): array
  73.     {
  74.         $roles $this->roles;
  75.         // guarantee every user at least has ROLE_USER
  76.         $roles[] = 'ROLE_SUPER_ADMIN';
  77.         return array_unique($roles);
  78.     }
  79.     public function addRole(string $role): self
  80.     {
  81.         $this->roles[] = $role;
  82.         return $this;
  83.     }
  84.     public function setRoles(array $roles): self
  85.     {
  86.         $this->roles $roles;
  87.         return $this;
  88.     }
  89.     public function hasRole(string $role): bool
  90.     {
  91.         return in_array($role$this->roles);
  92.     }
  93.     /**
  94.      * @see UserInterface
  95.      */
  96.     public function getSalt(): ?string
  97.     {
  98.         // not needed when using the "bcrypt" algorithm in security.yaml
  99.         return null;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function eraseCredentials(): void
  105.     {
  106.         // If you store any temporary, sensitive data on the user, clear it here
  107.         // $this->plainPassword = null;
  108.     }
  109. }