anonymous_user === null) { $this->anonymous_user = $this->findOneBy([ 'id' => User::ID_ANONYMOUS, ]); } return $this->anonymous_user; } /** * Find a user by its name or its email. Useful for login or password reset purposes. * @param string $name_or_password The username or the email of the user that should be found * @return User|null The user if it is existing, null if no one matched the criteria */ public function findByEmailOrName(string $name_or_password) : ?User { if (empty($name_or_password)) { return null; } $qb = $this->createQueryBuilder('u'); $qb->select('u') ->where('u.name = (:name)') ->orWhere('u.email = (:email)'); $qb->setParameters(['email' => $name_or_password, 'name' => $name_or_password]); try { return $qb->getQuery()->getOneOrNullResult(); } catch (NonUniqueResultException $exception) { return null; } } }