Parse input structure.

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

@return \EzSystems\EzPlatformAdminUi\REST\Value\Operation
771654
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('uri', $data) || !is_string($data['uri'])) {
            throw new Exceptions\Parser("Missing or invalid 'uri' element for BulkOperation.");
        }

        if (!array_key_exists('method', $data) || !is_string($data['method'])) {
            throw new Exceptions\Parser("Missing or invalid 'method' element for BulkOperation.");
        }

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

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

        if (array_key_exists('content', $data) && !is_string($data['content'])) {
            throw new Exceptions\Parser("Missing or invalid 'content' element for BulkOperation.");
        }

        $operation = new OperationValue(
            $data['uri'],
            $data['method'],
            $data['parameters'] ?? [],
            $data['headers'] ?? [],
            $data['content'] ?? ''
        );

        return $operation;
    }
613023
private function processCriteriaArray(array $criteriaArray, ParsingDispatcher $parsingDispatcher)
    {
        if (count($criteriaArray) === 0) {
            return null;
        }

        $criteria = array();
        foreach ($criteriaArray as $criterionName => $criterionData) {
            $criteria[] = $this->dispatchCriterion($criterionName, $criterionData, $parsingDispatcher);
        }

        return (count($criteria) === 1) ? $criteria[0] : new CriterionValue\LogicalAnd($criteria);
    }
638719
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('identifier', $data)) {
            throw new Exceptions\Parser("Missing 'identifier' attribute for ObjectStateCreate.");
        }

        $objectStateCreateStruct = $this->objectStateService->newObjectStateCreateStruct($data['identifier']);

        if (!array_key_exists('priority', $data)) {
            throw new Exceptions\Parser("Missing 'priority' attribute for ObjectStateCreate.");
        }

        $objectStateCreateStruct->priority = (int)$data['priority'];

        if (!array_key_exists('defaultLanguageCode', $data)) {
            throw new Exceptions\Parser("Missing 'defaultLanguageCode' attribute for ObjectStateCreate.");
        }

        $objectStateCreateStruct->defaultLanguageCode = $data['defaultLanguageCode'];

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

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

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

        // @todo XSD says that descriptions field is mandatory. Does that make sense?
        if (array_key_exists('descriptions', $data) && is_array($data['descriptions'])) {
            $objectStateCreateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
        }

        return $objectStateCreateStruct;
    }
109615
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $policies = array();

        if (array_key_exists('Policy', $data) && is_array($data['Policy'])) {
            foreach ($data['Policy'] as $rawPolicyData) {
                $policies[] = $parsingDispatcher->parse(
                    $rawPolicyData,
                    $rawPolicyData['_media-type']
                );
            }
        }

        return $policies;
    }
329721
public function parseAll(array $data, int $fetchStyle, $fetchArgument = null, array $ctorArgs = array()): array
    {
        $result = [];
        foreach($data as $row)
        {
            switch($fetchStyle)
            {
                case \PDO::FETCH_COLUMN:
                    $item = $this->fetchParser->parseRow($row, \PDO::FETCH_BOTH);
                    $result[] = $item[$fetchArgument ?? 0] ?? null;
                    break;
                default:
                    $result[] = $this->fetchParser->parseRow($row, $fetchStyle);
                    break;
            }
        }
        return $result;
    }
54655
protected function parseArrayOfPrimaryData(array $data)
    {
        $isValid = true;
        $result  = null;
        foreach ($data as $primaryData) {
            $parsed = $this->parseSinglePrimaryData($primaryData);
            if ($parsed === null) {
                $isValid = false;
            } else {
                $result[] = $parsed;
            }
        }

        return $isValid === true ? $result : null;
    }
265862
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $sectionCreate = $this->sectionService->newSectionCreateStruct();

        //@todo XSD says that name is not mandatory? Does that make sense?
        if (!array_key_exists('name', $data)) {
            throw new Exceptions\Parser("Missing 'name' attribute for SectionInput.");
        }

        $sectionCreate->name = $data['name'];

        //@todo XSD says that identifier is not mandatory? Does that make sense?
        if (!array_key_exists('identifier', $data)) {
            throw new Exceptions\Parser("Missing 'identifier' attribute for SectionInput.");
        }

        $sectionCreate->identifier = $data['identifier'];

        return $sectionCreate;
    }
