UserProviderInterface.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\User;
  11. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  12. use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
  13. /**
  14. * Represents a class that loads UserInterface objects from some source for the authentication system.
  15. *
  16. * In a typical authentication configuration, a username (i.e. some unique
  17. * user identifier) credential enters the system (via form login, or any
  18. * method). The user provider that is configured with that authentication
  19. * method is asked to load the UserInterface object for the given username
  20. * (via loadUserByUsername) so that the rest of the process can continue.
  21. *
  22. * Internally, a user provider can load users from any source (databases,
  23. * configuration, web service). This is totally independent of how the authentication
  24. * information is submitted or what the UserInterface object looks like.
  25. *
  26. * @see UserInterface
  27. *
  28. * @author Fabien Potencier <fabien@symfony.com>
  29. */
  30. interface UserProviderInterface
  31. {
  32. /**
  33. * Loads the user for the given username.
  34. *
  35. * This method must throw UsernameNotFoundException if the user is not
  36. * found.
  37. *
  38. * @return UserInterface
  39. *
  40. * @throws UsernameNotFoundException if the user is not found
  41. */
  42. public function loadUserByUsername(string $username);
  43. /**
  44. * Refreshes the user.
  45. *
  46. * It is up to the implementation to decide if the user data should be
  47. * totally reloaded (e.g. from the database), or if the UserInterface
  48. * object can just be merged into some internal array of users / identity
  49. * map.
  50. *
  51. * @return UserInterface
  52. *
  53. * @throws UnsupportedUserException if the user is not supported
  54. * @throws UsernameNotFoundException if the user is not found
  55. */
  56. public function refreshUser(UserInterface $user);
  57. /**
  58. * Whether this provider supports the given user class.
  59. *
  60. * @return bool
  61. */
  62. public function supportsClass(string $class);
  63. }