NullToken.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\Authentication\Token;
  11. /**
  12. * @author Wouter de Jong <wouter@wouterj.nl>
  13. */
  14. class NullToken implements TokenInterface
  15. {
  16. public function __toString(): string
  17. {
  18. return '';
  19. }
  20. public function getRoleNames(): array
  21. {
  22. return [];
  23. }
  24. public function getCredentials()
  25. {
  26. return '';
  27. }
  28. public function getUser()
  29. {
  30. return null;
  31. }
  32. public function setUser($user)
  33. {
  34. throw new \BadMethodCallException('Cannot set user on a NullToken.');
  35. }
  36. public function getUsername()
  37. {
  38. return '';
  39. }
  40. public function isAuthenticated()
  41. {
  42. return true;
  43. }
  44. public function setAuthenticated(bool $isAuthenticated)
  45. {
  46. throw new \BadMethodCallException('Cannot change authentication state of NullToken.');
  47. }
  48. public function eraseCredentials()
  49. {
  50. }
  51. public function getAttributes()
  52. {
  53. return [];
  54. }
  55. public function setAttributes(array $attributes)
  56. {
  57. throw new \BadMethodCallException('Cannot set attributes of NullToken.');
  58. }
  59. public function hasAttribute(string $name)
  60. {
  61. return false;
  62. }
  63. public function getAttribute(string $name)
  64. {
  65. return null;
  66. }
  67. public function setAttribute(string $name, $value)
  68. {
  69. throw new \BadMethodCallException('Cannot add attribute to NullToken.');
  70. }
  71. public function __serialize(): array
  72. {
  73. return [];
  74. }
  75. public function __unserialize(array $data): void
  76. {
  77. }
  78. /**
  79. * @return string
  80. */
  81. public function serialize()
  82. {
  83. return '';
  84. }
  85. /**
  86. * @return void
  87. */
  88. public function unserialize($serialized)
  89. {
  90. }
  91. }