Skip to content

Commit

Permalink
minor #6228 removed unnecessary exception from repository (gondo)
Browse files Browse the repository at this point in the history
This PR was submitted for the master branch but it was merged into the 2.8 branch instead (closes #6228).

Discussion
----------

removed unnecessary exception from repository

removed `UsernameNotFoundException` form repository as this logic does not belong to repository and also it is duplicated. exception is already thrown on proper place if no user is found:
https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php#L60

Commits
-------

0e288a2 removed unnecesary exception form repository
  • Loading branch information
xabbuh committed Feb 6, 2016
2 parents ab57eed + 0e288a2 commit f7adcfa
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions cookbook/security/entity_provider.rst
Expand Up @@ -432,29 +432,18 @@ interface only requires one method: ``loadUserByUsername($username)``::

use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Doctrine\ORM\EntityRepository;

class UserRepository extends EntityRepository implements UserLoaderInterface
{
public function loadUserByUsername($username)
{
$user = $this->createQueryBuilder('u')
return $this->createQueryBuilder('u')
->where('u.username = :username OR u.email = :email')
->setParameter('username', $username)
->setParameter('email', $username)
->getQuery()
->getOneOrNullResult();

if (null === $user) {
$message = sprintf(
'Unable to find an active admin AppBundle:User object identified by "%s".',
$username
);
throw new UsernameNotFoundException($message);
}

return $user;
}
}

Expand Down

0 comments on commit f7adcfa

Please sign in to comment.