Parse input structure.

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

@return \EzSystems\EzPlatformAdminUi\REST\Value\BulkOperation
160333
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!is_array($data) || 'operations' !== key($data)) {
            throw new Exceptions\Parser('Invalid structure for BulkOperation.');
        }

        if (array_key_exists('uri', $data['operations'])) {
            $operationData[] = $data['operations'];
        } else {
            $operationData = $data['operations'];
        }

        $operations = [];
        foreach ($operationData as $operationId => $operation) {
            $operations[$operationId] = $parsingDispatcher->parse($operation, 'application/vnd.ez.api.internal.Operation');
        }

        return new BulkOperationValue($operations);
    }
822489
public function getParser() : ParserInterface
    {
        if (null === $this->parser) {
            $patternHelper = new Parser\Helper\GetPattern($this->cache, $this->logger);
            $dataHelper = new Parser\Helper\GetData($this->cache, $this->logger, new Quoter());

            $this->parser = new Parser\Ini($patternHelper, $dataHelper, $this->formatter);
        }

        return $this->parser;
    }
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;
    }
668557
public function get($url, array $data = [])
    {
        $this->resetAndAssociateUrl($url);

        $this->addFields($data);

        return new Parser($this->ch);
    }
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;
    }
1328048
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('_href', $data['User'])) {
            throw new Exceptions\Parser("Missing '_href' attribute for User element in Session.");
        }

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

        $user = $this->userService->loadUser($userId);

        return new Values\UserSession(
            $user,
            $data['name'],
            $data['identifier'],
            $data['csrfToken'],
            null
        );
    }
1138238
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('identifier', $data)) {
            throw new Exceptions\Parser("Missing 'identifier' attribute for ObjectStateGroupCreate.");
        }

        $objectStateGroupCreateStruct = $this->objectStateService->newObjectStateGroupCreateStruct($data['identifier']);

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

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

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

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

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

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

        return $objectStateGroupCreateStruct;
    }
847204
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentInfoId = $this->requestParser->parseHref($data['Content']['_href'], 'contentId');

        return new Values\Content\VersionInfo(
            $this->contentService,
            array(
                'id' => $data['id'],
                'versionNo' => $data['versionNo'],
                'status' => $this->convertVersionStatus($data['status']),
                'modificationDate' => new \DateTime($data['modificationDate']),
                'creatorId' => $data['Creator']['_href'],
                'creationDate' => new \DateTime($data['creationDate']),
                'initialLanguageCode' => $data['initialLanguageCode'],
                'languageCodes' => explode(',', $data['languageCodes']),
                'names' => $this->parserTools->parseTranslatableList($data['names']),
                'contentInfoId' => $contentInfoId,
            )
        );
    }
609238
public function parser(&$data) {
        $data = json_decode($data,true);
        is_null($data) and trigger_error('The data must be a JSON string');
        $action = isset($data['action'])?$data['action']:'';
        unset($data['action']);
        return $action;
    }
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);
    }
844903
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('Role', $data)) {
            throw new Exceptions\Parser("Missing 'Role' element for RoleAssignInput.");
        }

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

        try {
            $roleId = $this->requestParser->parseHref($data['Role']['_href'], 'roleId');
        } catch (Exceptions\InvalidArgumentException $e) {
            throw new Exceptions\Parser('Invalid format for <Role> reference in <RoleAssignInput>.');
        }

        // @todo XSD says that limitation is mandatory, but roles can be assigned without limitations
        $limitation = null;
        if (array_key_exists('limitation', $data) && is_array($data['limitation'])) {
            if (!array_key_exists('_identifier', $data['limitation'])) {
                throw new Exceptions\Parser("Missing '_identifier' attribute for Limitation.");
            }

            $limitation = $parsingDispatcher->parse(
                $data['limitation'],
                'application/vnd.ez.api.internal.limitation.' . $data['limitation']['_identifier']
            );
        }

        return new RoleAssignment($roleId, $limitation);
    }
339071
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $error = new ErrorMessageValue([
            'code' => $data['errorCode'],
            'message' => isset($data['errorMessage']) ? $data['errorMessage'] : null,
            'description' => isset($data['errorDescription']) ? $data['errorDescription'] : null,
            'details' => isset($data['errorDetails']) ? $data['errorDetails'] : null,
            'trace' => isset($data['trace']) ? $data['trace'] : null,
            'file' => isset($data['file']) ? $data['file'] : null,
            'line' => isset($data['line']) ? $data['line'] : null,
        ]);

        // So client behaves closer to api, return relevant exceptions on status codes that maps to them
        if (isset($this->errorCodeMapping[$data['errorCode']])) {
            $exceptionClass = $this->errorCodeMapping[$data['errorCode']];
            return new $exceptionClass($data['errorDescription'], $data['errorCode'], new ServerException($error));
        }

        return $error;
    }
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;
    }
221520
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!isset($data['Field'])) {
            throw new Exceptions\Parser("The <Field> sort clause doesn't exist in the input structure");
        }

        if (!is_array($data['Field'])) {
            throw new Exceptions\Parser('The <Field> sort clause has missing arguments: contentTypeIdentifier, fieldDefinitionIdentifier');
        }

        $data['Field'] = $this->normalizeData($data['Field']);

        $direction = isset($data['Field']['direction']) ? $data['Field']['direction'] : null;

        if (!in_array($direction, [Query::SORT_ASC, Query::SORT_DESC])) {
            throw new Exceptions\Parser('Invalid direction format in <Field> sort clause');
        }

        if (isset($data['Field']['identifier'])) {
            if (false === strpos($data['Field']['identifier'], '/')) {
                throw new Exceptions\Parser('<Field> sort clause parameter "identifier" value has to be in "contentTypeIdentifier/fieldDefinitionIdentifier" format');
            }

            list($contentTypeIdentifier, $fieldDefinitionIdentifier) = explode('/', $data['Field']['identifier'], 2);
        } else {
            if (!isset($data['Field']['contentTypeIdentifier'])) {
                throw new Exceptions\Parser('<Field> sort clause have missing parameter "contentTypeIdentifier"');
            }
            if (!isset($data['Field']['fieldDefinitionIdentifier'])) {
                throw new Exceptions\Parser('<Field> sort clause have missing parameter "fieldDefinitionIdentifier"');
            }

            $contentTypeIdentifier = $data['Field']['contentTypeIdentifier'];
            $fieldDefinitionIdentifier = $data['Field']['fieldDefinitionIdentifier'];
        }

        return new FieldSortClause($contentTypeIdentifier, $fieldDefinitionIdentifier, $direction);
    }
756811
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        return new Client\Values\User\Role(
            array(
                'id' => $data['_href'],
                'identifier' => $data['identifier'],
            )
        );
    }
934776
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        if (!array_key_exists('LocationCreate', $data) || !is_array($data['LocationCreate'])) {
            throw new Exceptions\Parser("Missing or invalid 'LocationCreate' element for ContentCreate.");
        }

        $locationCreateStruct = $this->locationCreateParser->parse($data['LocationCreate'], $parsingDispatcher);

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

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

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

        $contentType = $this->contentTypeService->loadContentType(
            $this->requestParser->parseHref($data['ContentType']['_href'], 'contentTypeId')
        );

        $contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, $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 ContentCreate.");
            }

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

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

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

        if (array_key_exists('modificationDate', $data)) {
            $contentCreateStruct->modificationDate = new DateTime($data['modificationDate']);
        }

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

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

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

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

            $fieldDefinition = $contentType->getFieldDefinition($fieldData['fieldDefinitionIdentifier']);
            if (!$fieldDefinition) {
                throw new Exceptions\Parser(
                    "'{$fieldData['fieldDefinitionIdentifier']}' is invalid field definition identifier for '{$contentType->identifier}' content type in ContentCreate."
                );
            }

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

            $fieldValue = $this->fieldTypeParser->parseValue($fieldDefinition->fieldTypeIdentifier,
                $fieldData['fieldValue']);

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

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

        return new RestContentCreateStruct($contentCreateStruct, $locationCreateStruct);
    }
1320744
final public static function deserialize(array $data)
    {
        return Reconstitution::reconstitute()->objectFrom(
            get_called_class(),
            RecursiveSerializer::deserialize($data, self::deserializationCallbacks())
        );
    }