src/Repository/UserRepository.php line 24

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