src/Entity/User.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. #[ORM\Entity(repositoryClassUserRepository::class)]
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length180uniquetrue)]
  17.     private $email;
  18.     #[ORM\Column(type'json')]
  19.     private $roles = [];
  20.     /**
  21.      * @var string The hashed password
  22.      */
  23.     #[ORM\Column(type'string'nullabletrue)]
  24.     private $password;
  25.     #[ORM\Column(type'string'length255)]
  26.     private $firstName;
  27.     #[ORM\Column(type'string'length255)]
  28.     private $lastName;
  29.     #[ORM\Column(type'datetime')]
  30.     private $modified;
  31.     #[ORM\Column(type'datetime')]
  32.     private $created;
  33.     #[ORM\OneToMany(targetEntityArticleDetails::class, mappedBy'user')]
  34.     private $articleDetails;
  35.     #[ORM\Column(type'string'length255nullabletrue)]
  36.     private $hashedEmail;
  37.     public function __construct()
  38.     {
  39.         $this->setModified(new \DateTime());
  40.         if ($this->getCreated() == null) {
  41.             $this->setCreated(new \DateTime());
  42.         }
  43.         $this->articleDetails = new ArrayCollection();
  44.     }
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getEmail(): ?string
  50.     {
  51.         return $this->email;
  52.     }
  53.     public function setEmail(string $email): self
  54.     {
  55.         $this->email $email;
  56.         return $this;
  57.     }
  58.     /**
  59.      * A visual identifier that represents this user.
  60.      *
  61.      * @see UserInterface
  62.      */
  63.     public function getUserIdentifier(): string
  64.     {
  65.         return (string) $this->email;
  66.     }
  67.     /**
  68.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  69.      */
  70.     public function getUsername(): string
  71.     {
  72.         return (string) $this->email;
  73.     }
  74.     /**
  75.      * @see UserInterface
  76.      */
  77.     public function getRoles(): array
  78.     {
  79.         $roles $this->roles;
  80.         // guarantee every user at least has ROLE_USER
  81.         $roles[] = 'ROLE_USER';
  82.         return array_unique($roles);
  83.     }
  84.     public function setRoles(array $roles): self
  85.     {
  86.         $this->roles $roles;
  87.         return $this;
  88.     }
  89.     /**
  90.      * @see PasswordAuthenticatedUserInterface
  91.      */
  92.     public function getPassword(): string
  93.     {
  94.         return $this->password;
  95.     }
  96.     public function setPassword(string $password): self
  97.     {
  98.         $this->password $password;
  99.         return $this;
  100.     }
  101.     /**
  102.      * Returning a salt is only needed, if you are not using a modern
  103.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  104.      *
  105.      * @see UserInterface
  106.      */
  107.     public function getSalt(): ?string
  108.     {
  109.         return null;
  110.     }
  111.     /**
  112.      * @see UserInterface
  113.      */
  114.     public function eraseCredentials()
  115.     {
  116.         // If you inventory any temporary, sensitive data on the user, clear it here
  117.         // $this->plainPassword = null;
  118.     }
  119.     public function getFirstName(): ?string
  120.     {
  121.         return $this->firstName;
  122.     }
  123.     public function setFirstName(string $firstName): self
  124.     {
  125.         $this->firstName $firstName;
  126.         return $this;
  127.     }
  128.     public function getLastName(): ?string
  129.     {
  130.         return $this->lastName;
  131.     }
  132.     public function setLastName(string $lastName): self
  133.     {
  134.         $this->lastName $lastName;
  135.         return $this;
  136.     }
  137.     public function getModified(): ?\DateTimeInterface
  138.     {
  139.         return $this->modified;
  140.     }
  141.     public function setModified(\DateTimeInterface $modified): self
  142.     {
  143.         $this->modified $modified;
  144.         return $this;
  145.     }
  146.     public function getCreated(): ?\DateTimeInterface
  147.     {
  148.         return $this->created;
  149.     }
  150.     public function setCreated(\DateTimeInterface $created): self
  151.     {
  152.         $this->created $created;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return Collection<int, ArticleDetails>
  157.      */
  158.     public function getArticleDetails(): Collection
  159.     {
  160.         return $this->articleDetails;
  161.     }
  162.     public function addArticleDetail(ArticleDetails $articleDetail): self
  163.     {
  164.         if (!$this->articleDetails->contains($articleDetail)) {
  165.             $this->articleDetails[] = $articleDetail;
  166.             $articleDetail->setUser($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeArticleDetail(ArticleDetails $articleDetail): self
  171.     {
  172.         if ($this->articleDetails->removeElement($articleDetail)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($articleDetail->getUser() === $this) {
  175.                 $articleDetail->setUser(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180.     public function getHashedEmail(): ?string
  181.     {
  182.         return $this->hashedEmail;
  183.     }
  184.     public function setHashedEmail(?string $hashedEmail): self
  185.     {
  186.         $this->hashedEmail $hashedEmail;
  187.         return $this;
  188.     }
  189. }