Skip to content

Commit ab0c00b

Browse files
author
Eric Bohanon
committed
MAGETWO-83872: Write metadata service
1 parent 2d25e46 commit ab0c00b

File tree

12 files changed

+189
-17
lines changed

12 files changed

+189
-17
lines changed

app/code/Magento/Catalog/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,9 @@
672672
</argument>
673673
</arguments>
674674
</type>
675-
<type name="Magento\Framework\Webapi\ServiceInputProcessor">
675+
<type name="Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
676676
<arguments>
677-
<argument name="dataInterfaceToEntityTypeMap" xsi:type="array">
677+
<argument name="serviceTypeToEntityTypeMap" xsi:type="array">
678678
<item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="const">Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE</item>
679679
<item name="Magento\Catalog\Api\Data\CategoryInterface" xsi:type="const">Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE</item>
680680
</argument>

app/code/Magento/Customer/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@
145145
</type>
146146
<preference for="Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface"
147147
type="Magento\Customer\CustomerData\JsLayoutDataProviderPool"/>
148-
<type name="Magento\Framework\Webapi\ServiceInputProcessor">
148+
<type name="Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
149149
<arguments>
150-
<argument name="dataInterfaceToEntityTypeMap" xsi:type="array">
150+
<argument name="serviceTypeToEntityTypeMap" xsi:type="array">
151151
<item name="Magento\Customer\Api\Data\CustomerInterface" xsi:type="const">Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER</item>
152152
<item name="Magento\Customer\Api\Data\AddressInterface" xsi:type="const">Magento\Customer\Api\AddressMetadataInterface::ENTITY_TYPE_ADDRESS</item>
153153
</argument>

app/code/Magento/Eav/Model/TypeLocator.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Eav\Model;
88

99
use Magento\Framework\Reflection\TypeProcessor;
10+
use Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface;
1011
use Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface;
1112

1213
/**
@@ -19,15 +20,22 @@ class TypeLocator implements CustomAttributeTypeLocatorInterface
1920
*/
2021
private $typeLocators;
2122

23+
/**
24+
* @var ServiceTypeListInterface
25+
*/
26+
private $serviceTypeList;
27+
2228
/**
2329
* Initialize TypeLocator
2430
*
2531
* @param \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface[] $typeLocators
2632
*/
2733
public function __construct(
34+
ServiceTypeListInterface $serviceTypeList,
2835
array $typeLocators = []
2936
) {
3037
$this->typeLocators = $typeLocators;
38+
$this->serviceTypeList = $serviceTypeList;
3139
}
3240

3341
/**
@@ -44,4 +52,12 @@ public function getType($attributeCode, $entityType)
4452

4553
return TypeProcessor::NORMALIZED_ANY_TYPE;
4654
}
55+
56+
/**
57+
* {@inheritDoc}
58+
*/
59+
public function getAllServiceDataInterfaces()
60+
{
61+
return $this->serviceTypeList->getDataTypes();
62+
}
4763
}

app/code/Magento/Eav/Model/TypeLocator/ComplexType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ public function getDataTypes()
9696
return array_unique($dataInterfaceArray);
9797
}
9898

