@@ -424,20 +424,18 @@ both are unique in the database. Unfortunately, the native entity provider
424
424
is only able to handle querying via a single property on the user.
425
425
426
426
To do this, make your ``UserRepository `` implement a special
427
- :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserProviderInterface `. This
428
- interface requires three methods: ``loadUserByUsername($username) ``,
429
- ``refreshUser(UserInterface $user) ``, and ``supportsClass($class) ``::
427
+ :class: `Symfony\\ Bridge\\ Doctrine\\ Security\\ User\U serLoaderInterface `. This
428
+ interface only requires one method: ``loadUserByUsername($username) ``::
430
429
431
430
// src/AppBundle/Entity/UserRepository.php
432
431
namespace AppBundle\Entity;
433
432
433
+ use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
434
434
use Symfony\Component\Security\Core\User\UserInterface;
435
- use Symfony\Component\Security\Core\User\UserProviderInterface;
436
435
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
437
- use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
438
436
use Doctrine\ORM\EntityRepository;
439
437
440
- class UserRepository extends EntityRepository implements UserProviderInterface
438
+ class UserRepository extends EntityRepository implements UserLoaderInterface
441
439
{
442
440
public function loadUserByUsername($username)
443
441
{
@@ -458,30 +456,13 @@ interface requires three methods: ``loadUserByUsername($username)``,
458
456
459
457
return $user;
460
458
}
461
-
462
- public function refreshUser(UserInterface $user)
463
- {
464
- $class = get_class($user);
465
- if (!$this->supportsClass($class)) {
466
- throw new UnsupportedUserException(
467
- sprintf(
468
- 'Instances of "%s" are not supported.',
469
- $class
470
- )
471
- );
472
- }
473
-
474
- return $this->find($user->getId());
475
- }
476
-
477
- public function supportsClass($class)
478
- {
479
- return $this->getEntityName() === $class
480
- || is_subclass_of($class, $this->getEntityName());
481
- }
482
459
}
483
460
484
- For more details on these methods, see :class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserProviderInterface `.
461
+ .. versionadded :: 2.8
462
+ The :class: `Symfony\\ Bridge\\ Doctrine\\ Security\\ User\\ UserLoaderInterface `
463
+ interface was introduced in 2.8. Prior to Symfony 2.8, you had to implement
464
+ `Symfony\\Component\\Security\\Core\User\\UserProviderInterface ` requiring you
465
+ to implement three methods, where only one was useful.
485
466
486
467
.. tip ::
487
468
0 commit comments