Recaller.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Illuminate\Auth;
  3. use Illuminate\Support\Str;
  4. class Recaller
  5. {
  6. /**
  7. * The "recaller" / "remember me" cookie string.
  8. *
  9. * @var string
  10. */
  11. protected $recaller;
  12. /**
  13. * Create a new recaller instance.
  14. *
  15. * @param string $recaller
  16. * @return void
  17. */
  18. public function __construct($recaller)
  19. {
  20. $this->recaller = $recaller;
  21. }
  22. /**
  23. * Get the user ID from the recaller.
  24. *
  25. * @return string
  26. */
  27. public function id()
  28. {
  29. return explode('|', $this->recaller, 3)[0];
  30. }
  31. /**
  32. * Get the "remember token" token from the recaller.
  33. *
  34. * @return string
  35. */
  36. public function token()
  37. {
  38. return explode('|', $this->recaller, 3)[1];
  39. }
  40. /**
  41. * Get the password from the recaller.
  42. *
  43. * @return string
  44. */
  45. public function hash()
  46. {
  47. return explode('|', $this->recaller, 3)[2];
  48. }
  49. /**
  50. * Determine if the recaller is valid.
  51. *
  52. * @return bool
  53. */
  54. public function valid()
  55. {
  56. return $this->properString() && $this->hasAllSegments();
  57. }
  58. /**
  59. * Determine if the recaller is an invalid string.
  60. *
  61. * @return bool
  62. */
  63. protected function properString()
  64. {
  65. return is_string($this->recaller) && Str::contains($this->recaller, '|');
  66. }
  67. /**
  68. * Determine if the recaller has all segments.
  69. *
  70. * @return bool
  71. */
  72. protected function hasAllSegments()
  73. {
  74. $segments = explode('|', $this->recaller);
  75. return count($segments) == 3 && trim($segments[0]) !== '' && trim($segments[1]) !== '';
  76. }
  77. }