User.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Core\User;
  11. /**
  12. * User is the user implementation used by the in-memory user provider.
  13. *
  14. * This should not be used for anything else.
  15. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. final class User implements AdvancedUserInterface
  19. {
  20. private $username;
  21. private $password;
  22. private $enabled;
  23. private $accountNonExpired;
  24. private $credentialsNonExpired;
  25. private $accountNonLocked;
  26. private $roles;
  27. public function __construct($username, $password, array $roles = array(), $enabled = true, $userNonExpired = true, $credentialsNonExpired = true, $userNonLocked = true)
  28. {
  29. if ('' === $username || null === $username) {
  30. throw new \InvalidArgumentException('The username cannot be empty.');
  31. }
  32. $this->username = $username;
  33. $this->password = $password;
  34. $this->enabled = $enabled;
  35. $this->accountNonExpired = $userNonExpired;
  36. $this->credentialsNonExpired = $credentialsNonExpired;
  37. $this->accountNonLocked = $userNonLocked;
  38. $this->roles = $roles;
  39. }
  40. public function __toString()
  41. {
  42. return $this->getUsername();
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function getRoles()
  48. {
  49. return $this->roles;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getPassword()
  55. {
  56. return $this->password;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function getSalt()
  62. {
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function getUsername()
  68. {
  69. return $this->username;
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function isAccountNonExpired()
  75. {
  76. return $this->accountNonExpired;
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function isAccountNonLocked()
  82. {
  83. return $this->accountNonLocked;
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function isCredentialsNonExpired()
  89. {
  90. return $this->credentialsNonExpired;
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function isEnabled()
  96. {
  97. return $this->enabled;
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function eraseCredentials()
  103. {
  104. }
  105. }