Guest User

Untitled

a guest
Feb 4th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2. // src/Entity/User.php
  3.  
  4. declare(strict_types=1);
  5.  
  6. namespace App\Entity;
  7.  
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Ramsey\Uuid\Uuid;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12.  
  13. /**
  14. * @ApiResource
  15. * @ORM\Entity
  16. * @ORM\Table(name="users")
  17. * @ApiResource
  18. */
  19. final class User implements UserInterface
  20. {
  21. /**
  22. * @var Uuid
  23. *
  24. * @ORM\Id
  25. * @ORM\Column(name="id", type="uuid", unique=true, nullable=false)
  26. */
  27. private $id;
  28.  
  29. /**
  30. * @var string
  31. *
  32. * @ORM\Column(name="username", type="string", length=255, unique=true, nullable=false)
  33. */
  34. private $username;
  35.  
  36. /**
  37. * @var string
  38. *
  39. * @ORM\Column(name="password", type="string", length=255, nullable=false)
  40. */
  41. private $password;
  42.  
  43. /**
  44. * @var string
  45. *
  46. * @ORM\Column(name="enabled", type="boolean", nullable=false)
  47. */
  48. private $enabled;
  49.  
  50. /**
  51. * @var array
  52. *
  53. * @ORM\Column(name="roles", type="json_array", nullable=false)
  54. */
  55. private $roles;
  56.  
  57. /**
  58. * User constructor.
  59. * @param string $username
  60. * @param string $password
  61. * @param array $roles
  62. * @param bool $enabled
  63. * @throws \Exception
  64. */
  65. public function __construct(string $username, string $password, array $roles = [], bool $enabled = true)
  66. {
  67. $this->id = Uuid::uuid4();
  68. $this->username = $username;
  69. $this->password = $password;
  70. $this->enabled = $enabled;
  71. $this->roles = $roles;
  72. }
  73.  
  74. public function getId(): Uuid
  75. {
  76. return $this->id;
  77. }
  78.  
  79. public function getUsername(): string
  80. {
  81. return $this->username;
  82. }
  83.  
  84. public function setUsername(string $username): void
  85. {
  86. $this->username = $username;
  87. }
  88.  
  89. public function getPassword(): string
  90. {
  91. return $this->password;
  92. }
  93.  
  94. public function setPassword(string $password): void
  95. {
  96. $this->password = $password;
  97. }
  98.  
  99. public function isEnabled(): bool
  100. {
  101. return $this->enabled;
  102. }
  103.  
  104. public function setEnabled(bool $enabled): void
  105. {
  106. $this->enabled = $enabled;
  107. }
  108.  
  109. public function getRoles(): array
  110. {
  111. return $this->roles;
  112. }
  113.  
  114. public function setRoles(array $roles): void
  115. {
  116. $this->roles = $roles;
  117. }
  118.  
  119. public function getSalt(): string
  120. {
  121. return '';
  122. }
  123.  
  124. public function eraseCredentials()
  125. {
  126. return null;
  127. }
  128. }
Add Comment
Please, Sign In to add comment