<?phpnamespace App\Entity;use App\Repository\UserRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Uid\Uuid;/** * @ORM\Entity(repositoryClass=UserRepository::class) * @ORM\Table(name="t_admin_user") */class User implements UserInterface, PasswordAuthenticatedUserInterface{ /** * @ORM\Id() * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Column(type="integer") */ private ?int $id = null; /** * @var string|null * @ORM\Column(nullable=true) */ private ?string $token = null; /** * @ORM\Column(type="string", length=50, unique=true) */ private ?string $username; /** * @var string|null The hashed password * @ORM\Column(type="string") */ private ?string $password; /** * @ORM\OneToMany(targetEntity=Role::class, mappedBy="users") */ private Collection $roles; public function __construct() { $this->token = Uuid::v4(); $this->roles = new ArrayCollection(); } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @return string|null */ public function getToken(): ?string { return $this->token; } /** * @param string|null $token */ public function setToken(?string $token): void { $this->token = $token; } /** * A visual identifier that represents this user. * * @see UserInterface */ public function getUsername(): string { return (string)$this->username; } /** * @param string $username * @return $this */ public function setUsername(string $username): self { $this->username = $username; return $this; } /** * @see UserInterface */ public function getRoles(): array { $roles = array_map(static function (Role $role){ return $role->getName(); },$this->roles->toArray()); return array_unique($roles); } /** * @param array $roles * @return $this */ public function setRoles(array $roles): self { $this->roles = $roles; return $this; } /** * @see UserInterface */ public function getPassword(): string { return (string)$this->password; } /** * @param string $password * @return $this */ public function setPassword(string $password): self { $this->password = $password; return $this; } /** * @see UserInterface */ public function getSalt() { // not needed when using the "bcrypt" algorithm in security.yaml } /** * @see UserInterface */ public function eraseCredentials() { // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; } public function getUserIdentifier(): string { return (string)$this->username; } public function addRole(Role $role): self { if (!$this->roles->contains($role)) { $this->roles[] = $role; $role->setUsers($this); } return $this; } public function removeRole(Role $role): self { if ($this->roles->removeElement($role)) { $role->removeUser($this); } return $this; }}