src/Entity/User.php line 15

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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'string'length180uniquetrue)]
  19.     private $email;
  20.     #[ORM\Column(type'json')]
  21.     private $roles = [];
  22.     #[ORM\Column(type'string')]
  23.     private $password;
  24.     #[ORM\Column(type'boolean')]
  25.     private $isVerified false;
  26.     #[ORM\OneToMany(mappedBy'user'targetEntityCompany::class, orphanRemovaltrue)]
  27.     private $companies;
  28.     #[ORM\OneToMany(mappedBy'user'targetEntityDriver::class, orphanRemovaltrue)]
  29.     private $drivers;
  30.     public function __construct()
  31.     {
  32.         $this->companies = new ArrayCollection();
  33.         $this->drivers = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getEmail(): ?string
  40.     {
  41.         return $this->email;
  42.     }
  43.     public function setEmail(string $email): self
  44.     {
  45.         $this->email $email;
  46.         return $this;
  47.     }
  48.     /**
  49.      * A visual identifier that represents this user.
  50.      *
  51.      * @see UserInterface
  52.      */
  53.     public function getUserIdentifier(): string
  54.     {
  55.         return (string) $this->email;
  56.     }
  57.     /**
  58.      * @see UserInterface
  59.      */
  60.     public function getRoles(): array
  61.     {
  62.         $roles $this->roles;
  63.         // guarantee every user at least has ROLE_USER
  64.         $roles[] = 'ROLE_USER';
  65.         return array_unique($roles);
  66.     }
  67.     public function setRoles(array $roles): self
  68.     {
  69.         $this->roles $roles;
  70.         return $this;
  71.     }
  72.     /**
  73.      * @see PasswordAuthenticatedUserInterface
  74.      */
  75.     public function getPassword(): string
  76.     {
  77.         return $this->password;
  78.     }
  79.     public function setPassword(string $password): self
  80.     {
  81.         $this->password $password;
  82.         return $this;
  83.     }
  84.     /**
  85.      * @see UserInterface
  86.      */
  87.     public function eraseCredentials()
  88.     {
  89.         // If you store any temporary, sensitive data on the user, clear it here
  90.         // $this->plainPassword = null;
  91.     }
  92.     public function isVerified(): bool
  93.     {
  94.         return $this->isVerified;
  95.     }
  96.     public function setIsVerified(bool $isVerified): self
  97.     {
  98.         $this->isVerified $isVerified;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection<int, Company>
  103.      */
  104.     public function getCompanies(): Collection
  105.     {
  106.         return $this->companies;
  107.     }
  108.     public function addCompany(Company $company): self
  109.     {
  110.         if (!$this->companies->contains($company)) {
  111.             $this->companies[] = $company;
  112.             $company->setUser($this);
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeCompany(Company $company): self
  117.     {
  118.         if ($this->companies->removeElement($company)) {
  119.             // set the owning side to null (unless already changed)
  120.             if ($company->getUser() === $this) {
  121.                 $company->setUser(null);
  122.             }
  123.         }
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return Collection<int, Driver>
  128.      */
  129.     public function getDrivers(): Collection
  130.     {
  131.         return $this->drivers;
  132.     }
  133.     public function addDriver(Driver $driver): self
  134.     {
  135.         if (!$this->drivers->contains($driver)) {
  136.             $this->drivers[] = $driver;
  137.             $driver->setUser($this);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeDriver(Driver $driver): self
  142.     {
  143.         if ($this->drivers->removeElement($driver)) {
  144.             // set the owning side to null (unless already changed)
  145.             if ($driver->getUser() === $this) {
  146.                 $driver->setUser(null);
  147.             }
  148.         }
  149.         return $this;
  150.     }
  151. }