Skip to content

Commit 420d3db

Browse files
committed
minor #14307 Update user_provider.rst (Yoann-TYT)
This PR was merged into the 4.4 branch. Discussion ---------- Update user_provider.rst ServiceEntityRepository instead of EntityRepository ( Using a Custom Query to Load the User ) Commits ------- fbf5348 Update user_provider.rst
2 parents 55190a8 + fbf5348 commit 420d3db

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

security/user_provider.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,24 @@ interface only requires one method: ``loadUserByUsername($username)``::
128128
// src/Repository/UserRepository.php
129129
namespace App\Repository;
130130

131-
use Doctrine\ORM\EntityRepository;
131+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
132132
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
133133

134-
class UserRepository extends EntityRepository implements UserLoaderInterface
134+
class UserRepository extends ServiceEntityRepository implements UserLoaderInterface
135135
{
136136
// ...
137137

138138
public function loadUserByUsername($usernameOrEmail)
139139
{
140-
return $this->createQuery(
140+
$entityManager = $this->getEntityManager();
141+
142+
return $entityManager->createQuery(
141143
'SELECT u
142144
FROM App\Entity\User u
143145
WHERE u.username = :query
144146
OR u.email = :query'
145147
)
146148
->setParameter('query', $usernameOrEmail)
147-
->getQuery()
148149
->getOneOrNullResult();
149150
}
150151
}

0 commit comments

Comments
 (0)