9
9
use Magento \Elasticsearch \Model \Adapter \FieldMapperInterface ;
10
10
use Magento \Elasticsearch \Model \Config ;
11
11
12
+ /**
13
+ * Field Mapper resolver.
14
+ */
12
15
class FieldMapperResolver implements FieldMapperInterface
13
16
{
14
17
/**
@@ -24,11 +27,11 @@ class FieldMapperResolver implements FieldMapperInterface
24
27
private $ fieldMappers ;
25
28
26
29
/**
27
- * Field Mapper instance
30
+ * Field Mapper instance per entity
28
31
*
29
- * @var FieldMapperInterface
32
+ * @var FieldMapperInterface[]
30
33
*/
31
- private $ fieldMapperEntity ;
34
+ private $ fieldMapperEntity = [] ;
32
35
33
36
/**
34
37
* @param ObjectManagerInterface $objectManager
@@ -43,7 +46,7 @@ public function __construct(
43
46
}
44
47
45
48
/**
46
- * { @inheritdoc}
49
+ * @inheritdoc
47
50
*/
48
51
public function getFieldName ($ attributeCode , $ context = [])
49
52
{
@@ -52,7 +55,7 @@ public function getFieldName($attributeCode, $context = [])
52
55
}
53
56
54
57
/**
55
- * { @inheritdoc}
58
+ * @inheritdoc
56
59
*/
57
60
public function getAllAttributesTypes ($ context = [])
58
61
{
@@ -69,8 +72,9 @@ public function getAllAttributesTypes($context = [])
69
72
*/
70
73
private function getEntity ($ entityType )
71
74
{
72
- if (empty ($ this ->fieldMapperEntity )) {
75
+ if (empty ($ this ->fieldMapperEntity [ $ entityType ] )) {
73
76
if (empty ($ entityType )) {
77
+ // phpcs:ignore Magento2.Exceptions.DirectThrow
74
78
throw new \Exception (
75
79
'No entity type given '
76
80
);
@@ -81,13 +85,13 @@ private function getEntity($entityType)
81
85
);
82
86
}
83
87
$ fieldMapperClass = $ this ->fieldMappers [$ entityType ];
84
- $ this ->fieldMapperEntity = $ this ->objectManager ->create ($ fieldMapperClass );
85
- if (!($ this ->fieldMapperEntity instanceof FieldMapperInterface)) {
88
+ $ this ->fieldMapperEntity [ $ entityType ] = $ this ->objectManager ->create ($ fieldMapperClass );
89
+ if (!($ this ->fieldMapperEntity [ $ entityType ] instanceof FieldMapperInterface)) {
86
90
throw new \InvalidArgumentException (
87
91
'Field mapper must implement \Magento\Elasticsearch\Model\Adapter\FieldMapperInterface '
88
92
);
89
93
}
90
94
}
91
- return $ this ->fieldMapperEntity ;
95
+ return $ this ->fieldMapperEntity [ $ entityType ] ;
92
96
}
93
97
}
0 commit comments