Advertisement
Guest User

User

a guest
Aug 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Entity;
  4.  
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8.  
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  11.  * @ORM\Table(name="user")
  12.  */
  13. class User implements UserInterface, \JsonSerializable
  14. {
  15.     /**
  16.      * @ORM\Id()
  17.      * @ORM\GeneratedValue()
  18.      * @ORM\Column(type="integer")
  19.      * @var int|null $id
  20.      */
  21.     private $id;
  22.  
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      * @var string $email
  26.      */
  27.     private $email;
  28.  
  29.     /**
  30.      * @ORM\Column(type="string", length=180, unique=true)
  31.      * @var string $username
  32.      */
  33.     private $username;
  34.  
  35.     /**
  36.      * @var string The hashed password
  37.      * @ORM\Column(type="string")
  38.      */
  39.     private $password;
  40.  
  41.     /**
  42.      * @ORM\ManyToMany(targetEntity="App\Entity\Role", inversedBy="users")
  43.      * @ORM\JoinTable(name="user_role", joinColumns={
  44.      *      @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  45.      *  }, inverseJoinColumns={
  46.      *      @ORM\JoinColumn(name="role_id", referencedColumnName="id")
  47.      *  })
  48.      * @var Role[]|null $roles
  49.      */
  50.     private $roles;
  51.  
  52.     public function __construct()
  53.     {
  54.         $this->roles = new ArrayCollection();
  55.     }
  56.  
  57.     /**
  58.      * @return int|null
  59.      */
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.  
  65.     /**
  66.      * @param int|null $id
  67.      */
  68.     public function setId(?int $id): void
  69.     {
  70.         $this->id = $id;
  71.     }
  72.  
  73.     /**
  74.      * @return string
  75.      */
  76.     public function getEmail(): string
  77.     {
  78.         return $this->email;
  79.     }
  80.  
  81.     /**
  82.      * @param string $email
  83.      */
  84.     public function setEmail(string $email): void
  85.     {
  86.         $this->email = $email;
  87.     }
  88.  
  89.     /**
  90.      * A visual identifier that represents this user.
  91.      *
  92.      * @see UserInterface
  93.      */
  94.     public function getUsername(): string
  95.     {
  96.         return (string) $this->username;
  97.     }
  98.  
  99.     /**
  100.      * @see UserInterface
  101.      */
  102.     public function getRoles()
  103.     {
  104.         return $this->roles;
  105.     }
  106.  
  107.     /**
  108.      * @see UserInterface
  109.      */
  110.     public function getPassword(): string
  111.     {
  112.         return (string) $this->password;
  113.     }
  114.  
  115.     /**
  116.      * @param string $password
  117.      * @return User
  118.      */
  119.     public function setPassword(string $password): void
  120.     {
  121.         $this->password = $password;
  122.     }
  123.  
  124.     /**
  125.      * @see UserInterface
  126.      */
  127.     public function getSalt()
  128.     {
  129.         // not needed when using the "bcrypt" algorithm in security.yaml
  130.     }
  131.  
  132.     /**
  133.      * @see UserInterface
  134.      */
  135.     public function eraseCredentials()
  136.     {
  137.         // If you store any temporary, sensitive data on the user, clear it here
  138.         // $this->plainPassword = null;
  139.     }
  140.  
  141.     /**
  142.      * @return array|mixed
  143.      */
  144.     public function jsonSerialize()
  145.     {
  146.         return [
  147.             'id' => $this->getId(),
  148.             'email' => $this->getEmail(),
  149.             'username' => $this->getUsername(),
  150.             'roles' => $this->getRoles()
  151.         ];
  152.     }
  153.  
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement