Parse input structure.

@param array $data
@param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher

@return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct
345778
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('ParentLocation', $data) || !is_array($data['ParentLocation'])) {
            throw new Exceptions\Parser("Missing or invalid 'ParentLocation' element for LocationCreate.");
        }

        if (!array_key_exists('_href', $data['ParentLocation'])) {
            throw new Exceptions\Parser("Missing '_href' attribute for ParentLocation element in LocationCreate.");
        }

        $locationHrefParts = explode('/', $this->requestParser->parseHref($data['ParentLocation']['_href'], 'locationPath'));

        $locationCreateStruct = $this->locationService->newLocationCreateStruct(
            array_pop($locationHrefParts)
        );

        if (array_key_exists('priority', $data)) {
            $locationCreateStruct->priority = (int)$data['priority'];
        }

        if (array_key_exists('hidden', $data)) {
            $locationCreateStruct->hidden = $this->parserTools->parseBooleanValue($data['hidden']);
        }

        if (array_key_exists('remoteId', $data)) {
            $locationCreateStruct->remoteId = $data['remoteId'];
        }

        if (!array_key_exists('sortField', $data)) {
            throw new Exceptions\Parser("Missing 'sortField' element for LocationCreate.");
        }

        $locationCreateStruct->sortField = $this->parserTools->parseDefaultSortField($data['sortField']);

        if (!array_key_exists('sortOrder', $data)) {
            throw new Exceptions\Parser("Missing 'sortOrder' element for LocationCreate.");
        }

        $locationCreateStruct->sortOrder = $this->parserTools->parseDefaultSortOrder($data['sortOrder']);

        return $locationCreateStruct;
    }
870809
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $locations = array();
        foreach ($data['Location'] as $rawLocationData) {
            $locations[] = $parsingDispatcher->parse(
                $rawLocationData,
                $rawLocationData['_media-type']
            );
        }

        return $locations;
    }
557018
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $creatorId = $this->parserTools->parseObjectElement($data['Creator'], $parsingDispatcher);
        $modifierId = $this->parserTools->parseObjectElement($data['Modifier'], $parsingDispatcher);

        return new Values\ContentType\ContentTypeGroup(
            array(
                'id' => $data['_href'],
                'identifier' => $data['identifier'],
                'creationDate' => new \DateTime($data['created']),
                'modificationDate' => new \DateTime($data['modified']),
                'creatorId' => $creatorId,
                'modifierId' => $modifierId,
            )
        );
    }
574227
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentTypeGroups = array();
        foreach ($data['ContentTypeGroup'] as $rawContentTypeGroupData) {
            $contentTypeGroups[] = $parsingDispatcher->parse(
                $rawContentTypeGroupData,
                $rawContentTypeGroupData['_media-type']
            );
        }

        return $contentTypeGroups;
    }
393595
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $roles = array();
        foreach ($data['Role'] as $rawRoleData) {
            $roles[] = $parsingDispatcher->parse(
                $rawRoleData,
                $rawRoleData['_media-type']
            );
        }

        return $roles;
    }
1267201
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $states = array();
        foreach ($data['ObjectState'] as $rawStateData) {
            $states[] = $parsingDispatcher->parse(
                $rawStateData,
                $rawStateData['_media-type']
            );
        }

        return $states;
    }
940920
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $fieldDefinitionReferences = array();

        foreach ($data['FieldDefinition'] as $fieldDefinitionData) {
            $fieldDefinitionReferences[] = $this->parserTools->parseObjectElement(
                $fieldDefinitionData,
                $parsingDispatcher
            );
        }

        return new Values\FieldDefinitionList(
            $this->contentTypeService,
            $fieldDefinitionReferences
        );
    }
1180417
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $objectStateUpdateStruct = $this->objectStateService->newObjectStateUpdateStruct();

        if (array_key_exists('identifier', $data)) {
            $objectStateUpdateStruct->identifier = $data['identifier'];
        }

        if (array_key_exists('defaultLanguageCode', $data)) {
            $objectStateUpdateStruct->defaultLanguageCode = $data['defaultLanguageCode'];
        }

        if (array_key_exists('names', $data)) {
            if (!is_array($data['names'])) {
                throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateUpdate.");
            }

            if (!array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
                throw new Exceptions\Parser("Missing or invalid 'names' element for ObjectStateUpdate.");
            }

            $objectStateUpdateStruct->names = $this->parserTools->parseTranslatableList($data['names']);
        }

        if (array_key_exists('descriptions', $data) && is_array($data['descriptions'])) {
            $objectStateUpdateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
        }

        return $objectStateUpdateStruct;
    }
