src/Entity/User.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. #[ORM\Entity(repositoryClassUserRepository::class)]
  9. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length180uniquetrue)]
  17.     private $email;
  18.     #[ORM\Column(type'json')]
  19.     private $roles = [];
  20.     #[ORM\Column(type'string')]
  21.     private $password;
  22.     #[ORM\Column(type'string'length255)]
  23.     private $display_name;
  24.     #[ORM\Column(type'boolean')]
  25.     private $isVerified false;
  26.     #[ORM\Column(length255)]
  27.     private ?string $username null;
  28.     #[ORM\Column(nullabletrue)]
  29.     private ?bool $active null;
  30.     #[ORM\OneToOne(cascade: ['persist''remove'])]
  31.     private ?Client $client null;
  32.     public function __construct()
  33.     {
  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.     public function getRole(): string
  73.     {
  74.         if ($this->roles && count($this->roles) > 0) {
  75.             $role $this->roles[0];
  76.             $role str_replace("ROLE_"""$role);
  77.             //$role = str_replace("_"," ", $role);
  78.             return $role;
  79.         }
  80.         return '';
  81.     }
  82.     /**
  83.      * @see PasswordAuthenticatedUserInterface
  84.      * @return string|null
  85.      */
  86.     public function getPassword(): ?string
  87.     {
  88.         return $this->password;
  89.     }
  90.     public function setPassword(string $password): self
  91.     {
  92.         $this->password $password;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @see UserInterface
  97.      */
  98.     public function eraseCredentials()
  99.     {
  100.         // If you store any temporary, sensitive data on the user, clear it here
  101.         // $this->plainPassword = null;
  102.     }
  103.     public function getDisplayName(): ?string
  104.     {
  105.         return $this->display_name;
  106.     }
  107.     public function setDisplayName(string $display_name): self
  108.     {
  109.         $this->display_name $display_name;
  110.         return $this;
  111.     }
  112.     public function isVerified(): bool
  113.     {
  114.         return $this->isVerified;
  115.     }
  116.     public function setIsVerified(bool $isVerified): self
  117.     {
  118.         $this->isVerified $isVerified;
  119.         return $this;
  120.     }
  121.     public function getUsername(): ?string
  122.     {
  123.         return $this->username;
  124.     }
  125.     public function setUsername(string $username): self
  126.     {
  127.         $this->username $username;
  128.         return $this;
  129.     }
  130.     public function isActive(): ?bool
  131.     {
  132.         return $this->active;
  133.     }
  134.     public function setActive(?bool $active): self
  135.     {
  136.         $this->active $active;
  137.         return $this;
  138.     }
  139.     public function getClient(): ?Client
  140.     {
  141.         return $this->client;
  142.     }
  143.     public function setClient(?Client $client): self
  144.     {
  145.         $this->client $client;
  146.         return $this;
  147.     }
  148. }