UsernameNotFoundException.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * @param string $username
  40. */
  41. public function setUsername($username)
  42. {
  43. $this->username = $username;
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function serialize()
  49. {
  50. return serialize(array(
  51. $this->username,
  52. parent::serialize(),
  53. ));
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function unserialize($str)
  59. {
  60. list($this->username, $parentData) = unserialize($str);
  61. parent::unserialize($parentData);
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function getMessageData()
  67. {
  68. return array('{{ username }}' => $this->username);
  69. }
  70. }