1026011
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $limitation = $this->getLimitationByIdentifier($data['_identifier']);

        $limitationValues = array();
        foreach ($data['values']['ref'] as $limitationValue) {
            $limitationValues[] = $limitationValue['_href'];
        }

        $limitation->limitationValues = $limitationValues;

        return $limitation;
    }
1064769
public function reverseMap($data): SectionCreateStruct
    {
        if (!$data instanceof SectionCreateData) {
            throw new InvalidArgumentException('data', 'must be an instance of ' . SectionCreateData::class);
        }

        return new SectionCreateStruct([
            'name' => $data->getName(),
            'identifier' => $data->getIdentifier(),
        ]);
    }
743040
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentId = $this->requestParser->parseHref($data['VersionInfo']['Content']['_href'], 'contentId');

        $content = $this->contentService->loadContent($contentId, null, $data['VersionInfo']['versionNo']);
        $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
        $relations = $this->contentService->loadRelations($content->versionInfo);

        return new VersionValue($content, $contentType, $relations);
    }
1083524
public function reverseMap($data): ContentMetadataUpdateStruct
    {
        if (!$data instanceof ContentMainLocationUpdateData) {
            throw new InvalidArgumentException('data', 'must be an instance of ' . ContentMainLocationUpdateData::class);
        }

        return new ContentMetadataUpdateStruct([
            'mainLocationId' => $data->getLocation()->id,
        ]);
    }
1021797
protected function createStructure( array $data )
    {
        $structure = clone $this->structurePrototype;

        if ( $structure instanceof MapperAwareInterface )
        {
            $structure->setMapper( $this );
        }

        return $structure->setOptions( $data );
    }
