Skip to content

Commit 9973774

Browse files
author
Eric Bohanon
committed
MAGETWO-83872: Write metadata service
1 parent ac0afdb commit 9973774

File tree

8 files changed

+56
-41
lines changed

8 files changed

+56
-41
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@
672672
</argument>
673673
</arguments>
674674
</type>
675-
<type name="Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
675+
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">
676676
<arguments>
677677
<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>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
</type>
146146
<preference for="Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface"
147147
type="Magento\Customer\CustomerData\JsLayoutDataProviderPool"/>
148-
<type name="Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
148+
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">
149149
<arguments>
150150
<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>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Exception\NoSuchEntityException;
1111
use Magento\Framework\Reflection\TypeProcessor;
1212
use Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface;
13+
use Magento\Framework\Webapi\ServiceTypeToEntityTypeMap;
1314

1415
/**
1516
* Class to find type based off of ServiceTypeToEntityTypeMap. This locator is introduced for backwards compatibility.
@@ -60,8 +61,8 @@ public function __construct(
6061
*/
6162
public function getType($attributeCode, $entityType)
6263
{
63-
$map = $this->serviceTypeMap->getMap();
64-
if (!isset($map[$entityType])) {
64+
$entityCode = $this->serviceTypeMap->getEntityType($entityType);
65+
if (!$entityType) {
6566
return TypeProcessor::NORMALIZED_ANY_TYPE;
6667
}
6768

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
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\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
49+
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">
5050
<arguments>
5151
<argument name="serviceTypeToEntityTypeMap" xsi:type="array" />
5252
</arguments>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</argument>
3939
</arguments>
4040
</virtualType>
41-
<type name="Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap">
41+
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">
4242
<arguments>
4343
<argument name="serviceTypeToEntityTypeMap" xsi:type="array">
4444
<item name="Magento\TestModuleMSC\Api\AllSoapAndRestInterface" xsi:type="string">1</item>

lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
namespace Magento\Framework\Webapi;
99

10-
use Magento\Eav\Model\TypeLocator\ServiceTypeToEntityTypeMap;
10+
use Magento\Framework\Webapi\ServiceTypeToEntityTypeMap;
1111
use Magento\Framework\Api\AttributeValue;
1212
use Magento\Framework\Api\AttributeValueFactory;
1313
use Magento\Framework\Api\SimpleDataObjectConverter;
@@ -232,11 +232,11 @@ protected function convertCustomAttributeValue($customAttributesValueArray, $dat
232232

233233
list($customAttributeCode, $customAttributeValue) = $this->processCustomAttribute($customAttribute);
234234

235-
$map = $this->serviceTypeToEntityTypeMap->getMap();
236-
if (isset($map[$dataObjectClassName])) {
235+
$entityType = $this->serviceTypeToEntityTypeMap->getEntityType($dataObjectClassName);
236+
if ($entityType) {
237237
$type = $this->customAttributeTypeLocator->getType(
238238
$customAttributeCode,
239-
$map[$dataObjectClassName]
239+
$entityType
240240
);
241241
} else {
242242
$type = TypeProcessor::ANY_TYPE;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Webapi;
8+
9+
/**
10+
* Maps configured entity types relative to their service data contract
11+
*/
12+
class ServiceTypeToEntityTypeMap
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $serviceTypeToEntityTypeMap;
18+
19+
/**
20+
* @param $serviceTypeToEntityTypeMap
21+
*/
22+
public function __construct($serviceTypeToEntityTypeMap)
23+
{
24+
$this->serviceTypeToEntityTypeMap = $serviceTypeToEntityTypeMap;
25+
}
26+
27+
/**
28+
* Return entity type mapped to service type. Returns false if service type is not mapped.
29+
*
30+
* Example:
31+
* [
32+
* 'Magento\Catalog\Api\Data\ProductInterface' => 'catalog_product'
33+
* ]
34+
*
35+
* @return string|boolean
36+
*/
37+
public function getEntityType(string $serviceType)
38+
{
39+
if (isset($this->serviceTypeToEntityTypeMap[$serviceType])) {
40+
return $this->serviceTypeToEntityTypeMap;
41+
}
42+
43+
return false;
44+
}
45+
}

0 commit comments

Comments
 (0)