10
10
use Magento \Customer \Api \Data \OptionInterface ;
11
11
use Magento \Customer \Api \Data \OptionInterfaceFactory ;
12
12
use Magento \Customer \Api \Data \ValidationRuleInterfaceFactory ;
13
+ use Magento \Framework \Reflection \DataObjectProcessor ;
13
14
14
15
/**
15
- * Factory for AttributeMetadataInterface
16
+ * Hydrator for AttributeMetadataInterface
16
17
*/
17
- class AttributeMetadataFactory
18
+ class AttributeMetadataHydrator
18
19
{
19
20
/**
20
21
* @var AttributeMetadataInterfaceFactory
@@ -31,30 +32,38 @@ class AttributeMetadataFactory
31
32
*/
32
33
private $ validationRuleFactory ;
33
34
35
+ /**
36
+ * @var DataObjectProcessor
37
+ */
38
+ private $ dataObjectProcessor ;
39
+
34
40
/**
35
41
* Constructor
36
42
*
37
43
* @param AttributeMetadataInterfaceFactory $attributeMetadataFactory
38
44
* @param OptionInterfaceFactory $optionFactory
39
45
* @param ValidationRuleInterfaceFactory $validationRuleFactory
46
+ * @param DataObjectProcessor $dataObjectProcessor
40
47
*/
41
48
public function __construct (
42
49
AttributeMetadataInterfaceFactory $ attributeMetadataFactory ,
43
50
OptionInterfaceFactory $ optionFactory ,
44
- ValidationRuleInterfaceFactory $ validationRuleFactory
51
+ ValidationRuleInterfaceFactory $ validationRuleFactory ,
52
+ DataObjectProcessor $ dataObjectProcessor
45
53
) {
46
54
$ this ->attributeMetadataFactory = $ attributeMetadataFactory ;
47
55
$ this ->optionFactory = $ optionFactory ;
48
56
$ this ->validationRuleFactory = $ validationRuleFactory ;
57
+ $ this ->dataObjectProcessor = $ dataObjectProcessor ;
49
58
}
50
59
51
60
/**
52
- * Create and populate with data AttributeMetadataInterface
61
+ * Convert array to AttributeMetadataInterface
53
62
*
54
63
* @param array $data
55
64
* @return AttributeMetadataInterface
56
65
*/
57
- public function create ( $ data )
66
+ public function hydrate ( array $ data )
58
67
{
59
68
if (isset ($ data [AttributeMetadataInterface::OPTIONS ])) {
60
69
$ data [AttributeMetadataInterface::OPTIONS ] = $ this ->createOptions (
@@ -72,12 +81,12 @@ public function create($data)
72
81
}
73
82
74
83
/**
75
- * Create and populate with data OptionInterface
84
+ * Convert AttributeMetadataInterface to array
76
85
*
77
86
* @param array $data
78
87
* @return OptionInterface[]
79
88
*/
80
- private function createOptions ($ data )
89
+ private function createOptions (array $ data )
81
90
{
82
91
foreach ($ data as $ key => $ optionData ) {
83
92
if (isset ($ optionData [OptionInterface::OPTIONS ])) {
@@ -87,4 +96,16 @@ private function createOptions($data)
87
96
}
88
97
return $ data ;
89
98
}
99
+
100
+ /**
101
+ * @param $attributeMetadata
102
+ * @return array
103
+ */
104
+ public function extract ($ attributeMetadata )
105
+ {
106
+ return $ this ->dataObjectProcessor ->buildOutputDataArray (
107
+ $ attributeMetadata ,
108
+ AttributeMetadataInterface::class
109
+ );
110
+ }
90
111
}
0 commit comments