src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  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. /**
  9.  * @ORM\Entity(repositoryClass=UserRepository::class)
  10.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  11.  */
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=180, unique=true)
  22.      */
  23.     private $email;
  24.     /**
  25.      * @ORM\Column(type="json")
  26.      */
  27.     private $roles = [];
  28.     /**
  29.      * @var string The hashed password
  30.      * @ORM\Column(type="string")
  31.      */
  32.     private $password;
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getEmail(): ?string
  38.     {
  39.         return $this->email;
  40.     }
  41.     public function setEmail(string $email): self
  42.     {
  43.         $this->email $email;
  44.         return $this;
  45.     }
  46.     /**
  47.      * A visual identifier that represents this user.
  48.      *
  49.      * @see UserInterface
  50.      */
  51.     public function getUserIdentifier(): string
  52.     {
  53.         return (string) $this->email;
  54.     }
  55.     /**
  56.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  57.      */
  58.     public function getUsername(): string
  59.     {
  60.         return (string) $this->email;
  61.     }
  62.     /**
  63.      * @see UserInterface
  64.      */
  65.     public function getRoles(): array
  66.     {
  67.         $roles $this->roles;
  68.         // guarantee every user at least has ROLE_USER
  69.         $roles[] = 'ROLE_USER';
  70.         return array_unique($roles);
  71.     }
  72.     public function setRoles(array $roles): self
  73.     {
  74.         $this->roles $roles;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @see PasswordAuthenticatedUserInterface
  79.      */
  80.     public function getPassword(): string
  81.     {
  82.         return $this->password;
  83.     }
  84.     public function setPassword(string $password): self
  85.     {
  86.         $this->password $password;
  87.         return $this;
  88.     }
  89.     /**
  90.      * Returning a salt is only needed, if you are not using a modern
  91.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  92.      *
  93.      * @see UserInterface
  94.      */
  95.     public function getSalt(): ?string
  96.     {
  97.         return null;
  98.     }
  99.     /**
  100.      * @see UserInterface
  101.      */
  102.     public function eraseCredentials()
  103.     {
  104.         // If you store any temporary, sensitive data on the user, clear it here
  105.         // $this->plainPassword = null;
  106.     }
  107.     private static $statuses = [
  108.         'ROLE_ADMIN'    => 'ROLE_ADMIN',
  109.         'ROLE_EDIT' => 'ROLE_EDIT'
  110.     ];
  111.     public static function getStatuses()
  112.     {
  113.         return self::$statuses;
  114.     }
  115. }