*/ class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, User::class); } /** * Used to upgrade (rehash) the user's password automatically over time. */ 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(); } /** * @return User[] */ public function findByRole(string $role): array { return $this->createQueryBuilder('u') ->andWhere('u.roles LIKE :role') ->setParameter('role', '%"' . $role . '"%') ->getQuery() ->getResult(); } /** * Soft-deleted users, deleted before the given date, who never played a game. * * @return User[] */ public function findPurgeableDeletedUsers(\DateTimeImmutable $deletedBefore): array { return $this->createQueryBuilder('u') ->andWhere('u.deletedAt IS NOT NULL') ->andWhere('u.deletedAt <= :deletedBefore') ->andWhere('NOT EXISTS (SELECT 1 FROM App\Game\Entity\Player p WHERE p.user = u)') ->setParameter('deletedBefore', $deletedBefore) ->getQuery() ->getResult(); } }