eZ\Bundle\EzPublishCoreBundle\Features\Context\UserContext::searchUserByLogin PHP Method

searchUserByLogin() public method

Search User with given username, optionally at given location.
public searchUserByLogin ( string $username, $parentGroupId = null ) : User
$username string name of User to search for
return User found
    public function searchUserByLogin($username, $parentGroupId = null)
    {
        try {
            $user = $this->userService->loadUserByLogin($username);
        } catch (ApiExceptions\NotFoundException $e) {
            return null;
        }
        if ($user && $parentGroupId) {
            $userGroups = $this->userService->loadUserGroupsOfUser($user);
            foreach ($userGroups as $userGroup) {
                if ($userGroup->getVersionInfo()->getContentInfo()->id == $parentGroupId) {
                    return $user;
                }
            }
            // user not found in $parentGroupId
            return null;
        }
        return $user;
    }