src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClass"App\Repository\UserRepository")]
  13. #[UniqueEntity(fields: ['username'], message'Username deja utilisé')]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private int $id;
  20.     #[ORM\Column(length180uniquetrue)]
  21.     private string $username;
  22.     #[ORM\Column(type"json")]
  23.     private array $roles = [];
  24.     #[ORM\Column]
  25.     private string $password;
  26.     #[Assert\EqualTo(propertyPath:'password'message'Les mots de passe ne sont pas identiques' )]
  27.     private string $passwordConfirm;
  28.     #[ORM\OneToMany(mappedBy'User'targetEntityProduct::class, orphanRemovaltrue)]
  29.     private Collection $Products;
  30.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  31.     private ?string $image null;
  32.     private ?File $imageFile null;
  33.     public function __construct()
  34.     {
  35.         $this->Products = new ArrayCollection();
  36.     }
  37.     public function __toString(): string
  38.     {
  39.         return $this->username;
  40.     }
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     /**
  46.      * A visual identifier that represents this user.
  47.      *
  48.      * @see UserInterface
  49.      */
  50.     public function getUsername(): string
  51.     {
  52.         return (string) $this->username;
  53.     }
  54.     public function setUsername(string $username): self
  55.     {
  56.         $this->username $username;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @see UserInterface
  61.      */
  62.     public function getRoles(): array
  63.     {
  64.         $roles $this->roles;
  65.         // guarantee every user at least has ROLE_USER
  66.         $roles[] = 'ROLE_USER';
  67.         return array_unique($roles);
  68.     }
  69.     public function setRoles(array $roles): self
  70.     {
  71.         $this->roles $roles;
  72.         return $this;
  73.     }
  74.     /**
  75.      * @see UserInterface
  76.      */
  77.     public function getPassword(): string
  78.     {
  79.         return $this->password;
  80.     }
  81.     public function setPassword(string $password): self
  82.     {
  83.         $this->password $password;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @see UserInterface
  88.      */
  89.     public function getSalt()
  90.     {
  91.         // not needed when using the "bcrypt" algorithm in security.yaml
  92.     }
  93.     /**
  94.      * @see UserInterface
  95.      */
  96.     public function eraseCredentials()
  97.     {
  98.         // If you store any temporary, sensitive data on the user, clear it here
  99.         // $this->plainPassword = null;
  100.     }
  101.     /**
  102.      * @return mixed
  103.      */
  104.     public function getFullName(): mixed
  105.     {
  106.         return $this->username;
  107.     }
  108.     public function getUserIdentifier(): string
  109.     {
  110.         return $this->getUsername();
  111.     }
  112.     /**
  113.      * @return Collection<int, Product>
  114.      */
  115.     public function getProducts(): Collection
  116.     {
  117.         return $this->Products;
  118.     }
  119.     public function addProduct(Product $product): self
  120.     {
  121.         if (!$this->Products->contains($product)) {
  122.             $this->Products->add($product);
  123.             $product->setUser($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removeProduct(Product $product): self
  128.     {
  129.         $this->Products->removeElement($product);
  130.         return $this;
  131.     }
  132.     public function getImage(): ?string
  133.     {
  134.         return $this->image;
  135.     }
  136.     public function setImage(?string $image): self
  137.     {
  138.         $this->image $image;
  139.         return $this;
  140.     }
  141.     public function getPasswordConfirm(): string
  142.     {
  143.         return $this->passwordConfirm;
  144.     }
  145.     public function setPasswordConfirm(string $passwordConfirm): self
  146.     {
  147.         $this->passwordConfirm $passwordConfirm;
  148.         return $this;
  149.     }
  150.     public function getImageFile(): ?File
  151.     {
  152.         return $this->imageFile;
  153.     }
  154.     public function setImageFile(File $imageFile): self
  155.     {
  156.         $this->imageFile $imageFile;
  157.         return $this;
  158.     }
  159. }