*/ class PasswordResetTokenRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, PasswordResetToken::class); } public function save(PasswordResetToken $entity, bool $flush = false): void { $this->getEntityManager()->persist($entity); if ($flush) { $this->getEntityManager()->flush(); } } public function remove(PasswordResetToken $entity, bool $flush = false): void { $this->getEntityManager()->remove($entity); if ($flush) { $this->getEntityManager()->flush(); } } public function findByToken(string $token): ?PasswordResetToken { return $this->findOneBy(['token' => $token]); } public function findValidByToken(string $token): ?PasswordResetToken { $tokenEntity = $this->findByToken($token); if ($tokenEntity && $tokenEntity->isValid()) { return $tokenEntity; } return null; } public function removeExpiredTokens(): int { $qb = $this->createQueryBuilder('t'); $qb->delete() ->where('t.expiresAt < :now') ->setParameter('now', new \DateTime()); return $qb->getQuery()->execute(); } }