src/Repository/UserRepository.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\User;
  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\PasswordUpgraderInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @method User|null find($id, $lockMode = null, $lockVersion = null)
  11.  * @method User|null findOneBy(array $criteria, array $orderBy = null)
  12.  * @method User[]    findAll()
  13.  * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  14.  */
  15. class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
  16. {
  17.     public function __construct(ManagerRegistry $registry)
  18.     {
  19.         parent::__construct($registryUser::class);
  20.     }
  21.     /**
  22.      * Used to upgrade (rehash) the user's password automatically over time.
  23.      */
  24.     public function upgradePassword(UserInterface $userstring $newEncodedPassword): void
  25.     {
  26.         if (!$user instanceof User) {
  27.             throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.'\get_class($user)));
  28.         }
  29.         $user->setPassword($newEncodedPassword);
  30.         $this->_em->persist($user);
  31.         $this->_em->flush();
  32.     }
  33.     public function hasUser(): ?User
  34.     {
  35.         return $this->createQueryBuilder('u')
  36.             ->getQuery()
  37.             ->getOneOrNullResult()
  38.         ;
  39.     }
  40.     // /**
  41.     //  * @return User[] Returns an array of User objects
  42.     //  */
  43.     /*
  44.     public function findByExampleField($value)
  45.     {
  46.         return $this->createQueryBuilder('u')
  47.             ->andWhere('u.exampleField = :val')
  48.             ->setParameter('val', $value)
  49.             ->orderBy('u.id', 'ASC')
  50.             ->setMaxResults(10)
  51.             ->getQuery()
  52.             ->getResult()
  53.         ;
  54.     }
  55.     */
  56.     /*
  57.     public function findOneBySomeField($value): ?User
  58.     {
  59.         return $this->createQueryBuilder('u')
  60.             ->andWhere('u.exampleField = :val')
  61.             ->setParameter('val', $value)
  62.             ->getQuery()
  63.             ->getOneOrNullResult()
  64.         ;
  65.     }
  66.     */
  67. }