8
8
use Magento \Framework \App \CacheInterface ;
9
9
use Magento \Framework \App \Cache \StateInterface ;
10
10
use Magento \Customer \Api \Data \AttributeMetadataInterface ;
11
- use Magento \Customer \Api \Data \AttributeMetadataInterfaceFactory ;
12
- use Magento \Customer \Api \Data \OptionInterface ;
13
- use Magento \Customer \Api \Data \OptionInterfaceFactory ;
14
- use Magento \Customer \Api \Data \ValidationRuleInterfaceFactory ;
15
11
use Magento \Framework \Serialize \SerializerInterface ;
16
12
use Magento \Eav \Model \Cache \Type ;
17
13
use Magento \Eav \Model \Entity \Attribute ;
@@ -48,20 +44,10 @@ class AttributeMetadataCache
48
44
private $ isAttributeCacheEnabled ;
49
45
50
46
/**
51
- * @var AttributeMetadataInterfaceFactory
47
+ * @var AttributeMetadataFactory
52
48
*/
53
49
private $ attributeMetadataFactory ;
54
50
55
- /**
56
- * @var OptionInterfaceFactory
57
- */
58
- private $ optionFactory ;
59
-
60
- /**
61
- * @var ValidationRuleInterfaceFactory
62
- */
63
- private $ validationRuleFactory ;
64
-
65
51
/**
66
52
* @var SerializerInterface
67
53
*/
@@ -72,24 +58,18 @@ class AttributeMetadataCache
72
58
*
73
59
* @param CacheInterface $cache
74
60
* @param StateInterface $state
75
- * @param AttributeMetadataInterfaceFactory $attributeMetadataFactory
76
- * @param OptionInterfaceFactory $optionFactory
77
- * @param ValidationRuleInterfaceFactory $validationRuleFactory
61
+ * @param AttributeMetadataFactory $attributeMetadataFactory
78
62
* @param SerializerInterface $serializer
79
63
*/
80
64
public function __construct (
81
65
CacheInterface $ cache ,
82
66
StateInterface $ state ,
83
- AttributeMetadataInterfaceFactory $ attributeMetadataFactory ,
84
- OptionInterfaceFactory $ optionFactory ,
85
- ValidationRuleInterfaceFactory $ validationRuleFactory ,
67
+ AttributeMetadataFactory $ attributeMetadataFactory ,
86
68
SerializerInterface $ serializer
87
69
) {
88
70
$ this ->cache = $ cache ;
89
71
$ this ->state = $ state ;
90
72
$ this ->attributeMetadataFactory = $ attributeMetadataFactory ;
91
- $ this ->optionFactory = $ optionFactory ;
92
- $ this ->validationRuleFactory = $ validationRuleFactory ;
93
73
$ this ->serializer = $ serializer ;
94
74
}
95
75
@@ -112,7 +92,7 @@ public function load($entityType, $suffix = '')
112
92
$ attributesData = $ this ->serializer ->unserialize ($ serializedData );
113
93
$ attributes = [];
114
94
foreach ($ attributesData as $ key => $ attributeData ) {
115
- $ attributes [$ key ] = $ this ->createMetadataAttribute ($ attributeData );
95
+ $ attributes [$ key ] = $ this ->attributeMetadataFactory -> create ($ attributeData );
116
96
}
117
97
$ this ->attributes [$ entityType . $ suffix ] = $ attributes ;
118
98
return $ attributes ;
@@ -181,44 +161,4 @@ private function isEnabled()
181
161
}
182
162
return $ this ->isAttributeCacheEnabled ;
183
163
}
184
-
185
- /**
186
- * Create and populate with data AttributeMetadataInterface
187
- *
188
- * @param array $data
189
- * @return AttributeMetadataInterface
190
- */
191
- private function createMetadataAttribute ($ data )
192
- {
193
- if (isset ($ data [AttributeMetadataInterface::OPTIONS ])) {
194
- $ data [AttributeMetadataInterface::OPTIONS ] = $ this ->createOptions (
195
- $ data [AttributeMetadataInterface::OPTIONS ]
196
- );
197
- }
198
- if (isset ($ data [AttributeMetadataInterface::VALIDATION_RULES ])) {
199
- $ validationRules = [];
200
- foreach ($ data [AttributeMetadataInterface::VALIDATION_RULES ] as $ validationRuleData ) {
201
- $ validationRules [] = $ this ->validationRuleFactory ->create (['data ' => $ validationRuleData ]);
202
- }
203
- $ data [AttributeMetadataInterface::VALIDATION_RULES ] = $ validationRules ;
204
- }
205
- return $ this ->attributeMetadataFactory ->create (['data ' => $ data ]);
206
- }
207
-
208
- /**
209
- * Create and populate with data OptionInterface
210
- *
211
- * @param array $data
212
- * @return OptionInterface[]
213
- */
214
- private function createOptions ($ data )
215
- {
216
- foreach ($ data as $ key => $ optionData ) {
217
- if (isset ($ optionData [OptionInterface::OPTIONS ])) {
218
- $ optionData [OptionInterface::OPTIONS ] = $ this ->createOptions ($ optionData [OptionInterface::OPTIONS ]);
219
- }
220
- $ data [$ key ] = $ this ->optionFactory ->create (['data ' => $ optionData ]);
221
- }
222
- return $ data ;
223
- }
224
164
}
0 commit comments