src/Entity/User.php line 13

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. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  6. /**
  7.  * @ORM\Entity
  8.  * @ORM\Table(name="user")
  9.  */
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue(strategy="AUTO")
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=180, unique=true)
  20.      */
  21.     private $username;
  22.     /**
  23.      * @ORM\Column(type="json")
  24.      */
  25.     private $roles = [];
  26.     /**
  27.      * @var string The hashed password
  28.      * @ORM\Column(type="string", length=255)
  29.      */
  30.     private $password;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $avatar;
  35.     /**
  36.      * @ORM\Column(type="string", length=180, unique=true)
  37.      */
  38.     private $email;
  39.     /**
  40.      * @ORM\Column(type="datetime")
  41.      */
  42.     private $createdAt;
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getUserIdentifier(): string
  48.     {
  49.         return (string) $this->username;
  50.     }
  51.     // For Symfony < 5.3 compatibility (optional)
  52.     public function getUsername(): string
  53.     {
  54.         return (string) $this->username;
  55.     }
  56.     public function setUsername(string $username): self
  57.     {
  58.         $this->username $username;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return string[]
  63.      */
  64.     public function getRoles(): array
  65.     {
  66.         $roles $this->roles;
  67.         // guarantee every user at least has ROLE_USER
  68.         if (!in_array('ROLE_USER'$rolestrue)) {
  69.             $roles[] = 'ROLE_USER';
  70.         }
  71.         return array_values(array_unique($roles));
  72.     }
  73.     /**
  74.      * @param string[] $roles
  75.      */
  76.     public function setRoles(array $roles): self
  77.     {
  78.         $this->roles $roles;
  79.         return $this;
  80.     }
  81.     public function getPassword(): string
  82.     {
  83.         return $this->password;
  84.     }
  85.     public function setPassword(string $password): self
  86.     {
  87.         $this->password $password;
  88.         return $this;
  89.     }
  90.     public function getSalt(): ?string
  91.     {
  92.         return null// not needed for modern algorithms
  93.     }
  94.     public function eraseCredentials(): void
  95.     {
  96.         // If you store any temporary, sensitive data on the user, clear it here
  97.         // $this->plainPassword = null;
  98.     }
  99.     public function getAvatar(): ?string
  100.     {
  101.         return $this->avatar;
  102.     }
  103.     public function setAvatar(?string $avatar): self
  104.     {
  105.         $this->avatar $avatar;
  106.         return $this;
  107.     }
  108.     public function getEmail(): ?string
  109.     {
  110.         return $this->email;
  111.     }
  112.     public function setEmail(string $email): self
  113.     {
  114.         $this->email $email;
  115.         return $this;
  116.     }
  117.     public function getCreatedAt(): ?\DateTimeInterface
  118.     {
  119.         return $this->createdAt;
  120.     }
  121.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  122.     {
  123.         $this->createdAt $createdAt;
  124.         return $this;
  125.     }
  126. }