From 79ec09a01bc3c19cf698b1048de7ba40ef888193 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Wed, 9 Dec 2015 22:32:16 +0100 Subject: [PATCH] [Cookbook] [Security] Use UserLoaderInterface instead of UserProviderInterface --- cookbook/security/entity_provider.rst | 36 ++++++--------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/cookbook/security/entity_provider.rst b/cookbook/security/entity_provider.rst index 58acf646245..425272b9b8d 100644 --- a/cookbook/security/entity_provider.rst +++ b/cookbook/security/entity_provider.rst @@ -424,20 +424,18 @@ both are unique in the database. Unfortunately, the native entity provider is only able to handle querying via a single property on the user. To do this, make your ``UserRepository`` implement a special -:class:`Symfony\\Component\\Security\\Core\\User\\UserProviderInterface`. This -interface requires three methods: ``loadUserByUsername($username)``, -``refreshUser(UserInterface $user)``, and ``supportsClass($class)``:: +:class:`Symfony\\Bridge\\Doctrine\\Security\\User\\UserLoaderInterface`. This +interface only requires one method: ``loadUserByUsername($username)``:: // src/AppBundle/Entity/UserRepository.php namespace AppBundle\Entity; + use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; use Symfony\Component\Security\Core\User\UserInterface; - use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; - use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Doctrine\ORM\EntityRepository; - class UserRepository extends EntityRepository implements UserProviderInterface + class UserRepository extends EntityRepository implements UserLoaderInterface { public function loadUserByUsername($username) { @@ -458,30 +456,12 @@ interface requires three methods: ``loadUserByUsername($username)``, return $user; } - - public function refreshUser(UserInterface $user) - { - $class = get_class($user); - if (!$this->supportsClass($class)) { - throw new UnsupportedUserException( - sprintf( - 'Instances of "%s" are not supported.', - $class - ) - ); - } - - return $this->find($user->getId()); - } - - public function supportsClass($class) - { - return $this->getEntityName() === $class - || is_subclass_of($class, $this->getEntityName()); - } } -For more details on these methods, see :class:`Symfony\\Component\\Security\\Core\\User\\UserProviderInterface`. +.. versionadded:: 2.8 + The :class:`Symfony\\Bridge\\Doctrine\\Security\\User\\UserLoaderInterface` + interface was introduced in 2.8. Prior to Symfony 2.8, you had to implement + ``Symfony\Component\Security\Core\User\UserProviderInterface``. .. tip::