517712
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('identifier', $data)) {
            throw new Exceptions\Parser("Missing 'identifier' element for ContentTypeCreate.");
        }

        $contentTypeCreateStruct = $this->contentTypeService->newContentTypeCreateStruct($data['identifier']);

        if (!array_key_exists('mainLanguageCode', $data)) {
            throw new Exceptions\Parser("Missing 'mainLanguageCode' element for ContentTypeCreate.");
        }

        $contentTypeCreateStruct->mainLanguageCode = $data['mainLanguageCode'];

        if (array_key_exists('remoteId', $data)) {
            $contentTypeCreateStruct->remoteId = $data['remoteId'];
        }

        if (array_key_exists('urlAliasSchema', $data)) {
            $contentTypeCreateStruct->urlAliasSchema = $data['urlAliasSchema'];
        }

        // @todo XSD says that nameSchema is mandatory, but it is not in create struct
        if (array_key_exists('nameSchema', $data)) {
            $contentTypeCreateStruct->nameSchema = $data['nameSchema'];
        }

        // @todo XSD says that isContainer is mandatory, but it is not in create struct
        if (array_key_exists('isContainer', $data)) {
            $contentTypeCreateStruct->isContainer = $this->parserTools->parseBooleanValue($data['isContainer']);
        }

        // @todo XSD says that defaultSortField is mandatory, but it is not in create struct
        if (array_key_exists('defaultSortField', $data)) {
            $contentTypeCreateStruct->defaultSortField = $this->parserTools->parseDefaultSortField($data['defaultSortField']);
        }

        // @todo XSD says that defaultSortOrder is mandatory, but it is not in create struct
        if (array_key_exists('defaultSortOrder', $data)) {
            $contentTypeCreateStruct->defaultSortOrder = $this->parserTools->parseDefaultSortOrder($data['defaultSortOrder']);
        }

        // @todo XSD says that defaultAlwaysAvailable is mandatory, but it is not in create struct
        if (array_key_exists('defaultAlwaysAvailable', $data)) {
            $contentTypeCreateStruct->defaultAlwaysAvailable = $this->parserTools->parseBooleanValue($data['defaultAlwaysAvailable']);
        }

        if (array_key_exists('names', $data)) {
            if (!is_array($data['names'])
                || !array_key_exists('value', $data['names'])
                || !is_array($data['names']['value'])
            ) {
                throw new Exceptions\Parser("Invalid 'names' element for ContentTypeCreate.");
            }

            $contentTypeCreateStruct->names = $this->parserTools->parseTranslatableList($data['names']);
        }

        // @todo XSD says that descriptions is mandatory, but content type can be created without descriptions
        if (array_key_exists('descriptions', $data)) {
            if (!is_array($data['descriptions'])
                || !array_key_exists('value', $data['descriptions'])
                || !is_array($data['descriptions']['value'])
            ) {
                throw new Exceptions\Parser("Invalid 'descriptions' element for ContentTypeCreate.");
            }

            $contentTypeCreateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
        }

        // @todo 1: XSD says that modificationDate is mandatory, but it is not in create struct
        // @todo 2: mismatch between XSD naming and create struct naming
        if (array_key_exists('modificationDate', $data)) {
            $contentTypeCreateStruct->creationDate = new DateTime($data['modificationDate']);
        }

        if (array_key_exists('User', $data)) {
            if (!array_key_exists('_href', $data['User'])) {
                throw new Exceptions\Parser("Missing '_href' attribute for User element in ContentTypeCreate.");
            }

            $contentTypeCreateStruct->creatorId = $this->requestParser->parseHref($data['User']['_href'], 'userId');
        }

        if (!array_key_exists('FieldDefinitions', $data)) {
            throw new Exceptions\Parser("Missing 'FieldDefinitions' element for ContentTypeCreate.");
        }

        if (
            !is_array($data['FieldDefinitions'])
            || !array_key_exists('FieldDefinition', $data['FieldDefinitions'])
            || !is_array($data['FieldDefinitions']['FieldDefinition'])
        ) {
            throw new Exceptions\Parser("Invalid 'FieldDefinitions' element for ContentTypeCreate.");
        }

        // With no field definitions given and when ContentType is immediately published we must return HTTP 400 BadRequest,
        // instead of relying on service to throw InvalidArgumentException
        if (isset($data['__publish']) && $data['__publish'] === true && empty($data['FieldDefinitions']['FieldDefinition'])) {
            throw new Exceptions\Parser('ContentTypeCreate should provide at least one field definition.');
        }

        foreach ($data['FieldDefinitions']['FieldDefinition'] as $fieldDefinitionData) {
            if (!is_array($fieldDefinitionData)) {
                throw new Exceptions\Parser("Invalid 'FieldDefinition' element for ContentTypeCreate.");
            }

            $contentTypeCreateStruct->addFieldDefinition(
                $this->fieldDefinitionCreateParser->parse($fieldDefinitionData, $parsingDispatcher)
            );
        }

        return $contentTypeCreateStruct;
    }
936448
public function reverseMap($data): RoleCreateStruct
    {
        if (!$data instanceof RoleCreateData) {
            throw new InvalidArgumentException('data', 'must be an instance of ' . RoleCreateData::class);
        }

        return new RoleCreateStruct([
            'identifier' => $data->getIdentifier(),
        ]);
    }
1044420
protected function buildSPILocationCreateStructs(array $locationCreateStructs)
    {
        $spiLocationCreateStructs = array();
        $parentLocationIdSet = array();
        $mainLocation = true;

        foreach ($locationCreateStructs as $locationCreateStruct) {
            if (isset($parentLocationIdSet[$locationCreateStruct->parentLocationId])) {
                throw new InvalidArgumentException(
                    '$locationCreateStructs',
                    "Multiple LocationCreateStructs with the same parent Location '{$locationCreateStruct->parentLocationId}' are given"
                );
            }

            if (!array_key_exists($locationCreateStruct->sortField, Location::SORT_FIELD_MAP)) {
                $locationCreateStruct->sortField = Location::SORT_FIELD_NAME;
            }

            if (!array_key_exists($locationCreateStruct->sortOrder, Location::SORT_ORDER_MAP)) {
                $locationCreateStruct->sortOrder = Location::SORT_ORDER_ASC;
            }

            $parentLocationIdSet[$locationCreateStruct->parentLocationId] = true;
            $parentLocation = $this->repository->getLocationService()->loadLocation(
                $locationCreateStruct->parentLocationId
            );

            $spiLocationCreateStructs[] = $this->domainMapper->buildSPILocationCreateStruct(
                $locationCreateStruct,
                $parentLocation,
                $mainLocation,
                // For Content draft contentId and contentVersionNo are set in ContentHandler upon draft creation
                null,
                null
            );

            // First Location in the list will be created as main Location
            $mainLocation = false;
        }

        return $spiLocationCreateStructs;
    }
