src/Repository/SharedUserRepository.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\SharedUser;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9.  * @extends ServiceEntityRepository<SharedUser>
  10.  *
  11.  * @method SharedUser|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method SharedUser|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method SharedUser[]    findAll()
  14.  * @method SharedUser[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class SharedUserRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registrySharedUser::class);
  21.     }
  22.     public function refreshUser(UserInterface $user)
  23.     {
  24.         $class get_class($user);
  25.         if (! $this->supportsClass($class)) {
  26.             throw new UnsupportedUserException(sprintf('Instances of %s are not suppoted'$class));
  27.         }
  28.         return $this->find($user->getId());
  29.     }
  30.     public function supportsClass($class): bool
  31.     {
  32.         return $this->getEntityName() === $class || is_subclass_of($class$this->getEntityName());
  33.     }
  34. }