Advertisement
Guest User

Untitled

a guest
Oct 17th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. <?php
  2.  
  3. namespace XXX\AppBundle\Model\Entity;
  4.  
  5. use XXX\AppBundle\Model\Entity\Server\Logging;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8.  
  9. /**
  10. * User
  11. */
  12. class User implements UserInterface
  13. {
  14. /**
  15. * @var integer $id
  16. */
  17. protected $id;
  18.  
  19. /**
  20. * @var string $username
  21. */
  22. protected $username;
  23.  
  24. /**
  25. * @var string $email
  26. */
  27. protected $email;
  28.  
  29. /**
  30. * @var string $password
  31. */
  32. protected $password;
  33.  
  34. /**
  35. * @var array $roles
  36. */
  37. protected $roles = array();
  38.  
  39. /**
  40. * @var \Doctrine\Common\Collections\Collection $logEvents
  41. */
  42. protected $logEvents;
  43.  
  44. /**
  45. * @return int
  46. */
  47. public function getId()
  48. {
  49. return $this->id;
  50. }
  51.  
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function getUsername()
  56. {
  57. return $this->username;
  58. }
  59.  
  60. /**
  61. * @param string $username
  62. * @return $this
  63. */
  64. public function setUsername($username)
  65. {
  66. $this->username = $username;
  67. return $this;
  68. }
  69.  
  70. /**
  71. * @return string
  72. */
  73. public function getEmail()
  74. {
  75. return $this->email;
  76. }
  77.  
  78. /**
  79. * @param string $email
  80. * @return $this
  81. */
  82. public function setEmail($email)
  83. {
  84. $this->email = $email;
  85. return $this;
  86. }
  87.  
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function getPassword()
  92. {
  93. return $this->password;
  94. }
  95.  
  96. /**
  97. * @param string $password
  98. * @return $this
  99. */
  100. public function setPassword($password)
  101. {
  102. $this->password = $password;
  103. return $this;
  104. }
  105.  
  106. /**
  107. * Returns the roles or permissions granted to the user for security.
  108. */
  109. public function getRoles()
  110. {
  111. $roles = $this->roles;
  112.  
  113. // guarantees that a user always has at least one role for security
  114. if (empty($roles)) {
  115. $roles[] = 'ROLE_USER';
  116. }
  117.  
  118. return array_unique($roles);
  119. }
  120.  
  121. public function setRoles(array $roles)
  122. {
  123. $this->roles = $roles;
  124. }
  125.  
  126. /**
  127. * Returns the salt that was originally used to encode the password.
  128. */
  129. public function getSalt()
  130. {
  131. // See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html
  132. // we're using bcrypt in security.yml to encode the password, so
  133. // the salt value is built-in and you don't have to generate one
  134.  
  135. return;
  136. }
  137.  
  138. /**
  139. * Removes sensitive data from the user.
  140. */
  141. public function eraseCredentials()
  142. {
  143. $this->password = null;
  144. $this->email = null;
  145. }
  146.  
  147. /**
  148. * Appends an entry to administration log
  149. *
  150. * @param \XXX\AppBundle\Model\Entity\Server\Logging $logEvent
  151. * @return $this
  152. */
  153. public function appendLog(Server\Logging $logEvent)
  154. {
  155. if (!$this->logEvents->contains($logEvent))
  156. {
  157. $this->logEvents->add($logEvent);
  158. }
  159.  
  160. return $this;
  161. }
  162.  
  163. /**
  164. * Remove a log entry from the history
  165. *
  166. * @param \XXX\AppBundle\Model\Entity\Server\Logging $logEvent
  167. * @return $this
  168. */
  169. public function clearLogEntry(Server\Logging $logEvent)
  170. {
  171. $this->logEvents->removeElement($logEvent);
  172.  
  173. return $this;
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement