1313use Magento \Framework \Api \SimpleDataObjectConverter ;
1414use Magento \Framework \App \ObjectManager ;
1515use Magento \Framework \Exception \InputException ;
16+ use Magento \Framework \Exception \InvalidArgumentException ;
17+ use Magento \Framework \Exception \LocalizedException ;
1618use Magento \Framework \Exception \SerializationException ;
1719use Magento \Framework \ObjectManager \ConfigInterface ;
1820use Magento \Framework \ObjectManagerInterface ;
@@ -37,7 +39,7 @@ class ServiceInputProcessor implements ServicePayloadConverterInterface
3739 public const EXTENSION_ATTRIBUTES_TYPE = \Magento \Framework \Api \ExtensionAttributesInterface::class;
3840
3941 /**
40- * @var \Magento\Framework\Reflection\ TypeProcessor
42+ * @var TypeProcessor
4143 */
4244 protected $ typeProcessor ;
4345
@@ -220,7 +222,7 @@ public function process($serviceClassName, $serviceMethodName, array $inputArray
220222 * @param array $data
221223 * @return array
222224 * @throws \ReflectionException
223- * @throws \Magento\Framework\Exception\ LocalizedException
225+ * @throws LocalizedException
224226 */
225227 private function getConstructorData (string $ className , array $ data ): array
226228 {
@@ -498,34 +500,51 @@ protected function _createDataObjectForTypeAndArrayValue($type, $customAttribute
498500 * @param mixed $data
499501 * @param string $type Convert given value to the this type
500502 * @return mixed
501- * @throws \Magento\Framework\Exception\ LocalizedException
503+ * @throws LocalizedException
502504 */
503505 public function convertValue ($ data , $ type )
504506 {
505- $ isArrayType = $ this ->typeProcessor ->isArrayType ($ type );
506- if ($ isArrayType && isset ($ data ['item ' ])) {
507+ if ($ this ->typeProcessor ->isArrayType ($ type ) && isset ($ data ['item ' ])) {
507508 $ data = $ this ->_removeSoapItemNode ($ data );
508509 }
510+
509511 if ($ this ->typeProcessor ->isTypeSimple ($ type ) || $ this ->typeProcessor ->isTypeAny ($ type )) {
510- $ result = $ this ->typeProcessor ->processSimpleAndAnyType ($ data , $ type );
511- } elseif ($ type == 'UnstructuredArray ' ) {
512- $ result = $ data ;
513- } else {
514- /** Complex type or array of complex types */
515- if ($ isArrayType ) {
516- // Initializing the result for array type else it will return null for empty array
517- $ result = is_array ($ data ) ? [] : null ;
518- $ itemType = $ this ->typeProcessor ->getArrayItemType ($ type );
519- if (is_array ($ data )) {
520- $ this ->serviceInputValidator ->validateComplexArrayType ($ itemType , $ data );
521- foreach ($ data as $ key => $ item ) {
522- $ result [$ key ] = $ this ->_createFromArray ($ itemType , $ item );
523- }
524- }
525- } else {
526- $ result = $ this ->_createFromArray ($ type , $ data );
512+ return $ this ->typeProcessor ->processSimpleAndAnyType ($ data , $ type );
513+ }
514+
515+ if ($ type == TypeProcessor::UNSTRUCTURED_ARRAY ) {
516+ return $ data ;
517+ }
518+
519+ return $ this ->processComplexTypes ($ data , $ type );
520+ }
521+
522+ /**
523+ * Process complex types or array of complex types.
524+ *
525+ * @param mixed $data
526+ * @param string $type
527+ * @return array|object|SearchCriteriaInterface
528+ * @throws SerializationException
529+ * @throws InvalidArgumentException
530+ */
531+ private function processComplexTypes ($ data , $ type ) {
532+ $ isArrayType = $ this ->typeProcessor ->isArrayType ($ type );
533+
534+ if (!$ isArrayType ) {
535+ return $ this ->_createFromArray ($ type , $ data );
536+ }
537+
538+ $ result = is_array ($ data ) ? [] : null ;
539+ $ itemType = $ this ->typeProcessor ->getArrayItemType ($ type );
540+
541+ if (is_array ($ data )) {
542+ $ this ->serviceInputValidator ->validateComplexArrayType ($ itemType , $ data );
543+ foreach ($ data as $ key => $ item ) {
544+ $ result [$ key ] = $ this ->_createFromArray ($ itemType , $ item );
527545 }
528546 }
547+
529548 return $ result ;
530549 }
531550
0 commit comments