src/Entity/User.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use App\Security\Role;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use phpDocumentor\Reflection\Types\Integer;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Uid\Uuid;
  13. /**
  14.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  15.  */
  16. #[ORM\Entity(repositoryClassUserRepository::class)]
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     use Shared;
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column(type'integer'unique:true)]
  23.     private $id;
  24.     #[ORM\Column(type'string'length255)]
  25.     private $name;
  26.     #[ORM\Column(type'string'length180uniquetrue)]
  27.     private $email;
  28.     #[ORM\Column(type'json')]
  29.     private $roles = [];
  30.     #[ORM\Column(type'string')]
  31.     private $password;
  32.     #[ORM\Column(type'boolean')]
  33.     private $isVerified false;
  34.     #[ORM\OneToMany(mappedBy'user'targetEntityReferencias::class)]
  35.     private $referencias;
  36.     public function __construct()
  37.     {
  38.         $this->createdAt = new \DateTime();
  39.         $this->markAsUpdated();
  40.         $this->roles[] = Role::ROLE_ADMIN;
  41.         $this->referencias = new ArrayCollection();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getEmail(): ?string
  48.     {
  49.         return $this->email;
  50.     }
  51.     public function setEmail(string $email): self
  52.     {
  53.         $this->email $email;
  54.         return $this;
  55.     }
  56.     /**
  57.      * A visual identifier that represents this user.
  58.      *
  59.      * @see UserInterface
  60.      */
  61.     public function getUserIdentifier(): string
  62.     {
  63.         return (string) $this->email;
  64.     }
  65.     /**
  66.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  67.      */
  68.     public function getUsername(): string
  69.     {
  70.         return (string) $this->email;
  71.     }
  72.     /**
  73.      * @see UserInterface
  74.      */
  75.     public function getRoles(): array
  76.     {
  77.         $roles $this->roles;
  78.         // guarantee every user at least has ROLE_USER
  79.         $roles[] = 'ROLE_USER';
  80.         return array_unique($roles);
  81.     }
  82.     public function setRoles(array $roles): self
  83.     {
  84.         $this->roles $roles;
  85.         return $this;
  86.     }
  87.     /**
  88.      * @see PasswordAuthenticatedUserInterface
  89.      */
  90.     public function getPassword(): string
  91.     {
  92.         return $this->password;
  93.     }
  94.     public function setPassword(string $password): self
  95.     {
  96.         $this->password $password;
  97.         return $this;
  98.     }
  99.     /**
  100.      * Returning a salt is only needed, if you are not using a modern
  101.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  102.      *
  103.      * @see UserInterface
  104.      */
  105.     public function getSalt(): ?string
  106.     {
  107.         return null;
  108.     }
  109.     /**
  110.      * @see UserInterface
  111.      */
  112.     public function eraseCredentials()
  113.     {
  114.         // If you store any temporary, sensitive data on the user, clear it here
  115.         // $this->plainPassword = null;
  116.     }
  117.     public function isVerified(): bool
  118.     {
  119.         return $this->isVerified;
  120.     }
  121.     public function setIsVerified(bool $isVerified): self
  122.     {
  123.         $this->isVerified $isVerified;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return mixed
  128.      */
  129.     public function getName(): string
  130.     {
  131.         return $this->name;
  132.     }
  133.     /**
  134.      * @param mixed $name
  135.      */
  136.     public function setName(string $name): void
  137.     {
  138.         $this->name $name;
  139.     }
  140.     /**
  141.      * @return Collection|Referencias[]
  142.      */
  143.     public function getReferencias(): Collection
  144.     {
  145.         return $this->referencias;
  146.     }
  147.     public function addReferencia(Referencias $referencia): self
  148.     {
  149.         if (!$this->referencias->contains($referencia)) {
  150.             $this->referencias[] = $referencia;
  151.             $referencia->setUser($this);
  152.         }
  153.         return $this;
  154.     }
  155.     public function removeReferencia(Referencias $referencia): self
  156.     {
  157.         if ($this->referencias->removeElement($referencia)) {
  158.             // set the owning side to null (unless already changed)
  159.             if ($referencia->getUser() === $this) {
  160.                 $referencia->setUser(null);
  161.             }
  162.         }
  163.         return $this;
  164.     }
  165. }