src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, unique=true)
  24.      */
  25.     private $email;
  26.     /**
  27.      * @ORM\Column(type="json")
  28.      */
  29.     private $roles = [];
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string")
  33.      */
  34.     private $password;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private $firstName;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, nullable=true)
  41.      */
  42.     private $lastName;
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getEmail(): ?string
  48.     {
  49.         return $this->email;
  50.     }
  51.     public function setEmail(string $email): self
  52.     {
  53.         $this->email $email;
  54.         return $this;
  55.     }
  56.     /**
  57.      * A visual identifier that represents this user.
  58.      *
  59.      * @see UserInterface
  60.      */
  61.     public function getUserIdentifier(): string
  62.     {
  63.         return (string)$this->email;
  64.     }
  65.     /**
  66.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  67.      */
  68.     public function getUsername(): string
  69.     {
  70.         return (string)$this->email;
  71.     }
  72.     /**
  73.      * @see UserInterface
  74.      */
  75.     public function getRoles(): array
  76.     {
  77.         $roles $this->roles;
  78.         return array_unique($roles);
  79.     }
  80.     public function setRoles(array $roles): self
  81.     {
  82.         $this->roles $roles;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @see PasswordAuthenticatedUserInterface
  87.      */
  88.     public function getPassword(): string
  89.     {
  90.         return $this->password;
  91.     }
  92.     public function setPassword(string $password): self
  93.     {
  94.         $this->password $password;
  95.         return $this;
  96.     }
  97.     /**
  98.      * Returning a salt is only needed, if you are not using a modern
  99.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  100.      *
  101.      * @see UserInterface
  102.      */
  103.     public function getSalt(): ?string
  104.     {
  105.         return null;
  106.     }
  107.     /**
  108.      * @see UserInterface
  109.      */
  110.     public function eraseCredentials()
  111.     {
  112.         // If you store any temporary, sensitive data on the user, clear it here
  113.         // $this->plainPassword = null;
  114.     }
  115.     public function getFirstName(): ?string
  116.     {
  117.         return $this->firstName;
  118.     }
  119.     public function setFirstName(?string $firstName): self
  120.     {
  121.         $this->firstName $firstName;
  122.         return $this;
  123.     }
  124.     public function getLastName(): ?string
  125.     {
  126.         return $this->lastName;
  127.     }
  128.     public function setLastName(?string $lastName): self
  129.     {
  130.         $this->lastName $lastName;
  131.         return $this;
  132.     }
  133.     public function getFullName(): ?string
  134.     {
  135.         return $this->firstName " " $this->lastName;
  136.     }
  137. }