951184
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $fieldDefinitionUpdate = $this->contentTypeService->newFieldDefinitionUpdateStruct();

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

        // @todo XSD says that descriptions is mandatory, but field definition can be updated without it
        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 FieldDefinitionUpdate.");
            }

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

        // @todo XSD says that descriptions is mandatory, but field definition can be updated without it
        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 FieldDefinitionUpdate.");
            }

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

        // @todo XSD says that fieldGroup is mandatory, but field definition can be updated without it
        if (array_key_exists('fieldGroup', $data)) {
            $fieldDefinitionUpdate->fieldGroup = $data['fieldGroup'];
        }

        // @todo XSD says that position is mandatory, but field definition can be updated without it
        if (array_key_exists('position', $data)) {
            $fieldDefinitionUpdate->position = (int)$data['position'];
        }

        // @todo XSD says that isTranslatable is mandatory, but field definition can be updated without it
        if (array_key_exists('isTranslatable', $data)) {
            $fieldDefinitionUpdate->isTranslatable = $this->parserTools->parseBooleanValue($data['isTranslatable']);
        }

        // @todo XSD says that isRequired is mandatory, but field definition can be updated without it
        if (array_key_exists('isRequired', $data)) {
            $fieldDefinitionUpdate->isRequired = $this->parserTools->parseBooleanValue($data['isRequired']);
        }

        // @todo XSD says that isInfoCollector is mandatory, but field definition can be updated without it
        if (array_key_exists('isInfoCollector', $data)) {
            $fieldDefinitionUpdate->isInfoCollector = $this->parserTools->parseBooleanValue($data['isInfoCollector']);
        }

        // @todo XSD says that isSearchable is mandatory, but field definition can be updated without it
        if (array_key_exists('isSearchable', $data)) {
            $fieldDefinitionUpdate->isSearchable = $this->parserTools->parseBooleanValue($data['isSearchable']);
        }

        $fieldDefinition = $this->getFieldDefinition($data);

        // @todo XSD says that defaultValue is mandatory, but content type can be created without it
        if (array_key_exists('defaultValue', $data)) {
            $fieldDefinitionUpdate->defaultValue = $this->fieldTypeParser->parseValue(
                $fieldDefinition->fieldTypeIdentifier,
                $data['defaultValue']
            );
        }

        if (array_key_exists('validatorConfiguration', $data)) {
            $fieldDefinitionUpdate->validatorConfiguration = $this->fieldTypeParser->parseValidatorConfiguration(
                $fieldDefinition->fieldTypeIdentifier,
                $data['validatorConfiguration']
            );
        }

        if (array_key_exists('fieldSettings', $data)) {
            $fieldDefinitionUpdate->fieldSettings = $this->fieldTypeParser->parseFieldSettings(
                $fieldDefinition->fieldTypeIdentifier,
                $data['fieldSettings']
            );
        }

        return $fieldDefinitionUpdate;
    }
1216488
public static function parse($data)
    {
        if (
            $data === OutgoingInterface::class
            || $data instanceof OutgoingInterface
            || is_subclass_of($data, OutgoingInterface::class)
        ) {
            return new self($data);
        }

        return false;
    }
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
        );
    }
688683
private function parse(array $data)
    {
        // generate id
        $enumId = EnumId::fromString(sprintf('%s:%s', $data['namespace'], $data['name']));

        // force default type to be "string"
        if (!isset($data['type'])) {
            $data['type'] = 'string';
        }

        $values = [];
        $keys = $this->fixArray($data['option'], 'key');
        foreach ($keys as $key) {
            $values[strtoupper($key['key'])] = $data['type'] == 'int'
                ? intval($key['value'])
                : (string)$key['value'];
        }

        if (count($values) === 0) {
            return;
        }

        if (array_search('unknown', array_map('strtolower', array_keys($values))) === false) {
            throw new \InvalidArgumentException(sprintf(
                'Enum "%s" require an "UNKNOWN" key that will be used as default value.',
                $enumId->toString()
            ));
        }

        // add enums language options
        $languages = $this->getLanguageOptions($data);

        $isDeprecated = isset($data['deprecated']) && $data['deprecated'];

        return new EnumDescriptor($enumId, $data['type'], $values, $languages, $isDeprecated);
    }
617662
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('module', $data)) {
            throw new Exceptions\Parser("Missing 'module' attribute for PolicyCreate.");
        }

        if (!array_key_exists('function', $data)) {
            throw new Exceptions\Parser("Missing 'function' attribute for PolicyCreate.");
        }

        $policyCreate = $this->roleService->newPolicyCreateStruct($data['module'], $data['function']);

        // @todo XSD says that limitations is mandatory,
        // but polices can be created without limitations
        if (array_key_exists('limitations', $data)) {
            if (!is_array($data['limitations'])) {
                throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyCreate.");
            }

            if (!isset($data['limitations']['limitation']) || !is_array($data['limitations']['limitation'])) {
                throw new Exceptions\Parser("Invalid format for 'limitations' in PolicyCreate.");
            }

            foreach ($data['limitations']['limitation'] as $limitationData) {
                $policyCreate->addLimitation(
                    $this->parserTools->parseLimitation($limitationData)
                );
            }
        }

        return $policyCreate;
    }
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;
    }
385175
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $sections = array();
        foreach ($data['Section'] as $rawSectionData) {
            $sections[] = $parsingDispatcher->parse(
                $rawSectionData,
                $rawSectionData['_media-type']
            );
        }

        return $sections;
    }
147746
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentUpdateStruct = $this->contentService->newContentUpdateStruct();

        // Missing initial language code

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

        // @todo Where to set the user?
        // @todo Where to set modification date?

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

            $contentId = $this->requestParser->parseHref($data['__url'], 'contentId');

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

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

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

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

                $contentUpdateStruct->setField($fieldData['fieldDefinitionIdentifier'], $fieldValue, $languageCode);
            }
        }

        return $contentUpdateStruct;
    }
544751
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentTypes = array();
        foreach ($data['ContentType'] as $rawContentTypeData) {
            $contentTypes[] = $parsingDispatcher->parse(
                $rawContentTypeData,
                $rawContentTypeData['_media-type']
            );
        }

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

        return $locations;
    }