Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ServiceOutputProcessor.php
Go to the documentation of this file.
1 <?php
7 
12 
20 {
25 
30 
35  public function __construct(
38  ) {
39  $this->dataObjectProcessor = $dataObjectProcessor;
40  $this->methodsMapProcessor = $methodsMapProcessor;
41  }
42 
57  public function process($data, $serviceClassName, $serviceMethodName)
58  {
60  $dataType = $this->methodsMapProcessor->getMethodReturnType($serviceClassName, $serviceMethodName);
61  return $this->convertValue($data, $dataType);
62  }
63 
70  protected function processDataObject($dataObjectArray)
71  {
72  if (isset($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
74  $dataObjectArray
75  );
76  }
77  //Check for nested custom_attributes
78  foreach ($dataObjectArray as $key => $value) {
79  if (is_array($value)) {
80  $dataObjectArray[$key] = $this->processDataObject($value);
81  }
82  }
83  return $dataObjectArray;
84  }
85 
93  public function convertValue($data, $type)
94  {
95  if (is_array($data)) {
96  $result = [];
97  $arrayElementType = substr($type, 0, -2);
98  foreach ($data as $datum) {
99  if (is_object($datum)) {
100  $datum = $this->processDataObject(
101  $this->dataObjectProcessor->buildOutputDataArray($datum, $arrayElementType)
102  );
103  }
104  $result[] = $datum;
105  }
106  return $result;
107  } elseif (is_object($data)) {
108  return $this->processDataObject(
109  $this->dataObjectProcessor->buildOutputDataArray($data, $type)
110  );
111  } elseif ($data === null) {
112  return [];
113  } else {
115  return $data;
116  }
117  }
118 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
__construct(DataObjectProcessor $dataObjectProcessor, MethodsMap $methodsMapProcessor)