|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Entity; |
| 4 | + |
| 5 | +use App\Repository\UserRepository; |
| 6 | +use Doctrine\DBAL\Types\Types; |
| 7 | +use Doctrine\ORM\Mapping as ORM; |
| 8 | +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; |
| 9 | +use Symfony\Component\Security\Core\User\UserInterface; |
| 10 | + |
| 11 | +#[ORM\Entity(repositoryClass: UserRepository::class)] |
| 12 | +#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_USERNAME', fields: ['username'])] |
| 13 | +class User implements UserInterface, PasswordAuthenticatedUserInterface |
| 14 | +{ |
| 15 | + #[ORM\Id] |
| 16 | + #[ORM\GeneratedValue] |
| 17 | + #[ORM\Column] |
| 18 | + private ?int $id = null; |
| 19 | + |
| 20 | + #[ORM\Column(length: 180)] |
| 21 | + private ?string $username = null; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var list<string> The user roles |
| 25 | + */ |
| 26 | + #[ORM\Column] |
| 27 | + private array $roles = []; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var string The hashed password |
| 31 | + */ |
| 32 | + #[ORM\Column] |
| 33 | + private ?string $password = null; |
| 34 | + |
| 35 | + #[ORM\Column(type: Types::TEXT, nullable: true)] |
| 36 | + private ?string $description = null; |
| 37 | + |
| 38 | + public function getId(): ?int |
| 39 | + { |
| 40 | + return $this->id; |
| 41 | + } |
| 42 | + |
| 43 | + public function getUsername(): ?string |
| 44 | + { |
| 45 | + return $this->username; |
| 46 | + } |
| 47 | + |
| 48 | + public function setUsername(string $username): static |
| 49 | + { |
| 50 | + $this->username = $username; |
| 51 | + |
| 52 | + return $this; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * A visual identifier that represents this user. |
| 57 | + * |
| 58 | + * @see UserInterface |
| 59 | + */ |
| 60 | + public function getUserIdentifier(): string |
| 61 | + { |
| 62 | + return (string) $this->username; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @see UserInterface |
| 67 | + * @return list<string> |
| 68 | + */ |
| 69 | + public function getRoles(): array |
| 70 | + { |
| 71 | + $roles = $this->roles; |
| 72 | + // guarantee every user at least has ROLE_USER |
| 73 | + $roles[] = 'ROLE_USER'; |
| 74 | + |
| 75 | + return array_unique($roles); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @param list<string> $roles |
| 80 | + */ |
| 81 | + public function setRoles(array $roles): static |
| 82 | + { |
| 83 | + $this->roles = $roles; |
| 84 | + |
| 85 | + return $this; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @see PasswordAuthenticatedUserInterface |
| 90 | + */ |
| 91 | + public function getPassword(): ?string |
| 92 | + { |
| 93 | + return $this->password; |
| 94 | + } |
| 95 | + |
| 96 | + public function setPassword(string $password): static |
| 97 | + { |
| 98 | + $this->password = $password; |
| 99 | + |
| 100 | + return $this; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * @see UserInterface |
| 105 | + */ |
| 106 | + public function eraseCredentials(): void |
| 107 | + { |
| 108 | + // If you store any temporary, sensitive data on the user, clear it here |
| 109 | + // $this->plainPassword = null; |
| 110 | + } |
| 111 | + |
| 112 | + public function getDescription(): ?string |
| 113 | + { |
| 114 | + return $this->description; |
| 115 | + } |
| 116 | + |
| 117 | + public function setDescription(?string $description): static |
| 118 | + { |
| 119 | + $this->description = $description; |
| 120 | + |
| 121 | + return $this; |
| 122 | + } |
| 123 | +} |
0 commit comments