13
13
use Magento \Framework \Api \SimpleDataObjectConverter ;
14
14
use Magento \Framework \App \ObjectManager ;
15
15
use Magento \Framework \Exception \InputException ;
16
+ use Magento \Framework \Exception \InvalidArgumentException ;
17
+ use Magento \Framework \Exception \LocalizedException ;
16
18
use Magento \Framework \Exception \SerializationException ;
17
19
use Magento \Framework \ObjectManager \ConfigInterface ;
18
20
use Magento \Framework \ObjectManagerInterface ;
@@ -37,7 +39,7 @@ class ServiceInputProcessor implements ServicePayloadConverterInterface
37
39
public const EXTENSION_ATTRIBUTES_TYPE = \Magento \Framework \Api \ExtensionAttributesInterface::class;
38
40
39
41
/**
40
- * @var \Magento\Framework\Reflection\ TypeProcessor
42
+ * @var TypeProcessor
41
43
*/
42
44
protected $ typeProcessor ;
43
45
@@ -220,7 +222,7 @@ public function process($serviceClassName, $serviceMethodName, array $inputArray
220
222
* @param array $data
221
223
* @return array
222
224
* @throws \ReflectionException
223
- * @throws \Magento\Framework\Exception\ LocalizedException
225
+ * @throws LocalizedException
224
226
*/
225
227
private function getConstructorData (string $ className , array $ data ): array
226
228
{
@@ -498,34 +500,51 @@ protected function _createDataObjectForTypeAndArrayValue($type, $customAttribute
498
500
* @param mixed $data
499
501
* @param string $type Convert given value to the this type
500
502
* @return mixed
501
- * @throws \Magento\Framework\Exception\ LocalizedException
503
+ * @throws LocalizedException
502
504
*/
503
505
public function convertValue ($ data , $ type )
504
506
{
505
- $ isArrayType = $ this ->typeProcessor ->isArrayType ($ type );
506
- if ($ isArrayType && isset ($ data ['item ' ])) {
507
+ if ($ this ->typeProcessor ->isArrayType ($ type ) && isset ($ data ['item ' ])) {
507
508
$ data = $ this ->_removeSoapItemNode ($ data );
508
509
}
510
+
509
511
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 );
527
545
}
528
546
}
547
+
529
548
return $ result ;
530
549
}
531
550
0 commit comments