Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79ec09a

Browse files
committed
[Cookbook] [Security] Use UserLoaderInterface instead of UserProviderInterface
1 parent3ebf2d0 commit79ec09a

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

‎cookbook/security/entity_provider.rst

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -424,20 +424,18 @@ both are unique in the database. Unfortunately, the native entity provider
424424
is only able to handle querying via a single property on the user.
425425

426426
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\\UserLoaderInterface`. This
428+
interface only requires one method: ``loadUserByUsername($username)``::
430429

431430
// src/AppBundle/Entity/UserRepository.php
432431
namespace AppBundle\Entity;
433432

433+
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
434434
use Symfony\Component\Security\Core\User\UserInterface;
435-
use Symfony\Component\Security\Core\User\UserProviderInterface;
436435
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
437-
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
438436
use Doctrine\ORM\EntityRepository;
439437

440-
class UserRepository extends EntityRepository implementsUserProviderInterface
438+
class UserRepository extends EntityRepository implementsUserLoaderInterface
441439
{
442440
public function loadUserByUsername($username)
443441
{
@@ -458,30 +456,12 @@ interface requires three methods: ``loadUserByUsername($username)``,
458456

459457
return $user;
460458
}
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-
}
482459
}
483460

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``.
485465

486466
..tip::
487467

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp