src/Entity/User.php line 17

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. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[UniqueEntity('email'"Cet email est déja pris")]
  13. #[ORM\Table(name'`user`')]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type'integer')]
  19.     private $id;
  20.     #[ORM\Column(type'string'length180uniquetrue)]
  21.     #[Assert\NotBlank]
  22.     private $email;
  23.     #[ORM\Column(type'json')]
  24.     private $roles = [];
  25.     #[ORM\Column(type'string')]
  26.     private $password;
  27.     #[ORM\Column(type'string'length255)]
  28.     #[Assert\Length(null3)]
  29.     private $firstname;
  30.     #[ORM\Column(type'string'length255)]
  31.     private $lastname;
  32.     #[ORM\OneToMany(mappedBy'user'targetEntityAddress::class)]
  33.     private $addresses;
  34.     #[ORM\OneToMany(mappedBy'user'targetEntityOrder::class)]
  35.     private $orders;
  36.     public function __construct()
  37.     {
  38.         $this->addresses = new ArrayCollection();
  39.         $this->orders = new ArrayCollection();
  40.     }
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     public function getEmail(): ?string
  46.     {
  47.         return $this->email;
  48.     }
  49.     public function setEmail(string $email): self
  50.     {
  51.         $this->email $email;
  52.         return $this;
  53.     }
  54.     /**
  55.      * A visual identifier that represents this user.
  56.      *
  57.      * @see UserInterface
  58.      */
  59.     public function getUserIdentifier(): string
  60.     {
  61.         return (string) $this->email;
  62.     }
  63.     /**
  64.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  65.      */
  66.     public function getUsername(): string
  67.     {
  68.         return (string) $this->email;
  69.     }
  70.     /**
  71.      * @see UserInterface
  72.      */
  73.     public function getRoles(): array
  74.     {
  75.         $roles $this->roles;
  76.         // guarantee every user at least has ROLE_USER
  77.         $roles[] = 'ROLE_USER';
  78.         return array_unique($roles);
  79.     }
  80.     public function setRoles(array $roles): self
  81.     {
  82.         $this->roles $roles;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @see PasswordAuthenticatedUserInterface
  87.      */
  88.     public function getPassword(): string
  89.     {
  90.         return $this->password;
  91.     }
  92.     public function setPassword(string $password): self
  93.     {
  94.         $this->password $password;
  95.         return $this;
  96.     }
  97.     /**
  98.      * Returning a salt is only needed, if you are not using a modern
  99.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  100.      *
  101.      * @see UserInterface
  102.      */
  103.     public function getSalt(): ?string
  104.     {
  105.         return null;
  106.     }
  107.     /**
  108.      * @see UserInterface
  109.      */
  110.     public function eraseCredentials()
  111.     {
  112.         // If you store any temporary, sensitive data on the user, clear it here
  113.         // $this->plainPassword = null;
  114.     }
  115.     public function getFirstname(): ?string
  116.     {
  117.         return $this->firstname;
  118.     }
  119.     public function setFirstname(string $firstname): self
  120.     {
  121.         $this->firstname $firstname;
  122.         return $this;
  123.     }
  124.     public function getLastname(): ?string
  125.     {
  126.         return $this->lastname;
  127.     }
  128.     public function setLastname(string $lastname): self
  129.     {
  130.         $this->lastname $lastname;
  131.         return $this;
  132.     }
  133.     public function getFullName(): ?string
  134.     {
  135.         return $this->firstname ' ' $this->lastname;
  136.     }
  137.     /**
  138.      * @return Collection|Address[]
  139.      */
  140.     public function getAddresses(): Collection
  141.     {
  142.         return $this->addresses;
  143.     }
  144.     public function addAddress(Address $address): self
  145.     {
  146.         if (!$this->addresses->contains($address)) {
  147.             $this->addresses[] = $address;
  148.             $address->setUser($this);
  149.         }
  150.         return $this;
  151.     }
  152.     public function removeAddress(Address $address): self
  153.     {
  154.         if ($this->addresses->removeElement($address)) {
  155.             // set the owning side to null (unless already changed)
  156.             if ($address->getUser() === $this) {
  157.                 $address->setUser(null);
  158.             }
  159.         }
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return Collection|Order[]
  164.      */
  165.     public function getOrders(): Collection
  166.     {
  167.         return $this->orders;
  168.     }
  169.     public function addOrder(Order $order): self
  170.     {
  171.         if (!$this->orders->contains($order)) {
  172.             $this->orders[] = $order;
  173.             $order->setUser($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeOrder(Order $order): self
  178.     {
  179.         if ($this->orders->removeElement($order)) {
  180.             // set the owning side to null (unless already changed)
  181.             if ($order->getUser() === $this) {
  182.                 $order->setUser(null);
  183.             }
  184.         }
  185.         return $this;
  186.     }
  187. }