GenericUser.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace Illuminate\Auth;
  3. use Illuminate\Contracts\Auth\Authenticatable as UserContract;
  4. class GenericUser implements UserContract
  5. {
  6. /**
  7. * All of the user's attributes.
  8. *
  9. * @var array
  10. */
  11. protected $attributes;
  12. /**
  13. * Create a new generic User object.
  14. *
  15. * @param array $attributes
  16. * @return void
  17. */
  18. public function __construct(array $attributes)
  19. {
  20. $this->attributes = $attributes;
  21. }
  22. /**
  23. * Get the name of the unique identifier for the user.
  24. *
  25. * @return string
  26. */
  27. public function getAuthIdentifierName()
  28. {
  29. return 'id';
  30. }
  31. /**
  32. * Get the unique identifier for the user.
  33. *
  34. * @return mixed
  35. */
  36. public function getAuthIdentifier()
  37. {
  38. $name = $this->getAuthIdentifierName();
  39. return $this->attributes[$name];
  40. }
  41. /**
  42. * Get the password for the user.
  43. *
  44. * @return string
  45. */
  46. public function getAuthPassword()
  47. {
  48. return $this->attributes['password'];
  49. }
  50. /**
  51. * Get the "remember me" token value.
  52. *
  53. * @return string
  54. */
  55. public function getRememberToken()
  56. {
  57. return $this->attributes[$this->getRememberTokenName()];
  58. }
  59. /**
  60. * Set the "remember me" token value.
  61. *
  62. * @param string $value
  63. * @return void
  64. */
  65. public function setRememberToken($value)
  66. {
  67. $this->attributes[$this->getRememberTokenName()] = $value;
  68. }
  69. /**
  70. * Get the column name for the "remember me" token.
  71. *
  72. * @return string
  73. */
  74. public function getRememberTokenName()
  75. {
  76. return 'remember_token';
  77. }
  78. /**
  79. * Dynamically access the user's attributes.
  80. *
  81. * @param string $key
  82. * @return mixed
  83. */
  84. public function __get($key)
  85. {
  86. return $this->attributes[$key];
  87. }
  88. /**
  89. * Dynamically set an attribute on the user.
  90. *
  91. * @param string $key
  92. * @param mixed $value
  93. * @return void
  94. */
  95. public function __set($key, $value)
  96. {
  97. $this->attributes[$key] = $value;
  98. }
  99. /**
  100. * Dynamically check if a value is set on the user.
  101. *
  102. * @param string $key
  103. * @return bool
  104. */
  105. public function __isset($key)
  106. {
  107. return isset($this->attributes[$key]);
  108. }
  109. /**
  110. * Dynamically unset a value on the user.
  111. *
  112. * @param string $key
  113. * @return void
  114. */
  115. public function __unset($key)
  116. {
  117. unset($this->attributes[$key]);
  118. }
  119. }