src/Entity/User.php line 21

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. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserRepository::class)
  11.  *
  12.  * @ORM\Table(name="`user`")
  13.  *
  14.  * @UniqueEntity(
  15.  *     fields={"email"},
  16.  * )
  17.  */
  18. class User implements UserInterfacePasswordAuthenticatedUserInterface
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      *
  23.      * @ORM\GeneratedValue(strategy="AUTO")
  24.      *
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=180, unique=true)
  30.      *
  31.      * @Assert\Email(
  32.      *     message="L'indirizzo email '{{ value }}' non รจ valido.",
  33.      *     mode="html5"
  34.      * )
  35.      */
  36.     private $email;
  37.     /**
  38.      * @ORM\Column(type="json")
  39.      */
  40.     private $roles = [];
  41.     /**
  42.      * @var string The hashed password
  43.      *
  44.      * @ORM\Column(type="string")
  45.      */
  46.     private $password;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      */
  50.     private $name;
  51.     /**
  52.      * @ORM\Column(type="string", length=255)
  53.      */
  54.     private $surname;
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function setId(int $id): self
  60.     {
  61.         $this->id $id;
  62.         return $this;
  63.     }
  64.     public function getEmail(): ?string
  65.     {
  66.         return $this->email;
  67.     }
  68.     public function setEmail(string $email): self
  69.     {
  70.         $this->email $email;
  71.         return $this;
  72.     }
  73.     /**
  74.      * A visual identifier that represents this user.
  75.      *
  76.      * @see UserInterface
  77.      */
  78.     public function getUserIdentifier(): string
  79.     {
  80.         return (string) $this->email;
  81.     }
  82.     /**
  83.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  84.      */
  85.     public function getUsername(): string
  86.     {
  87.         return (string) $this->email;
  88.     }
  89.     /**
  90.      * @see UserInterface
  91.      */
  92.     public function getRoles(): array
  93.     {
  94.         $roles $this->roles;
  95.         // guarantee every user at least has ROLE_USER
  96.         $roles[] = 'ROLE_USER';
  97.         return array_unique($roles);
  98.     }
  99.     public function setRoles(array $roles): self
  100.     {
  101.         $this->roles $roles;
  102.         return $this;
  103.     }
  104.     /**
  105.      * @see PasswordAuthenticatedUserInterface
  106.      */
  107.     public function getPassword(): string
  108.     {
  109.         return $this->password;
  110.     }
  111.     public function setPassword(string $password): self
  112.     {
  113.         $this->password $password;
  114.         return $this;
  115.     }
  116.     /**
  117.      * Returning a salt is only needed, if you are not using a modern
  118.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  119.      *
  120.      * @see UserInterface
  121.      */
  122.     public function getSalt(): ?string
  123.     {
  124.         return null;
  125.     }
  126.     /**
  127.      * @see UserInterface
  128.      */
  129.     public function eraseCredentials()
  130.     {
  131.         // If you store any temporary, sensitive data on the user, clear it here
  132.         // $this->plainPassword = null;
  133.     }
  134.     public function getName(): ?string
  135.     {
  136.         return $this->name;
  137.     }
  138.     public function setName(string $name): self
  139.     {
  140.         $this->name $name;
  141.         return $this;
  142.     }
  143.     public function getSurname(): ?string
  144.     {
  145.         return $this->surname;
  146.     }
  147.     public function setSurname(string $surname): self
  148.     {
  149.         $this->surname $surname;
  150.         return $this;
  151.     }
  152.     public function getFullName(): ?string
  153.     {
  154.         return $this->name.' '.$this->surname;
  155.     }
  156. }