UsernameNotFoundException.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\Exception;
  11. /**
  12. * UsernameNotFoundException is thrown if a User cannot be found by its username.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. * @author Alexander <iam.asm89@gmail.com>
  16. */
  17. class UsernameNotFoundException extends AuthenticationException
  18. {
  19. private $username;
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function getMessageKey()
  24. {
  25. return 'Username could not be found.';
  26. }
  27. /**
  28. * Get the username.
  29. *
  30. * @return string
  31. */
  32. public function getUsername()
  33. {
  34. return $this->username;
  35. }
  36. /**
  37. * Set the username.
  38. */
  39. public function setUsername(string $username)
  40. {
  41. $this->username = $username;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function getMessageData()
  47. {
  48. return ['{{ username }}' => $this->username];
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function __serialize(): array
  54. {
  55. return [$this->username, parent::__serialize()];
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function __unserialize(array $data): void
  61. {
  62. [$this->username, $parentData] = $data;
  63. $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
  64. parent::__unserialize($parentData);
  65. }
  66. }