public function createRole(APIRoleCreateStruct $roleCreateStruct)
    {
        $inputMessage = $this->outputVisitor->visit($roleCreateStruct);
        $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Role');

        $result = $this->client->request(
            'POST',
            $this->requestParser->generate('roles'),
            $inputMessage
        );

        $createdRole = $this->inputDispatcher->parse($result);
        $createdRoleValues = $this->requestParser->parse('role', $createdRole->id);

        $createdPolicies = array();
        foreach ($roleCreateStruct->getPolicies() as $policyCreateStruct) {
            $inputMessage = $this->outputVisitor->visit($policyCreateStruct);
            $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Policy');

            $result = $this->client->request(
                'POST',
                $this->requestParser->generate('policies', array('role' => $createdRoleValues['role'])),
                $inputMessage
            );

            $createdPolicy = $this->inputDispatcher->parse($result);

            // @todo Workaround for missing roleId in Policy XSD definition
            $createdPolicyArray = array(
                'id' => $createdPolicy->id,
                'roleId' => $createdRole->id,
                'module' => $createdPolicy->module,
                'function' => $createdPolicy->function,
            );

            $createdPolicy = new Policy($createdPolicyArray);
            $createdPolicies[] = $createdPolicy;
        }

        return new RoleDraft(
            array(
                'id' => $createdRole->id,
                'identifier' => $createdRole->identifier,
            ),
            $createdPolicies
        );
    }
public function createRole(APIRoleCreateStruct $roleCreateStruct)
    {
        $inputMessage = $this->outputVisitor->visit($roleCreateStruct);
        $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Role');

        $result = $this->client->request(
            'POST',
            $this->requestParser->generate('roles'),
            $inputMessage
        );

        $createdRole = $this->inputDispatcher->parse($result);
        $createdRoleValues = $this->requestParser->parse('role', $createdRole->id);

        $createdPolicies = array();
        foreach ($roleCreateStruct->getPolicies() as $policyCreateStruct) {
            $inputMessage = $this->outputVisitor->visit($policyCreateStruct);
            $inputMessage->headers['Accept'] = $this->outputVisitor->getMediaType('Policy');

            $result = $this->client->request(
                'POST',
                $this->requestParser->generate('policies', array('role' => $createdRoleValues['role'])),
                $inputMessage
            );

            $createdPolicy = $this->inputDispatcher->parse($result);

            // @todo Workaround for missing roleId in Policy XSD definition
            $createdPolicyArray = array(
                'id' => $createdPolicy->id,
                'roleId' => $createdRole->id,
                'module' => $createdPolicy->module,
                'function' => $createdPolicy->function,
            );

            $createdPolicy = new Policy($createdPolicyArray);
            $createdPolicies[] = $createdPolicy;
        }

        return new RoleDraft(
            array(
                'id' => $createdRole->id,
                'identifier' => $createdRole->identifier,
            ),
            $createdPolicies
        );
    }
public function createRole ( APIRoleCreateStruct $ roleCreateStruct ) { $ inputMessage = $ this -> outputVisitor -> visit ( $ roleCreateStruct ) ; $ inputMessage -> headers [ 'Accept' ] = $ this -> outputVisitor -> getMediaType ( 'Role' ) ; $ result = $ this -> client -> request ( 'POST' , $ this -> requestParser -> generate ( 'roles' ) , $ inputMessage ) ; $ createdRole = $ this -> inputDispatcher -> parse ( $ result ) ; $ createdRoleValues = $ this -> requestParser -> parse ( 'role' , $ createdRole -> id ) ; $ createdPolicies = array ( ) ; foreach ( $ roleCreateStruct -> getPolicies ( ) as $ policyCreateStruct ) { $ inputMessage = $ this -> outputVisitor -> visit ( $ policyCreateStruct ) ; $ inputMessage -> headers [ 'Accept' ] = $ this -> outputVisitor -> getMediaType ( 'Policy' ) ; $ result = $ this -> client -> request ( 'POST' , $ this -> requestParser -> generate ( 'policies' , array ( 'role' => $ createdRoleValues [ 'role' ] ) ) , $ inputMessage ) ; $ createdPolicy = $ this -> inputDispatcher -> parse ( $ result ) ; // @todo Workaround for missing roleId in Policy XSD definition $ createdPolicyArray = array ( 'id' => $ createdPolicy -> id , 'roleId' => $ createdRole -> id , 'module' => $ createdPolicy -> module , 'function' => $ createdPolicy -> function , ) ; $ createdPolicy = new Policy ( $ createdPolicyArray ) ; $ createdPolicies [ ] = $ createdPolicy ; } return new RoleDraft ( array ( 'id' => $ createdRole -> id , 'identifier' => $ createdRole -> identifier , ) , $ createdPolicies ) ; }
Creates a new Role draft.

@throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a role
@throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists or if limitation of the
same type is repeated in the policy create struct or if
limitation is not allowed on module/function
@throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid

@param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct

@return \eZ\Publish\API\Repository\Values\User\RoleDraft
Creates a new Role draft .