99+
/**
100+
* {@inheritDoc}
101+
*/
102+
public function getAllServiceDataInterfaces()
103+
{
104+
return $this->getDataTypes();
105+
}
106+
99107
/**
100108
* @return array [['backend model' => 'simple or complex type'], ..]
101109
*/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Eav\Model\TypeLocator;
8+
9+
use Magento\Eav\Api\AttributeRepositoryInterface;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Framework\Reflection\TypeProcessor;
12+
use Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface;
13+
14+
/**
15+
* Class to find type based off of ServiceTypeToEntityTypeMap. This locator is introduced for backwards compatibility.
16+
* @deprecated
17+
*/
18+
class ServiceClassLocator implements CustomAttributeTypeLocatorInterface
19+
{
20+
/**
21+
* @var ServiceTypeToEntityTypeMap
22+
*/
23+
private $serviceTypeMap;
24+
25+
/**
26+
* @var AttributeRepositoryInterface
27+
*/
28+
private $attributeRepository;
29+
30+
/**
31+
* @var ComplexType
32+
*/
33+
private $complexTypeLocator;
34+
35+
/**
36+
* @var SimpleType
37+
*/
38+
private $simpleTypeLocator;
39+
40+
/**
41+
* @param ServiceTypeToEntityTypeMap $serviceTypeMap
42+
* @param AttributeRepositoryInterface $attributeRepository
43+
* @param ComplexType $complexTypeLocator
44+
* @param SimpleType $simpleTypeLocator
45+
*/
46+
public function __construct(
47+
ServiceTypeToEntityTypeMap $serviceTypeMap,
48+
AttributeRepositoryInterface $attributeRepository,
49+
ComplexType $complexTypeLocator,
50+
SimpleType $simpleTypeLocator
51+
) {
52+
$this->serviceTypeMap = $serviceTypeMap;
53+
$this->attributeRepository = $attributeRepository;
54+
$this->complexTypeLocator = $complexTypeLocator;
55+
$this->simpleTypeLocator = $simpleTypeLocator;
56+
}
57+
58+
/**
59+
* @inheritDoc
60+
*/
61+
public function getType($attributeCode, $entityType)
62+
{
63+
$map = $this->serviceTypeMap->getMap();
64+
if (!isset($map[$entityType])) {
65+
return TypeProcessor::NORMALIZED_ANY_TYPE;
66+
}
67+
68+
$type = $this->complexTypeLocator->getType($attributeCode, $map[$entityType]);
69+
if ($type === TypeProcessor::NORMALIZED_ANY_TYPE) {
70+
$type = $this->simpleTypeLocator->getType($attributeCode, $map[$entityType]);
71+
}
72+
73+
return $type;
74+
}
75+
76+
/**
77+
* @inheritDoc
78+
*/
79+
public function getAllServiceDataInterfaces()
80+
{
81+
$this->complexTypeLocator->getDataTypes();
82+
}
83+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Eav\Model\TypeLocator;
8+
9+
class ServiceTypeToEntityTypeMap
10+
{
11+
/**
12+
* @var string[]
13+
*/
14+
private $serviceTypeToEntityTypeMap;
15+
16+
/**
17+
* @param $serviceTypeToEntityTypeMap
18+
*/
19+
public function __construct($serviceTypeToEntityTypeMap)
20+
{
21+
$this->serviceTypeToEntityTypeMap = $serviceTypeToEntityTypeMap;
22+
}
23+
24+
/**
25+
* @return string[]
26+
*/
27+
public function getMap()
28+
{
29+
return $this->serviceTypeToEntityTypeMap;
30+
}
31+
}

app/code/Magento/Eav/Model/TypeLocator/SimpleType.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\Exception\NoSuchEntityException;
1010
use Magento\Framework\Reflection\TypeProcessor;
1111
use Magento\Eav\Api\AttributeRepositoryInterface;
12+
use Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface;
1213
use Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface;
1314

1415
/**
@@ -21,14 +22,22 @@ class SimpleType implements CustomAttributeTypeLocatorInterface
2122
*/
2223
private $attributeRepository;
2324

25+
/**
26+
* @var ServiceTypeListInterface
27+
*/
28+
private $serviceTypeList;
29+
2430
/**
2531
* Initialize dependencies.
2632
*
2733
* @param AttributeRepositoryInterface $attributeRepository
2834
*/
29-
public function __construct(AttributeRepositoryInterface $attributeRepository)
30-
{
35+
public function __construct(
36+
AttributeRepositoryInterface $attributeRepository,
37+
ServiceTypeListInterface $serviceTypeList
38+
) {
3139
$this->attributeRepository = $attributeRepository;
40+
$this->serviceTypeList = $serviceTypeList;
3241
}
3342

3443
/**
@@ -53,4 +62,12 @@ public function getType($attributeCode, $entityType)
5362
return isset($backendTypeMap[$backendType])
5463
? $backendTypeMap[$backendType] : TypeProcessor::NORMALIZED_ANY_TYPE;
5564
}
65+
66+
/**
67+
* {@inheritDoc}
68+
*/
69+
public function getAllServiceDataInterfaces()
70+
{
71+
$this->serviceTypeList->getDataTypes();
72+
}
5673
}

app/code/Magento/Eav/etc/di.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@
4646
<type name="Magento\Eav\Model\ResourceModel\Entity\Attribute">
4747
<plugin name="storeLabelCaching" type="Magento\Eav\Plugin\Model\ResourceModel\Entity\Attribute" />
4848
</type>
49-
<type name="Magento\Framework\Webapi\ServiceInputProcessor">
49+
<type name="Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
5050
<arguments>
51-
<argument name="dataInterfaceToEntityTypeMap" xsi:type="array" />
51+
<argument name="serviceTypeToEntityTypeMap" xsi:type="array" />
5252
</arguments>
5353
</type>
5454
<type name="Magento\Eav\Model\TypeLocator">
5555
<arguments>
5656
<argument name="typeLocators" xsi:type="array">
5757
<item name="simpleType" sortOrder="50" xsi:type="object">Magento\Eav\Model\TypeLocator\SimpleType</item>
5858
<item name="complexType" sortOrder="10" xsi:type="object">Magento\Eav\Model\TypeLocator\ComplexType</item>
59+
<item name="serviceClassType" sortOrder="0" xsi:type="object">Magento\Eav\Model\TypeLocator\ServiceClassLocator</item>
5960
</argument>
6061
</arguments>
6162
</type>

dev/tests/api-functional/_files/Magento/TestModuleMSC/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
</argument>
3939
</arguments>
4040
</virtualType>
41-
<type name="Magento\Framework\Webapi\ServiceInputProcessor">
41+
<type name="Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
4242
<arguments>
43-
<argument name="dataInterfaceToEntityTypeMap" xsi:type="array">
43+
<argument name="serviceTypeToEntityTypeMap" xsi:type="array">
4444
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="string">1</item>
4545
</argument>
4646
</arguments>

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@
280280
['callbackQueryHook', 'Magento\Core\Model\Resource\Setup'],
281281
['canCreateUser', 'Magento\User\Model\ResourceModel\User'],
282282
['canPrint', 'Magento\Checkout\Block\Onepage\Success'],
283+
[
284+
'getAllServiceDataInterfaces',
285+
'Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface',
286+
'Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface::getDataTypes()'
287+
],
283288
[
284289
'canTestHeaders',
285290
'Magento\TestFramework\Bootstrap',

0 commit comments

Comments
 (0)