src/Core/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Core\Entity;
  3. use Doctrine\Common\Collections\Collection;
  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. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Core\Repository\UserRepository")
  11.  * @UniqueEntity("email")
  12.  * @UniqueEntity("username")
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id()
  18.      * @ORM\GeneratedValue()
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private int $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, unique=true)
  24.      * @Assert\NotBlank()
  25.      */
  26.     private string $username;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, unique=true)
  29.      * @Assert\Email()
  30.      * @Assert\NotBlank()
  31.      */
  32.     private string $email;
  33.     /**
  34.      * @ORM\Column(type="string", length=255)
  35.      * @Assert\NotCompromisedPassword()
  36.      */
  37.     private string $password;
  38.     /**
  39.      * @ORM\Column(type="string", length=255)
  40.      */
  41.     private string $fullName;
  42.     /**
  43.      * @ORM\ManyToMany(targetEntity="Role", inversedBy="id")
  44.      */
  45.     private Collection $roles;
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getUsername(): ?string
  51.     {
  52.         return $this->username;
  53.     }
  54.     public function setUsername(string $username): self
  55.     {
  56.         $this->username $username;
  57.         return $this;
  58.     }
  59.     public function getEmail(): ?string
  60.     {
  61.         return $this->email;
  62.     }
  63.     public function setEmail(string $email): self
  64.     {
  65.         $this->email $email;
  66.         return $this;
  67.     }
  68.     public function getPassword(): ?string
  69.     {
  70.         return $this->password;
  71.     }
  72.     public function setPassword(string $password): self
  73.     {
  74.         $this->password $password;
  75.         return $this;
  76.     }
  77.     public function getFullName(): ?string
  78.     {
  79.         return $this->fullName;
  80.     }
  81.     public function setFullName(string $fullName): self
  82.     {
  83.         $this->fullName $fullName;
  84.         return $this;
  85.     }
  86.     public function getRoles(): array
  87.     {
  88.         $roles = [];
  89.         /** @var Role $roleEntity */
  90.         foreach ($this->roles as $roleEntity) {
  91.             $roles[] = $roleEntity->getSystemCode();
  92.         }
  93.         return $roles;
  94.     }
  95.     public function setRoles(Collection $roles): self
  96.     {
  97.         $this->roles $roles;
  98.         return $this;
  99.     }
  100.     public function addRole(Role $role): self
  101.     {
  102.         $this->roles->add($role);
  103.         return $this;
  104.     }
  105.     public function removeRole(Role $role): self
  106.     {
  107.         $this->roles->removeElement($role);
  108.         return $this;
  109.     }
  110.     public function eraseCredentials()
  111.     {
  112.         // TODO: Implement eraseCredentials() method.
  113.     }
  114.     public function getSalt()
  115.     {
  116.         // TODO: Implement getSalt() method.
  117.     }
  118.     public function getUserIdentifier(): string
  119.     {
  120.         return $this->email;
  121.     }
  122. }