You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AccessToken.php 1.2 KiB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the overtrue/socialite.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Overtrue\Socialite;
  11. use ArrayAccess;
  12. use InvalidArgumentException;
  13. use JsonSerializable;
  14. /**
  15. * Class AccessToken.
  16. */
  17. class AccessToken implements AccessTokenInterface, ArrayAccess, JsonSerializable
  18. {
  19. use HasAttributes;
  20. /**
  21. * AccessToken constructor.
  22. *
  23. * @param array $attributes
  24. */
  25. public function __construct(array $attributes)
  26. {
  27. if (empty($attributes['access_token'])) {
  28. throw new InvalidArgumentException('The key "access_token" could not be empty.');
  29. }
  30. $this->attributes = $attributes;
  31. }
  32. /**
  33. * Return the access token string.
  34. *
  35. * @return string
  36. */
  37. public function getToken()
  38. {
  39. return $this->getAttribute('access_token');
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function __toString()
  45. {
  46. return strval($this->getAttribute('access_token', ''));
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function jsonSerialize()
  52. {
  53. return $this->getToken();
  54. }
  55. }