18
18
*/
19
19
class DataObjectProcessor
20
20
{
21
- const IS_METHOD_PREFIX = 'is ' ;
22
- const HAS_METHOD_PREFIX = 'has ' ;
23
- const GETTER_PREFIX = 'get ' ;
24
-
25
- /**
26
- * @var \Magento\Framework\Api\AttributeTypeResolverInterface
27
- */
28
- protected $ attributeTypeResolver ;
29
-
30
21
/**
31
22
* @var MethodsMap
32
23
*/
@@ -48,20 +39,17 @@ class DataObjectProcessor
48
39
private $ fieldNamer ;
49
40
50
41
/**
51
- * @param \Magento\Framework\Api\AttributeTypeResolverInterface $typeResolver
52
42
* @param MethodsMap $methodsMapProcessor
53
43
* @param ExtensionAttributesProcessor $extensionAttributesProcessor
54
44
* @param TypeCaster $typeCaster
55
45
* @param FieldNamer $fieldNamer
56
46
*/
57
47
public function __construct (
58
- \Magento \Framework \Api \AttributeTypeResolverInterface $ typeResolver ,
59
48
MethodsMap $ methodsMapProcessor ,
60
49
ExtensionAttributesProcessor $ extensionAttributesProcessor ,
61
50
TypeCaster $ typeCaster ,
62
51
FieldNamer $ fieldNamer
63
52
) {
64
- $ this ->attributeTypeResolver = $ typeResolver ;
65
53
$ this ->methodsMapProcessor = $ methodsMapProcessor ;
66
54
$ this ->extensionAttributesProcessor = $ extensionAttributesProcessor ;
67
55
$ this ->typeCaster = $ typeCaster ;
@@ -100,7 +88,7 @@ public function buildOutputDataArray($dataObject, $dataObjectType)
100
88
}
101
89
102
90
if ($ key === CustomAttributesDataInterface::CUSTOM_ATTRIBUTES ) {
103
- $ value = $ this ->convertCustomAttributes ( $ value , $ dataObjectType );
91
+ $ value = $ this ->customAttributesProcessor -> buildOutputDataArray ( $ dataObject , $ dataObjectType );
104
92
} elseif ($ key === "extension_attributes " ) {
105
93
$ value = $ this ->extensionAttributesProcessor ->buildOutputDataArray ($ value , $ returnType );
106
94
} else {
@@ -125,59 +113,4 @@ public function buildOutputDataArray($dataObject, $dataObjectType)
125
113
}
126
114
return $ outputData ;
127
115
}
128
-
129
- /**
130
- * Convert array of custom_attributes to use flat array structure
131
- *
132
- * @param \Magento\Framework\Api\AttributeInterface[] $customAttributes
133
- * @param string $dataObjectType
134
- * @return array
135
- */
136
- protected function convertCustomAttributes ($ customAttributes , $ dataObjectType )
137
- {
138
- $ result = [];
139
- foreach ((array )$ customAttributes as $ customAttribute ) {
140
- $ result [] = $ this ->convertCustomAttribute ($ customAttribute , $ dataObjectType );
141
- }
142
- return $ result ;
143
- }
144
-
145
- /**
146
- * Convert custom_attribute object to use flat array structure
147
- *
148
- * @param \Magento\Framework\Api\AttributeInterface $customAttribute
149
- * @param string $dataObjectType
150
- * @return array
151
- */
152
- protected function convertCustomAttribute ($ customAttribute , $ dataObjectType )
153
- {
154
- $ data = [];
155
- $ data [AttributeValue::ATTRIBUTE_CODE ] = $ customAttribute ->getAttributeCode ();
156
- $ value = $ customAttribute ->getValue ();
157
- if (is_object ($ value )) {
158
- $ type = $ this ->attributeTypeResolver ->resolveObjectType (
159
- $ customAttribute ->getAttributeCode (),
160
- $ value ,
161
- $ dataObjectType
162
- );
163
- $ value = $ this ->buildOutputDataArray ($ value , $ type );
164
- } elseif (is_array ($ value )) {
165
- $ valueResult = [];
166
- foreach ($ value as $ singleValue ) {
167
- if (is_object ($ singleValue )) {
168
- $ type = $ this ->attributeTypeResolver ->resolveObjectType (
169
- $ customAttribute ->getAttributeCode (),
170
- $ singleValue ,
171
- $ dataObjectType
172
- );
173
- $ singleValue = $ this ->buildOutputDataArray ($ singleValue , $ type );
174
- }
175
- // Cannot cast to a type because the type is unknown
176
- $ valueResult [] = $ singleValue ;
177
- }
178
- $ value = $ valueResult ;
179
- }
180
- $ data [AttributeValue::VALUE ] = $ value ;
181
- return $ data ;
182
- }
183
116
}
0 commit comments