Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataObjectProcessor.php
Go to the documentation of this file.
1 <?php
7 
10 
18 {
22  private $methodsMapProcessor;
23 
27  private $typeCaster;
28 
32  private $fieldNamer;
33 
37  private $extensionAttributesProcessor;
38 
42  private $customAttributesProcessor;
43 
51  public function __construct(
52  MethodsMap $methodsMapProcessor,
53  TypeCaster $typeCaster,
54  FieldNamer $fieldNamer,
55  CustomAttributesProcessor $customAttributesProcessor,
56  ExtensionAttributesProcessor $extensionAttributesProcessor
57  ) {
58  $this->methodsMapProcessor = $methodsMapProcessor;
59  $this->typeCaster = $typeCaster;
60  $this->fieldNamer = $fieldNamer;
61  $this->extensionAttributesProcessor = $extensionAttributesProcessor;
62  $this->customAttributesProcessor = $customAttributesProcessor;
63  }
64 
73  public function buildOutputDataArray($dataObject, $dataObjectType)
74  {
75  $methods = $this->methodsMapProcessor->getMethodsMap($dataObjectType);
76  $outputData = [];
77 
78  foreach (array_keys($methods) as $methodName) {
79  if (!$this->methodsMapProcessor->isMethodValidForDataField($dataObjectType, $methodName)) {
80  continue;
81  }
82 
83  $value = $dataObject->{$methodName}();
84  $isMethodReturnValueRequired = $this->methodsMapProcessor->isMethodReturnValueRequired(
85  $dataObjectType,
86  $methodName
87  );
88  if ($value === null && !$isMethodReturnValueRequired) {
89  continue;
90  }
91 
92  $returnType = $this->methodsMapProcessor->getMethodReturnType($dataObjectType, $methodName);
93  $key = $this->fieldNamer->getFieldNameForMethodName($methodName);
95  continue;
96  }
97 
99  $value = $this->customAttributesProcessor->buildOutputDataArray($dataObject, $dataObjectType);
100  } elseif ($key === "extension_attributes") {
101  $value = $this->extensionAttributesProcessor->buildOutputDataArray($value, $returnType);
102  if (empty($value)) {
103  continue;
104  }
105  } else {
106  if (is_object($value) && !($value instanceof Phrase)) {
107  $value = $this->buildOutputDataArray($value, $returnType);
108  } elseif (is_array($value)) {
109  $valueResult = [];
110  $arrayElementType = substr($returnType, 0, -2);
111  foreach ($value as $singleValue) {
112  if (is_object($singleValue) && !($singleValue instanceof Phrase)) {
113  $singleValue = $this->buildOutputDataArray($singleValue, $arrayElementType);
114  }
115  $valueResult[] = $this->typeCaster->castValueToType($singleValue, $arrayElementType);
116  }
117  $value = $valueResult;
118  } else {
119  $value = $this->typeCaster->castValueToType($value, $returnType);
120  }
121  }
122 
123  $outputData[$key] = $value;
124  }
125  return $outputData;
126  }
127 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(MethodsMap $methodsMapProcessor, TypeCaster $typeCaster, FieldNamer $fieldNamer, CustomAttributesProcessor $customAttributesProcessor, ExtensionAttributesProcessor $extensionAttributesProcessor)
$methods
Definition: billing.phtml:71
$value
Definition: gender.phtml:16