Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExtensibleDataObjectConverter.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Framework\Api;
8 
11 
16 {
21 
26  {
27  $this->dataObjectProcessor = $dataObjectProcessor;
28  }
29 
38  public function toNestedArray(
39  ExtensibleDataInterface $dataObject,
40  $skipAttributes = [],
41  $dataObjectType = null
42  ) {
43  if ($dataObjectType == null) {
44  $dataObjectType = get_class($dataObject);
45  }
46  $dataObjectArray = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
47  //process custom attributes if present
48  if (!empty($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
50  $customAttributes = $dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY];
51  unset($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY]);
52  foreach ($customAttributes as $attributeValue) {
53  if (!in_array($attributeValue[AttributeValue::ATTRIBUTE_CODE], $skipAttributes)) {
54  $dataObjectArray[$attributeValue[AttributeValue::ATTRIBUTE_CODE]]
55  = $attributeValue[AttributeValue::VALUE];
56  }
57  }
58  }
59  if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
63  foreach ($extensionAttributes as $attributeKey => $attributeValue) {
64  if (!in_array($attributeKey, $skipAttributes)) {
65  $dataObjectArray[$attributeKey] = $attributeValue;
66  }
67  }
68  }
69  return $dataObjectArray;
70  }
71 
80  public function toFlatArray(
81  ExtensibleDataInterface $dataObject,
82  $skipCustomAttributes = [],
83  $dataObjectType = null
84  ) {
85  $dataObjectArray = $this->toNestedArray($dataObject, $skipCustomAttributes, $dataObjectType);
86  return ConvertArray::toFlatArray($dataObjectArray);
87  }
88 
95  public static function convertCustomAttributesToSequentialArray($extensibleObjectData)
96  {
97  $extensibleObjectData[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY] = array_values(
99  );
100  return $extensibleObjectData;
101  }
102 }
toFlatArray(ExtensibleDataInterface $dataObject, $skipCustomAttributes=[], $dataObjectType=null)
$extensionAttributes
Definition: payment.php:22