protected function create($step)
    {
        if (!isset($step->dsl['groups'])) {
            throw new \Exception('No user groups set to create user in.');
        }

        if (!is_array($step->dsl['groups'])) {
            $step->dsl['groups'] = array($step->dsl['groups']);
        }

        $userService = $this->repository->getUserService();
        $contentTypeService = $this->repository->getContentTypeService();

        $userGroups = array();
        foreach ($step->dsl['groups'] as $groupId) {
            $groupId = $this->referenceResolver->resolveReference($groupId);
            $userGroup = $this->userGroupMatcher->matchOneByKey($groupId);

            // q: in which case can we have no group? And should we throw an exception?
            //if ($userGroup) {
                $userGroups[] = $userGroup;
            //}
        }

        $userContentType = $contentTypeService->loadContentTypeByIdentifier($this->getUserContentType($step));

        $userCreateStruct = $userService->newUserCreateStruct(
            $this->referenceResolver->resolveReference($step->dsl['username']),
            $this->referenceResolver->resolveReference($step->dsl['email']),
            $this->referenceResolver->resolveReference($step->dsl['password']),
            $this->getLanguageCode($step),
            $userContentType
        );
        $userCreateStruct->setField('first_name', $this->referenceResolver->resolveReference($step->dsl['first_name']));
        $userCreateStruct->setField('last_name', $this->referenceResolver->resolveReference($step->dsl['last_name']));

        // Create the user
        $user = $userService->createUser($userCreateStruct, $userGroups);

        $this->setReferences($user, $step);

        return $user;
    }
protected function create($step)
    {
        if (!isset($step->dsl['groups'])) {
            throw new \Exception('No user groups set to create user in.');
        }

        if (!is_array($step->dsl['groups'])) {
            $step->dsl['groups'] = array($step->dsl['groups']);
        }

        $userService = $this->repository->getUserService();
        $contentTypeService = $this->repository->getContentTypeService();

        $userGroups = array();
        foreach ($step->dsl['groups'] as $groupId) {
            $groupId = $this->referenceResolver->resolveReference($groupId);
            $userGroup = $this->userGroupMatcher->matchOneByKey($groupId);

            // q: in which case can we have no group? And should we throw an exception?
            //if ($userGroup) {
                $userGroups[] = $userGroup;
            //}
        }

        $userContentType = $contentTypeService->loadContentTypeByIdentifier($this->getUserContentType($step));

        $userCreateStruct = $userService->newUserCreateStruct(
            $this->referenceResolver->resolveReference($step->dsl['username']),
            $this->referenceResolver->resolveReference($step->dsl['email']),
            $this->referenceResolver->resolveReference($step->dsl['password']),
            $this->getLanguageCode($step),
            $userContentType
        );
        $userCreateStruct->setField('first_name', $this->referenceResolver->resolveReference($step->dsl['first_name']));
        $userCreateStruct->setField('last_name', $this->referenceResolver->resolveReference($step->dsl['last_name']));

        // Create the user
        $user = $userService->createUser($userCreateStruct, $userGroups);

        $this->setReferences($user, $step);

        return $user;
    }
protected function create ( $ step ) { if ( ! isset ( $ step -> dsl [ 'groups' ] ) ) { throw new \ Exception ( 'No user groups set to create user in.' ) ; } if ( ! is_array ( $ step -> dsl [ 'groups' ] ) ) { $ step -> dsl [ 'groups' ] = array ( $ step -> dsl [ 'groups' ] ) ; } $ userService = $ this -> repository -> getUserService ( ) ; $ contentTypeService = $ this -> repository -> getContentTypeService ( ) ; $ userGroups = array ( ) ; foreach ( $ step -> dsl [ 'groups' ] as $ groupId ) { $ groupId = $ this -> referenceResolver -> resolveReference ( $ groupId ) ; $ userGroup = $ this -> userGroupMatcher -> matchOneByKey ( $ groupId ) ; // q: in which case can we have no group? And should we throw an exception? //if ($userGroup) { $ userGroups [ ] = $ userGroup ; //} } $ userContentType = $ contentTypeService -> loadContentTypeByIdentifier ( $ this -> getUserContentType ( $ step ) ) ; $ userCreateStruct = $ userService -> newUserCreateStruct ( $ this -> referenceResolver -> resolveReference ( $ step -> dsl [ 'username' ] ) , $ this -> referenceResolver -> resolveReference ( $ step -> dsl [ 'email' ] ) , $ this -> referenceResolver -> resolveReference ( $ step -> dsl [ 'password' ] ) , $ this -> getLanguageCode ( $ step ) , $ userContentType ) ; $ userCreateStruct -> setField ( 'first_name' , $ this -> referenceResolver -> resolveReference ( $ step -> dsl [ 'first_name' ] ) ) ; $ userCreateStruct -> setField ( 'last_name' , $ this -> referenceResolver -> resolveReference ( $ step -> dsl [ 'last_name' ] ) ) ; // Create the user $ user = $ userService -> createUser ( $ userCreateStruct , $ userGroups ) ; $ this -> setReferences ( $ user , $ step ) ; return $ user ; }
Creates a user based on the DSL instructions.

@todo allow setting extra profile attributes!
Creates a user based on the DSL instructions .