src/Entity/User.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. //use ApiPlatform\Core\Annotation\ApiFilter;
  6. //use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. //use ApiPlatform\Core\Annotation\ApiResource;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use ApiPlatform\Metadata\ApiResource;
  11. use ApiPlatform\Metadata\ApiFilter;
  12. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  13. #[ApiResource]
  14. #[ORM\Table(name:"user")]
  15. #[ORM\Entity(repositoryClassUserRepository::class)]
  16. #[ApiFilter(SearchFilter::class, properties: ['email' => 'exact'])]
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(name:"id")]
  22.     private ?int $id null;
  23.     #[ORM\Column(name:"email"length:180unique:true)]
  24.     private ?string $email null;
  25.     #[ORM\Column(name:"roles")]
  26.     private array $roles = [];
  27.     /**
  28.      * @var string The hashed password
  29.      */
  30.     #[ORM\Column(name:"password")]
  31.     private ?string $password null;
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getEmail(): ?string
  37.     {
  38.         return $this->email;
  39.     }
  40.     public function setEmail(string $email): self
  41.     {
  42.         $this->email $email;
  43.         return $this;
  44.     }
  45.     /**
  46.      * A visual identifier that represents this user.
  47.      *
  48.      * @see UserInterface
  49.      */
  50.     public function getUserIdentifier(): string
  51.     {
  52.         return (string) $this->email;
  53.     }
  54.     /**
  55.      * @see UserInterface
  56.      */
  57.     public function getRoles(): array
  58.     {
  59.         $roles $this->roles;
  60.         // guarantee every user at least has ROLE_USER
  61.         $roles[] = 'ROLE_USER';
  62.         return array_unique($roles);
  63.     }
  64.     public function setRoles(array $roles): self
  65.     {
  66.         $this->roles $roles;
  67.         return $this;
  68.     }
  69.     /**
  70.      * @see PasswordAuthenticatedUserInterface
  71.      */
  72.     public function getPassword(): string
  73.     {
  74.         return $this->password;
  75.     }
  76.     public function setPassword(string $password): self
  77.     {
  78.         $this->password $password;
  79.         return $this;
  80.     }
  81.     /**
  82.      * @see UserInterface
  83.      */
  84.     public function eraseCredentials()
  85.     {
  86.         // If you store any temporary, sensitive data on the user, clear it here
  87.         // $this->plainPassword = null;
  88.     }
  89. }