<?php
namespace App\Core\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Core\Repository\UserRepository")
* @UniqueEntity("email")
* @UniqueEntity("username")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\NotBlank()
*/
private string $username;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\Email()
* @Assert\NotBlank()
*/
private string $email;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotCompromisedPassword()
*/
private string $password;
/**
* @ORM\Column(type="string", length=255)
*/
private string $fullName;
/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="id")
*/
private Collection $roles;
public function getId(): ?int
{
return $this->id;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getFullName(): ?string
{
return $this->fullName;
}
public function setFullName(string $fullName): self
{
$this->fullName = $fullName;
return $this;
}
public function getRoles(): array
{
$roles = [];
/** @var Role $roleEntity */
foreach ($this->roles as $roleEntity) {
$roles[] = $roleEntity->getSystemCode();
}
return $roles;
}
public function setRoles(Collection $roles): self
{
$this->roles = $roles;
return $this;
}
public function addRole(Role $role): self
{
$this->roles->add($role);
return $this;
}
public function removeRole(Role $role): self
{
$this->roles->removeElement($role);
return $this;
}
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
public function getSalt()
{
// TODO: Implement getSalt() method.
}
public function getUserIdentifier(): string
{
return $this->email;
}
}