src/Entity/User.php line 22
<?phpnamespace App\Entity;use App\Repository\UserRepository;use App\Traits\Timestamps;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Security\Core\User\EquatableInterface;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Validator\Constraints as Assert;use Symfony\Component\Validator\Context\ExecutionContextInterface;#[ORM\Entity(repositoryClass: UserRepository::class)]#[UniqueEntity(fields: ['username'])]#[UniqueEntity(fields: ['email'])]#[ORM\HasLifecycleCallbacks]class User implements UserInterface, EquatableInterface, PasswordAuthenticatedUserInterface{use Timestamps;#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 180, unique: true)]#[Assert\NotBlank(message: 'Ne doit pas être vide')]private ?string $username;#[ORM\Column(type: 'json')]private array $roles = [];#[ORM\Column(length: 50)]#[Assert\NotBlank(message: 'Ne doit pas être vide')]private ?string $nomComplet= null;#[ORM\Column( length: 100, unique: true)]#[Assert\NotBlank(message: 'Ne doit pas être vide')]#[Assert\Email(message: 'Email invalide')]private ?string $email= null;#[ORM\Column]private ?bool $valid = null;#[ORM\Column]private ?bool $deleted = null;#[ORM\Column( length: 255)]private ?string $password = null;#[ORM\Column(type: 'boolean')]private ?bool $admin = null;#[ORM\ManyToMany(targetEntity: Vault::class, mappedBy: 'authorizedUsers')]private Collection $vaults;public function __construct(){$this->vaults = new ArrayCollection();}public function getId(): ?int{return $this->id;}/*** A visual identifier that represents this user.** @see UserInterface*/public function getUsername(): string{return (string) $this->username;}public function getUserIdentifier(): string{return (string) $this->username;}public function setUsername($username): self{$this->username = $username;return $this;}/*** @see UserInterface*/public function getRoles(): array{$roles = $this->roles;// guarantee every user at least has ROLE_USER$roles[] = 'ROLE_USER';return array_unique($roles);}public function setRoles(array $roles): self{$this->roles = $roles;return $this;}/*** @see UserInterface*/public function getPassword(): ?string{return $this->password;}/*** @see UserInterface*/public function eraseCredentials(){// If you store any temporary, sensitive data on the user, clear it here// $this->plainPassword = null;}public function getNomComplet(): ?string{return $this->nomComplet;}public function setNomComplet($nomComplet): self{$this->nomComplet = $nomComplet;return $this;}public function getEmail(): ?string{return $this->email;}public function setEmail($email): self{$this->email = $email;return $this;}public function isValid(): ?bool{return $this->valid;}public function setValid(bool $valid): self{$this->valid = $valid;return $this;}public function isDeleted(): ?bool{return $this->deleted;}public function setDeleted(bool $deleted): self{$this->deleted = $deleted;return $this;}public function setPassword($password): self{$this->password = $password;return $this;}public function getAvatarUrl(): string{return "https://ui-avatars.com/api/?background=0D8ABC&color=fff&name=".$this->username;}public function getColorCode(): string{$code = dechex(crc32($this->getUsername()));$code = substr($code, 0, 6);return '#'.$code;}#[Assert\Callback]public function validate(ExecutionContextInterface $context, $payload){/*if (strlen($this->password)< 3){$context->buildViolation('Mot de passe trop court')->atPath('justpassword')->addViolation();}*/}public function __toString(): string{return "$this->nomComplet ($this->id)";}public function isAdmin(): ?bool{return $this->admin;}public function setAdmin(bool $admin): self{$this->admin = $admin;return $this;}public function isEqualTo(UserInterface $user): bool{if ($user instanceof User) {return $this->isValid() && !$this->isDeleted() && $this->getPassword() == $user->getPassword() && $this->getUsername() == $user->getUsername()&& $this->getEmail() == $user->getEmail();}return false;}/*** @return Collection<int, Vault>*/public function getVaults(): Collection{return $this->vaults;}public function addVault(Vault $vault): self{if (!$this->vaults->contains($vault)) {$this->vaults->add($vault);$vault->addAuthorizedUser($this);}return $this;}public function removeVault(Vault $vault): self{if ($this->vaults->removeElement($vault)) {$vault->removeAuthorizedUser($this);}return $this;}public function hasRole(string $role): bool{return in_array($role, $this->getRoles());}}