src/Entity/User.php line 18

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