* @category Class * @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License * @link www.splendidbear.org * @since 2026. 04. 09. * * @extends ServiceEntityRepository */ class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface { public function __construct(ManagerRegistry $registry, private readonly LoggerInterface $logger) { parent::__construct($registry, User::class); } public function findOneByUsername(string $username): ?User { $qb = $this->createQueryBuilder('u'); try { return $qb ->where($qb->expr()->eq('u.username', ':username')) ->setParameter('username', $username) ->getQuery() ->getOneOrNullResult(); } catch (NonUniqueResultException $e) { $this->logger->error($e->getMessage()); throw new RuntimeException("Multiple users found with the same username: $username", 0, $e); } } public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void { if (!$user instanceof User) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); } $user->setPassword($newHashedPassword); $this->getEntityManager()->persist($user); $this->getEntityManager()->flush(); } }