for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the zibios/sharep.
*
* (c) Zbigniew Ślązak
*/
namespace App\Security\User;
use App\Entity\Access\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
class UserProvider implements UserProviderInterface
{
/** @var EntityManagerInterface */
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
$this->entityManager = $entityManager;
}
/**
* @param string $username The username
public function loadUserByUsername($username): UserInterface
return $this->entityManager
->createQueryBuilder()
->select(User::class, 'u')
->where('u.email = :email')
->setParameter('email', $username)
->getQuery()
->getOneOrNullResult();
public function refreshUser(UserInterface $user): UserInterface
if (!$user instanceof User) {
throw new UnsupportedUserException(
sprintf('Instances of "%s" are not supported.', \get_class($user))
);
return $user;
* @param string $class
public function supportsClass($class): bool
return User::class === $class;