<?php
namespace App\Repository;
use App\Entity\SharedUser;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @extends ServiceEntityRepository<SharedUser>
*
* @method SharedUser|null find($id, $lockMode = null, $lockVersion = null)
* @method SharedUser|null findOneBy(array $criteria, array $orderBy = null)
* @method SharedUser[] findAll()
* @method SharedUser[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SharedUserRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, SharedUser::class);
}
public function refreshUser(UserInterface $user)
{
$class = get_class($user);
if (! $this->supportsClass($class)) {
throw new UnsupportedUserException(sprintf('Instances of %s are not suppoted', $class));
}
return $this->find($user->getId());
}
public function supportsClass($class): bool
{
return $this->getEntityName() === $class || is_subclass_of($class, $this->getEntityName());
}
}