diff --git a/vendor/magento/module-webapi-async/Model/OperationRepository.php b/vendor/magento/module-webapi-async/Model/OperationRepository.php index 31b43cbcf779c..1f8c476f7a34b 100644 --- a/vendor/magento/module-webapi-async/Model/OperationRepository.php +++ b/vendor/magento/module-webapi-async/Model/OperationRepository.php @@ -13,6 +13,7 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\MessageQueue\MessageValidator; +use Magento\Framework\MessageQueue\MessageEncoder; use Magento\Framework\Serialize\Serializer\Json; use Magento\Framework\EntityManager\EntityManager; use Magento\Store\Model\StoreManagerInterface; @@ -42,6 +43,12 @@ class OperationRepository implements OperationRepositoryInterface * @var MessageValidator */ private $messageValidator; + + /** + * @var MessageEncoder + */ + private $messageEncoder; + /** * @var InputParamsResolver */ @@ -61,6 +68,7 @@ class OperationRepository implements OperationRepositoryInterface * @param Json $jsonSerializer * @param InputParamsResolver $inputParamsResolver * @param StoreManagerInterface|null $storeManager + * @param MessageEncoder|null $messageEncoder */ public function __construct( OperationInterfaceFactory $operationFactory, @@ -68,7 +76,8 @@ public function __construct( MessageValidator $messageValidator, Json $jsonSerializer, InputParamsResolver $inputParamsResolver, - ?StoreManagerInterface $storeManager = null + ?StoreManagerInterface $storeManager = null, + ?MessageEncoder $messageEncoder = null ) { $this->operationFactory = $operationFactory; $this->jsonSerializer = $jsonSerializer; @@ -76,6 +85,7 @@ public function __construct( $this->entityManager = $entityManager; $this->inputParamsResolver = $inputParamsResolver; $this->storeManager = $storeManager?: ObjectManager::getInstance()->get(StoreManagerInterface::class); + $this->messageEncoder = $messageEncoder ?: ObjectManager::getInstance()->get(MessageEncoder::class); } /** @@ -83,15 +93,15 @@ public function __construct( */ public function create($topicName, $entityParams, $groupId, $operationId): OperationInterface { - - $this->messageValidator->validate($topicName, $entityParams); $requestData = $this->inputParamsResolver->getInputData(); if ($operationId === null || !isset($requestData[$operationId])) { throw new \InvalidArgumentException( 'Parameter "$operationId" must not be NULL and must exist in input data' ); } - $encodedMessage = $this->jsonSerializer->serialize($requestData[$operationId]); + + $this->messageValidator->validate($topicName, $entityParams); + $encodedMessage = $this->messageEncoder->encode($topicName, $entityParams); $serializedData = [ 'entity_id' => null, diff --git a/vendor/magento/framework/Reflection/DataObjectProcessor.php b/vendor/magento/framework/Reflection/DataObjectProcessor.php index 94023d129d1db..7940bb9f98c0e 100644 --- a/vendor/magento/framework/Reflection/DataObjectProcessor.php +++ b/vendor/magento/framework/Reflection/DataObjectProcessor.php @@ -13,6 +13,8 @@ * * @api * @since 100.0.2 + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class DataObjectProcessor { @@ -126,21 +128,7 @@ public function buildOutputDataArray($dataObject, $dataObjectType) continue; } } else { - if (is_object($value) && !($value instanceof Phrase)) { - $value = $this->buildOutputDataArray($value, $returnType); - } elseif (is_array($value)) { - $valueResult = []; - $arrayElementType = $returnType !== null ? substr($returnType, 0, -2) : ''; - foreach ($value as $singleValue) { - if (is_object($singleValue) && !($singleValue instanceof Phrase)) { - $singleValue = $this->buildOutputDataArray($singleValue, $arrayElementType); - } - $valueResult[] = $this->typeCaster->castValueToType($singleValue, $arrayElementType); - } - $value = $valueResult; - } else { - $value = $this->typeCaster->castValueToType($value, $returnType); - } + $value = $this->processValue($value, $returnType); } $outputData[$key] = $value; @@ -151,6 +139,35 @@ public function buildOutputDataArray($dataObject, $dataObjectType) return $outputData; } + /** + * Process value based on its type and return type + * + * @param mixed $value + * @param string $returnType + * @return mixed + */ + private function processValue($value, $returnType) + { + if (is_object($value) && !($value instanceof Phrase)) { + return $this->buildOutputDataArray($value, $returnType); + } + if (is_array($value)) { + if ($returnType === TypeProcessor::UNSTRUCTURED_ARRAY) { + return $value; + } + $valueResult = []; + $arrayElementType = $returnType !== null ? substr($returnType, 0, -2) : ''; + foreach ($value as $singleValue) { + if (is_object($singleValue) && !($singleValue instanceof Phrase)) { + $singleValue = $this->buildOutputDataArray($singleValue, $arrayElementType); + } + $valueResult[] = $this->typeCaster->castValueToType($singleValue, $arrayElementType); + } + return $valueResult; + } + return $this->typeCaster->castValueToType($value, $returnType); + } + /** * Change output array if needed. *