1051074
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $parsedData = array();

        //@todo XSD has a login element, but it's not possible to update login

        if (array_key_exists('email', $data)) {
            $parsedData['email'] = $data['email'];
        }

        if (array_key_exists('password', $data)) {
            $parsedData['password'] = $data['password'];
        }

        if (array_key_exists('enabled', $data)) {
            $parsedData['enabled'] = $this->parserTools->parseBooleanValue($data['enabled']);
        }

        if (array_key_exists('mainLanguageCode', $data)) {
            $parsedData['mainLanguageCode'] = $data['mainLanguageCode'];
        }

        if (array_key_exists('Section', $data) && is_array($data['Section'])) {
            if (!array_key_exists('_href', $data['Section'])) {
                throw new Exceptions\Parser("Missing '_href' attribute for Section element in UserUpdate.");
            }

            $parsedData['sectionId'] = $this->requestParser->parseHref($data['Section']['_href'], 'sectionId');
        }

        if (array_key_exists('remoteId', $data)) {
            $parsedData['remoteId'] = $data['remoteId'];
        }

        if (array_key_exists('fields', $data)) {
            $userId = $this->requestParser->parseHref($data['__url'], 'userId');

            if (!is_array($data['fields']) || !array_key_exists('field', $data['fields']) || !is_array($data['fields']['field'])) {
                throw new Exceptions\Parser("Invalid 'fields' element for UserUpdate.");
            }

            $parsedData['fields'] = array();
            foreach ($data['fields']['field'] as $fieldData) {
                if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
                    throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for UserUpdate.");
                }

                if (!array_key_exists('fieldValue', $fieldData)) {
                    throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in UserUpdate.");
                }

                $fieldValue = $this->fieldTypeParser->parseFieldValue($userId, $fieldData['fieldDefinitionIdentifier'], $fieldData['fieldValue']);

                $languageCode = null;
                if (array_key_exists('languageCode', $fieldData)) {
                    $languageCode = $fieldData['languageCode'];
                }

                $parsedData['fields'][$fieldData['fieldDefinitionIdentifier']] = array(
                    'fieldValue' => $fieldValue,
                    'languageCode' => $languageCode,
                );
            }
        }

        $userUpdateStruct = $this->userService->newUserUpdateStruct();

        if (!empty($parsedData)) {
            if (array_key_exists('email', $parsedData)) {
                $userUpdateStruct->email = $parsedData['email'];
            }

            if (array_key_exists('password', $parsedData)) {
                $userUpdateStruct->password = $parsedData['password'];
            }

            if (array_key_exists('enabled', $parsedData)) {
                $userUpdateStruct->enabled = $parsedData['enabled'];
            }

            if (array_key_exists('mainLanguageCode', $parsedData) || array_key_exists('remoteId', $parsedData)) {
                $userUpdateStruct->contentMetadataUpdateStruct = $this->contentService->newContentMetadataUpdateStruct();

                if (array_key_exists('mainLanguageCode', $parsedData)) {
                    $userUpdateStruct->contentMetadataUpdateStruct->mainLanguageCode = $parsedData['mainLanguageCode'];
                }

                if (array_key_exists('remoteId', $parsedData)) {
                    $userUpdateStruct->contentMetadataUpdateStruct->remoteId = $parsedData['remoteId'];
                }
            }

            if (array_key_exists('fields', $parsedData)) {
                $userUpdateStruct->contentUpdateStruct = $this->contentService->newContentUpdateStruct();

                foreach ($parsedData['fields'] as $fieldDefinitionIdentifier => $fieldValue) {
                    $userUpdateStruct->contentUpdateStruct->setField(
                        $fieldDefinitionIdentifier,
                        $fieldValue['fieldValue'],
                        $fieldValue['languageCode']
                    );
                }
            }
        }

        return new RestUserUpdateStruct(
            $userUpdateStruct,
            array_key_exists('sectionId', $parsedData) ? $parsedData['sectionId'] : null
        );
    }