yoesoff

User Entitiy

Aug 7th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Entity;
  4.  
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use Doctrine\ORM\Mapping as ORM;
  7.  
  8. /**
  9.  * @ApiResource()
  10.  * @ORM\Table(name="app_users")
  11.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  12.  */
  13. class User
  14. {
  15.     /**
  16.      * @ORM\Id()
  17.      * @ORM\GeneratedValue()
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.  
  22.     /**
  23.      * @ORM\Column(type="string", length=100)
  24.      */
  25.     private $username;
  26.  
  27.     /**
  28.      * @ORM\Column(type="string", length=100)
  29.      */
  30.     private $password;
  31.  
  32.     /**
  33.      * @ORM\Column(type="string", length=255)
  34.      */
  35.     private $email;
  36.  
  37.     /**
  38.      * @ORM\Column(type="boolean")
  39.      */
  40.     private $isActive;
  41.  
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.  
  47.     public function getUsername(): ?string
  48.     {
  49.         return $this->username;
  50.     }
  51.  
  52.     public function setUsername(string $username): self
  53.     {
  54.         $this->username = $username;
  55.  
  56.         return $this;
  57.     }
  58.  
  59.     public function getPassword(): ?string
  60.     {
  61.         return $this->password;
  62.     }
  63.  
  64.     public function setPassword(string $password): self
  65.     {
  66.         $this->password = $password;
  67.  
  68.         return $this;
  69.     }
  70.  
  71.     public function getEmail(): ?string
  72.     {
  73.         return $this->email;
  74.     }
  75.  
  76.     public function setEmail(string $email): self
  77.     {
  78.         $this->email = $email;
  79.  
  80.         return $this;
  81.     }
  82.  
  83.     public function getIsActive(): ?bool
  84.     {
  85.         return $this->isActive;
  86.     }
  87.  
  88.     public function setIsActive(bool $isActive): self
  89.     {
  90.         $this->isActive = $isActive;
  91.  
  92.         return $this;
  93.     }
  94.  
  95.     public function __construct()
  96.     {
  97.         $this->isActive = true;
  98.         // may not be needed, see section on salt below
  99.         // $this->salt = md5(uniqid('', true));
  100.     }
  101.  
  102.     public function getSalt()
  103.     {
  104.         // you *may* need a real salt depending on your encoder
  105.         // see section on salt below
  106.         return null;
  107.     }
  108.  
  109.     public function getRoles()
  110.     {
  111.         return array('ROLE_USER');
  112.     }
  113.  
  114.     public function eraseCredentials()
  115.     {
  116.     }
  117.  
  118.     /** @see \Serializable::serialize() */
  119.     public function serialize()
  120.     {
  121.         return serialize(array(
  122.             $this->id,
  123.             $this->username,
  124.             $this->password,
  125.             // see section on salt below
  126.             // $this->salt,
  127.         ));
  128.     }
  129.  
  130.     /** @see \Serializable::unserialize() */
  131.     public function unserialize($serialized)
  132.     {
  133.         list (
  134.             $this->id,
  135.             $this->username,
  136.             $this->password,
  137.             // see section on salt below
  138.             // $this->salt
  139.         ) = unserialize($serialized, array('allowed_classes' => false));
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment