/** * {@inheritdoc} */ public function call($serviceInfo, $arguments = [], $storeCode = null, $integration = null) { $soapOperation = $this->_getSoapOperation($serviceInfo); $arguments = $this->_converter->convertKeysToCamelCase($arguments); $soapResponse = $this->_getSoapClient($serviceInfo, $storeCode)->{$soapOperation}($arguments); //Convert to snake case for tests to use same assertion data for both SOAP and REST tests $result = is_array($soapResponse) || is_object($soapResponse) ? $this->toSnakeCase($this->_converter->convertStdObjectToArray($soapResponse, true)) : $soapResponse; /** Remove result wrappers */ $result = isset($result[SoapHandler::RESULT_NODE_NAME]) ? $result[SoapHandler::RESULT_NODE_NAME] : $result; return $result; }
/** * Update Data Object with the data from array * * @param mixed $dataObject * @param array $data * @param string $interfaceName * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _setDataValues($dataObject, array $data, $interfaceName) { $dataObjectMethods = get_class_methods(get_class($dataObject)); foreach ($data as $key => $value) { /* First, verify is there any setter for the key on the Service Data Object */ $camelCaseKey = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key); $possibleMethods = ['set' . $camelCaseKey, 'setIs' . $camelCaseKey]; if ($key === CustomAttributesDataInterface::CUSTOM_ATTRIBUTES && $dataObject instanceof ExtensibleDataInterface && is_array($data[$key]) && !empty($data[$key])) { foreach ($data[$key] as $customAttribute) { $dataObject->setCustomAttribute($customAttribute[AttributeInterface::ATTRIBUTE_CODE], $customAttribute[AttributeInterface::VALUE]); } } elseif ($methodNames = array_intersect($possibleMethods, $dataObjectMethods)) { $methodName = array_values($methodNames)[0]; if (!is_array($value)) { if ($methodName === 'setExtensionAttributes' && $value === null) { // Cannot pass a null value to a method with a typed parameter } else { $dataObject->{$methodName}($value); } } else { $getterMethodName = 'get' . $camelCaseKey; $this->setComplexValue($dataObject, $getterMethodName, $methodName, $value, $interfaceName); } } else { if ($dataObject instanceof ExtensibleDataInterface) { $dataObject->setCustomAttribute($key, $value); } } } return $this; }
/** * Load customer group collection data from service * * @param bool $printQuery * @param bool $logQuery * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function loadData($printQuery = false, $logQuery = false) { if (!$this->isLoaded()) { $searchCriteria = $this->getSearchCriteria(); $searchResults = $this->groupRepository->getList($searchCriteria); $this->_totalRecords = $searchResults->getTotalCount(); /** @var GroupInterface[] $groups */ $groups = $searchResults->getItems(); foreach ($groups as $group) { $groupItem = new \Magento\Framework\DataObject(); $groupItem->addData($this->simpleDataObjectConverter->toFlatArray($group, '\\Magento\\Customer\\Api\\Data\\GroupInterface')); $this->_addItem($groupItem); } $this->_setIsLoaded(); } return $this; }
/** * Converts a method's name into a data field name. * * @param string $methodName * @return string|null */ public function getFieldNameForMethodName($methodName) { if (substr($methodName, 0, 2) === self::IS_METHOD_PREFIX) { return SimpleDataObjectConverter::camelCaseToSnakeCase(substr($methodName, 2)); } elseif (substr($methodName, 0, 3) === self::HAS_METHOD_PREFIX) { return SimpleDataObjectConverter::camelCaseToSnakeCase(substr($methodName, 3)); } elseif (substr($methodName, 0, 3) === self::GETTER_PREFIX) { return SimpleDataObjectConverter::camelCaseToSnakeCase(substr($methodName, 3)); } return null; }
public function testCall() { $requestedServices = ['requestedServices']; $this->_requestMock->expects($this->once())->method('getRequestedServices')->will($this->returnValue($requestedServices)); $this->_dataObjectConverter->expects($this->once())->method('convertStdObjectToArray')->will($this->returnValue(['field' => 1])); $operationName = 'soapOperation'; $className = 'Magento\\Framework\\DataObject'; $methodName = 'testMethod'; $isSecure = false; $aclResources = [['Magento_TestModule::resourceA']]; $this->_apiConfigMock->expects($this->once())->method('getServiceMethodInfo')->with($operationName, $requestedServices)->will($this->returnValue([ServiceMetadata::KEY_CLASS => $className, ServiceMetadata::KEY_METHOD => $methodName, ServiceMetadata::KEY_IS_SECURE => $isSecure, ServiceMetadata::KEY_ACL_RESOURCES => $aclResources])); $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $serviceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->setMethods([$methodName])->getMock(); $serviceResponse = ['foo' => 'bar']; $serviceMock->expects($this->once())->method($methodName)->will($this->returnValue($serviceResponse)); $this->_objectManagerMock->expects($this->once())->method('get')->with($className)->will($this->returnValue($serviceMock)); $this->_serviceInputProcessorMock->expects($this->once())->method('process')->will($this->returnArgument(2)); /** Execute SUT. */ $this->assertEquals(['result' => $serviceResponse], $this->_handler->__call($operationName, [(object) ['field' => 1]])); }
/** * {@inheritdoc} */ protected function _getClassMethods() { $methods = []; foreach ($this->getCustomAttributes() as $attributeName => $attributeType) { $propertyName = SimpleDataObjectConverter::snakeCaseToCamelCase($attributeName); $getterName = 'get' . ucfirst($propertyName); $setterName = 'set' . ucfirst($propertyName); $methods[] = ['name' => $getterName, 'body' => "return \$this->_get('{$attributeName}');", 'docblock' => ['tags' => [['name' => 'return', 'description' => $attributeType]]]]; $methods[] = ['name' => $setterName, 'parameters' => [['name' => $propertyName]], 'body' => "\$this->setData('{$attributeName}', \${$propertyName});" . PHP_EOL . "return \$this;", 'docblock' => ['tags' => [['name' => 'param', 'description' => "{$attributeType} \${$propertyName}"], ['name' => 'return', 'description' => '$this']]]]; } return $methods; }
/** * Generate a list of select fields with mapping of client facing attribute names to field names used in SQL select. * * @param string $attributeCode * @param array $selectFields * @return array */ public function getSelectFieldsMap($attributeCode, $selectFields) { $referenceTableAlias = $this->getReferenceTableAlias($attributeCode); $useFieldInAlias = count($selectFields) > 1; $selectFieldsAliases = []; foreach ($selectFields as $selectField) { $internalFieldName = $selectField[Converter::JOIN_FIELD_COLUMN] ? $selectField[Converter::JOIN_FIELD_COLUMN] : $selectField[Converter::JOIN_FIELD]; $setterName = 'set' . ucfirst(SimpleDataObjectConverter::snakeCaseToCamelCase($selectField[Converter::JOIN_FIELD])); $selectFieldsAliases[] = [JoinDataInterface::SELECT_FIELD_EXTERNAL_ALIAS => $attributeCode . ($useFieldInAlias ? '.' . $selectField[Converter::JOIN_FIELD] : ''), JoinDataInterface::SELECT_FIELD_INTERNAL_ALIAS => $referenceTableAlias . '_' . $internalFieldName, JoinDataInterface::SELECT_FIELD_WITH_DB_PREFIX => $referenceTableAlias . '.' . $internalFieldName, JoinDataInterface::SELECT_FIELD_SETTER => $setterName]; } return $selectFieldsAliases; }
/** * {@inheritdoc} */ protected function _getClassMethods() { $methods = []; foreach ($this->getCustomAttributes() as $attributeName => $attributeMetadata) { $attributeType = $attributeMetadata[Converter::DATA_TYPE]; $propertyName = SimpleDataObjectConverter::snakeCaseToCamelCase($attributeName); $getterName = 'get' . ucfirst($propertyName); $setterName = 'set' . ucfirst($propertyName); $methods[] = ['name' => $getterName, 'body' => "return \$this->_get('{$attributeName}');", 'docblock' => ['tags' => [['name' => 'return', 'description' => $attributeType . '|null']]]]; $parameters = ['name' => $propertyName]; // If the attribute type is a valid type declaration (e.g., interface, class, array) then use it to enforce // constraints on the generated setter methods if ($this->getTypeProcessor()->isValidTypeDeclaration($attributeType)) { $parameters['type'] = $attributeType; } $methods[] = ['name' => $setterName, 'parameters' => [$parameters], 'body' => "\$this->setData('{$attributeName}', \${$propertyName});" . PHP_EOL . "return \$this;", 'docblock' => ['tags' => [['name' => 'param', 'description' => "{$attributeType} \${$propertyName}"], ['name' => 'return', 'description' => '$this']]]]; } return $methods; }
/** * Convert service response into format acceptable by SoapServer. * * @param object|array|string|int|float|null $data * @param string $serviceClassName * @param string $serviceMethodName * @return array * @throws \InvalidArgumentException */ protected function _prepareResponseData($data, $serviceClassName, $serviceMethodName) { /** @var string $dataType */ $dataType = $this->methodsMapProcessor->getMethodReturnType($serviceClassName, $serviceMethodName); $result = null; if (is_object($data)) { $result = $this->_dataObjectConverter->convertKeysToCamelCase($this->_dataObjectProcessor->buildOutputDataArray($data, $dataType)); } elseif (is_array($data)) { $dataType = substr($dataType, 0, -2); foreach ($data as $key => $value) { if ($value instanceof ExtensibleDataInterface || $value instanceof MetadataObjectInterface) { $result[] = $this->_dataObjectConverter->convertKeysToCamelCase($this->_dataObjectProcessor->buildOutputDataArray($value, $dataType)); } else { $result[$key] = $value; } } } elseif (is_scalar($data) || $data === null) { $result = $data; } else { throw new \InvalidArgumentException("Service returned result in invalid format."); } return [self::RESULT_NODE_NAME => $result]; }
/** * Derive the custom attribute code and value. * * @param string[] $customAttribute * @return string[] */ private function processCustomAttribute($customAttribute) { $camelCaseAttributeCodeKey = lcfirst(SimpleDataObjectConverter::snakeCaseToUpperCamelCase(AttributeValue::ATTRIBUTE_CODE)); // attribute code key could be snake or camel case, depending on whether SOAP or REST is used. if (isset($customAttribute[AttributeValue::ATTRIBUTE_CODE])) { $customAttributeCode = $customAttribute[AttributeValue::ATTRIBUTE_CODE]; } elseif (isset($customAttribute[$camelCaseAttributeCodeKey])) { $customAttributeCode = $customAttribute[$camelCaseAttributeCodeKey]; } else { $customAttributeCode = null; } if (!$customAttributeCode && !isset($customAttribute[AttributeValue::VALUE])) { throw new SerializationException(new Phrase('There is an empty custom attribute specified.')); } else { if (!$customAttributeCode) { throw new SerializationException(new Phrase('A custom attribute is specified without an attribute code.')); } else { if (!isset($customAttribute[AttributeValue::VALUE])) { throw new SerializationException(new Phrase('Value is not set for attribute code "' . $customAttributeCode . '"')); } } } return [$customAttributeCode, $customAttribute[AttributeValue::VALUE]]; }
/** * Check presence for both camelCase and snake_case keys in array and substitute if either is present * * @param array $requestData * @param string $key * @param string $value * @return void */ protected function substituteParameters(&$requestData, $key, $value) { $snakeCaseKey = SimpleDataObjectConverter::camelCaseToSnakeCase($key); $camelCaseKey = SimpleDataObjectConverter::snakeCaseToCamelCase($key); if (isset($requestData[$camelCaseKey])) { $requestData[$camelCaseKey] = $value; } else { $requestData[$snakeCaseKey] = $value; } }
/** * @param mixed $dataObject * @param string $getterMethodName * @param string $methodName * @param array $value * @param string $interfaceName * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function setComplexValue($dataObject, $getterMethodName, $methodName, array $value, $interfaceName) { if ($interfaceName == null) { $interfaceName = get_class($dataObject); } $returnType = $this->methodsMapProcessor->getMethodReturnType($interfaceName, $getterMethodName); if ($this->typeProcessor->isTypeSimple($returnType)) { $dataObject->{$methodName}($value); return $this; } if ($this->typeProcessor->isArrayType($returnType)) { $type = $this->typeProcessor->getArrayItemType($returnType); $objects = []; foreach ($value as $arrayElementData) { $object = $this->objectFactory->create($type, []); $this->populateWithArray($object, $arrayElementData, $type); $objects[] = $object; } $dataObject->{$methodName}($objects); return $this; } if (is_subclass_of($returnType, '\\Magento\\Framework\\Api\\ExtensibleDataInterface')) { $object = $this->objectFactory->create($returnType, []); $this->populateWithArray($object, $value, $returnType); } else { if (is_subclass_of($returnType, '\\Magento\\Framework\\Api\\ExtensionAttributesInterface')) { foreach ($value as $extensionAttributeKey => $extensionAttributeValue) { $extensionAttributeGetterMethodName = 'get' . \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($extensionAttributeKey); $methodReturnType = $this->methodsMapProcessor->getMethodReturnType($returnType, $extensionAttributeGetterMethodName); $extensionAttributeType = $this->typeProcessor->isArrayType($methodReturnType) ? $this->typeProcessor->getArrayItemType($methodReturnType) : $methodReturnType; if ($this->typeProcessor->isTypeSimple($extensionAttributeType)) { $value[$extensionAttributeKey] = $extensionAttributeValue; } else { if ($this->typeProcessor->isArrayType($methodReturnType)) { foreach ($extensionAttributeValue as $key => $extensionAttributeArrayValue) { $extensionAttribute = $this->objectFactory->create($extensionAttributeType, []); $this->populateWithArray($extensionAttribute, $extensionAttributeArrayValue, $extensionAttributeType); $value[$extensionAttributeKey][$key] = $extensionAttribute; } } else { $value[$extensionAttributeKey] = $this->objectFactory->create($extensionAttributeType, ['data' => $extensionAttributeValue]); } } } $object = $this->extensionFactory->create(get_class($dataObject), ['data' => $value]); } else { $object = $this->objectFactory->create($returnType, $value); } } $dataObject->{$methodName}($object); return $this; }
/** * Use class reflection on given data interface to build output data array * * @param mixed $dataObject * @param string $dataObjectType * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function buildOutputDataArray($dataObject, $dataObjectType) { $methods = $this->getMethodsMap($dataObjectType); $outputData = []; /** @var MethodReflection $method */ foreach ($methods as $methodName => $methodReflectionData) { // any method with parameter(s) gets ignored because we do not know the type and value of // the parameter(s), so we are not able to process if ($methodReflectionData['parameterCount'] > 0) { continue; } $returnType = $methodReflectionData['type']; if (substr($methodName, 0, 2) === self::IS_METHOD_PREFIX) { $value = $dataObject->{$methodName}(); if ($value === null && !$methodReflectionData['isRequired']) { continue; } $key = SimpleDataObjectConverter::camelCaseToSnakeCase(substr($methodName, 2)); $outputData[$key] = $this->castValueToType($value, $returnType); } elseif (substr($methodName, 0, 3) === self::HAS_METHOD_PREFIX) { $value = $dataObject->{$methodName}(); if ($value === null && !$methodReflectionData['isRequired']) { continue; } $key = SimpleDataObjectConverter::camelCaseToSnakeCase(substr($methodName, 3)); $outputData[$key] = $this->castValueToType($value, $returnType); } elseif (substr($methodName, 0, 3) === self::GETTER_PREFIX) { $value = $dataObject->{$methodName}(); if ($methodName === 'getCustomAttributes' && $value === []) { continue; } if ($value === null && !$methodReflectionData['isRequired']) { continue; } $key = SimpleDataObjectConverter::camelCaseToSnakeCase(substr($methodName, 3)); if ($key === CustomAttributesDataInterface::CUSTOM_ATTRIBUTES) { $value = $this->convertCustomAttributes($value, $dataObjectType); } elseif (is_object($value) && !$value instanceof Phrase) { $value = $this->buildOutputDataArray($value, $returnType); } elseif (is_array($value)) { $valueResult = []; $arrayElementType = substr($returnType, 0, -2); foreach ($value as $singleValue) { if (is_object($singleValue) && !$singleValue instanceof Phrase) { $singleValue = $this->buildOutputDataArray($singleValue, $arrayElementType); } $valueResult[] = $this->castValueToType($singleValue, $arrayElementType); } $value = $valueResult; } $outputData[$key] = $this->castValueToType($value, $returnType); } } return $outputData; }
/** * {@inheritdoc} */ public function getCustomAttributesMetadata($dataObjectClassName = AddressMetadataInterface::DATA_INTERFACE_NAME) { if (!$this->addressDataObjectMethods) { $dataObjectMethods = array_flip(get_class_methods($dataObjectClassName)); $baseClassDataObjectMethods = array_flip(get_class_methods('Magento\\Framework\\Api\\AbstractExtensibleObject')); $this->addressDataObjectMethods = array_diff_key($dataObjectMethods, $baseClassDataObjectMethods); } $customAttributes = []; foreach ($this->getAllAttributesMetadata() as $attributeMetadata) { $attributeCode = $attributeMetadata->getAttributeCode(); $camelCaseKey = SimpleDataObjectConverter::snakeCaseToUpperCamelCase($attributeCode); $isDataObjectMethod = isset($this->addressDataObjectMethods['get' . $camelCaseKey]) || isset($this->addressDataObjectMethods['is' . $camelCaseKey]); if (!$isDataObjectMethod && !$attributeMetadata->isSystem()) { $customAttributes[] = $attributeMetadata; } } return $customAttributes; }
/** * Map criteria to Select Query Object * * @param CriteriaInterface $criteria * @return Select */ public function map(CriteriaInterface $criteria) { $criteriaParts = $criteria->toArray(); foreach ($criteriaParts as $key => $value) { $camelCaseKey = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key); $mapperMethod = 'map' . $camelCaseKey; if (method_exists($this, $mapperMethod)) { if (!is_array($value)) { $value = [$value]; } call_user_func_array([$this, $mapperMethod], $value); } } return $this->select; }
/** * Initializes Data Object with the data from array * * @param array $data * @return $this */ protected function _setDataValues(array $data) { $dataObjectMethods = get_class_methods($this->_getDataObjectType()); foreach ($data as $key => $value) { /* First, verify is there any getter for the key on the Service Data Object */ $camelCaseKey = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key); $possibleMethods = ['get' . $camelCaseKey, 'is' . $camelCaseKey]; if ($key === ExtensibleDataInterface::CUSTOM_ATTRIBUTES && is_array($data[$key]) && !empty($data[$key])) { foreach ($data[$key] as $customAttribute) { $this->setCustomAttribute($customAttribute[AttributeInterface::ATTRIBUTE_CODE], $customAttribute[AttributeInterface::VALUE]); } } elseif ($methodName = array_intersect($possibleMethods, $dataObjectMethods)) { if (!is_array($value)) { $this->data[$key] = $value; } else { $this->setComplexValue($methodName[0], $key, $value); } } elseif (in_array($key, $this->getCustomAttributesCodes())) { $this->setCustomAttribute($key, $value); } } return $this; }
/** * Format $name (JSON or XML) to the valid property name (camelCase with lowercase first). * Sample: 'json_prop_name' => 'jsonPropName'. * * @param $name * @return string */ public function formatPropertyName($name) { $result = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToCamelCase($name); return $result; }
public function getSubTabSuffix() { return SimpleDataObjectConverter::snakeCaseToCamelCase(str_replace('.', '_', $this->getNameInLayout())); }
/** * Converts associative array's key names from camelCase to snake_case, recursively. * * @param array $properties * @return array */ private function convertArrayToSnakeCase($properties) { foreach ($properties as $name => $value) { $snakeCaseName = SimpleDataObjectConverter::camelCaseToSnakeCase($name); if (is_array($value)) { $value = $this->convertArrayToSnakeCase($value); } unset($properties[$name]); $properties[$snakeCaseName] = $value; } return $properties; }
/** * @param string $field * @return string|null */ public function getConfigFieldValue($field) { $stockItem = $this->getStockItem(); if ($stockItem->getItemId()) { $method = 'getUseConfig' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($field); if (method_exists($stockItem, $method)) { return $stockItem->{$method}(); } } return $this->stockConfiguration->getDefaultConfigValue($field); }
/** * {@inheritdoc} */ public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_INTERFACE_NAME) { $customAttributes = []; if (!$this->customerDataObjectMethods) { $dataObjectMethods = array_flip(get_class_methods($dataObjectClassName)); $baseClassDataObjectMethods = array_flip(get_class_methods('Magento\\Framework\\Api\\AbstractExtensibleObject')); $this->customerDataObjectMethods = array_diff_key($dataObjectMethods, $baseClassDataObjectMethods); } foreach ($this->getAllAttributesMetadata() as $attributeMetadata) { $attributeCode = $attributeMetadata->getAttributeCode(); $camelCaseKey = SimpleDataObjectConverter::snakeCaseToUpperCamelCase($attributeCode); $isDataObjectMethod = isset($this->customerDataObjectMethods['get' . $camelCaseKey]) || isset($this->customerDataObjectMethods['is' . $camelCaseKey]); /** Even though disable_auto_group_change is system attribute, it should be available to the clients */ if (!$isDataObjectMethod && (!$attributeMetadata->isSystem() || $attributeCode == 'disable_auto_group_change')) { $customAttributes[] = $attributeMetadata; } } return $customAttributes; }
private function snakeToUCamel($input) { return \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($input); }
public function snakeCaseToUpperCamelCase($data) { $result = \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($data); return $result; }
/** * Convert custom attribute data array to array of AttributeValue Data Object * * @param array $customAttributesValueArray * @param string $dataObjectClassName * @return AttributeValue[] */ protected function convertCustomAttributeValue($customAttributesValueArray, $dataObjectClassName) { $result = []; $dataObjectClassName = ltrim($dataObjectClassName, '\\'); $camelCaseAttributeCodeKey = lcfirst(SimpleDataObjectConverter::snakeCaseToUpperCamelCase(AttributeValue::ATTRIBUTE_CODE)); foreach ($customAttributesValueArray as $key => $customAttribute) { if (!is_array($customAttribute)) { $customAttribute = [AttributeValue::ATTRIBUTE_CODE => $key, AttributeValue::VALUE => $customAttribute]; } if (isset($customAttribute[AttributeValue::ATTRIBUTE_CODE])) { $customAttributeCode = $customAttribute[AttributeValue::ATTRIBUTE_CODE]; } elseif (isset($customAttribute[$camelCaseAttributeCodeKey])) { $customAttributeCode = $customAttribute[$camelCaseAttributeCodeKey]; } else { $customAttributeCode = null; } //Check if type is defined, else default to string $type = $this->customAttributeTypeLocator->getType($customAttributeCode, $dataObjectClassName); $type = $type ? $type : TypeProcessor::ANY_TYPE; $customAttributeValue = $customAttribute[AttributeValue::VALUE]; if (is_array($customAttributeValue)) { //If type for AttributeValue's value as array is mixed, further processing is not possible if ($type === TypeProcessor::ANY_TYPE) { $attributeValue = $customAttributeValue; } else { $attributeValue = $this->_createDataObjectForTypeAndArrayValue($type, $customAttributeValue); } } else { $attributeValue = $this->convertValue($customAttributeValue, $type); } //Populate the attribute value data object once the value for custom attribute is derived based on type $result[$customAttributeCode] = $this->attributeValueFactory->create()->setAttributeCode($customAttributeCode)->setValue($attributeValue); } return $result; }
/** * Convert custom attribute data array to array of AttributeValue Data Object * * @param array $customAttributesValueArray * @param string $returnType * @param string $dataObjectClassName * @return AttributeValue[] */ protected function convertCustomAttributeValue($customAttributesValueArray, $returnType, $dataObjectClassName) { $result = []; $allAttributes = $this->serviceConfigReader->read(); $dataObjectClassName = ltrim($dataObjectClassName, '\\'); if (!isset($allAttributes[$dataObjectClassName])) { return $this->_convertValue($customAttributesValueArray, $returnType); } $dataObjectAttributes = $allAttributes[$dataObjectClassName]; $camelCaseAttributeCodeKey = lcfirst(SimpleDataObjectConverter::snakeCaseToUpperCamelCase(AttributeValue::ATTRIBUTE_CODE)); foreach ($customAttributesValueArray as $customAttribute) { if (isset($customAttribute[AttributeValue::ATTRIBUTE_CODE])) { $customAttributeCode = $customAttribute[AttributeValue::ATTRIBUTE_CODE]; } elseif (isset($customAttribute[$camelCaseAttributeCodeKey])) { $customAttributeCode = $customAttribute[$camelCaseAttributeCodeKey]; } else { $customAttributeCode = null; } //Check if type is defined, else default to mixed $type = isset($dataObjectAttributes[$customAttributeCode]) ? $dataObjectAttributes[$customAttributeCode] : TypeProcessor::ANY_TYPE; $customAttributeValue = $customAttribute[AttributeValue::VALUE]; if (is_array($customAttributeValue)) { //If type for AttributeValue's value as array is mixed, further processing is not possible if ($type === TypeProcessor::ANY_TYPE) { continue; } $attributeValue = $this->_createDataObjectForTypeAndArrayValue($type, $customAttributeValue); } else { $attributeValue = $this->_convertValue($customAttributeValue, $type); } //Populate the attribute value data object once the value for custom attribute is derived based on type $result[] = $this->attributeValueBuilder->setAttributeCode($customAttributeCode)->setValue($attributeValue)->create(); } return $result; }
/** * Verify property in parameter's object * * @param string $serviceClassName name of the service class that we are trying to call * @param string $serviceMethodName name of the method that we are trying to call * @param string $serviceMethodParamName * @param string $objectProperty * @return bool */ private function isPropertyDeclaredInDataObject($serviceClassName, $serviceMethodName, $serviceMethodParamName, $objectProperty) { if ($serviceClassName && $serviceMethodName) { $methodParams = $this->getMethodsMap()->getMethodParams($serviceClassName, $serviceMethodName); $index = array_search($serviceMethodParamName, array_column($methodParams, 'name')); if ($index !== false) { $paramObjectType = $methodParams[$index][MethodsMap::METHOD_META_TYPE]; $setter = 'set' . ucfirst(SimpleDataObjectConverter::snakeCaseToCamelCase($objectProperty)); if (array_key_exists($setter, $this->getMethodsMap()->getMethodsMap($paramObjectType))) { return true; } } } return false; }