Skip to content

Commit 635ce44

Browse files
committed
Merge pull request #269 from magento-api/develop
[API] Sprint 47 – Part 2
2 parents cd7d717 + 4da4cd4 commit 635ce44

File tree

58 files changed

+1558
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1558
-444
lines changed

app/code/Magento/Backend/Block/Menu.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ protected function _addSubMenu($menuItem, $level, $limit, $id = null)
436436
* @param array $colBrakes
437437
* @return string HTML
438438
* @SuppressWarnings(PHPMD.NPathComplexity)
439+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
439440
*/
440441
public function renderNavigation($menu, $level = 0, $limit = 0, $colBrakes = [])
441442
{
@@ -454,21 +455,30 @@ public function renderNavigation($menu, $level = 0, $limit = 0, $colBrakes = [])
454455
}
455456

456457
$id = $this->getJsId($menuItem->getId());
457-
$output .= '<li ' . $this->getUiId(
458-
$menuItem->getId()
459-
) . ' class="item-' . $itemClass . ' ' . $this->_renderItemCssClass(
460-
$menuItem,
461-
$level
462-
) . ($level == 0 ? '" id="' . $id . '" aria-haspopup="true' : '')
463-
. '" role="menu-item">' . $this->_renderAnchor(
464-
$menuItem,
465-
$level
466-
) . $this->_addSubMenu(
467-
$menuItem,
468-
$level,
469-
$limit,
470-
$id
471-
) . '</li>';
458+
if (count($menu) > 1 || $level != 1) {
459+
$output .= '<li ' . $this->getUiId(
460+
$menuItem->getId()
461+
) . ' class="item-' . $itemClass . ' ' . $this->_renderItemCssClass(
462+
$menuItem,
463+
$level
464+
) . ($level == 0 ? '" id="' . $id . '" aria-haspopup="true' : '')
465+
. '" role="menu-item">' . $this->_renderAnchor(
466+
$menuItem,
467+
$level
468+
) . $this->_addSubMenu(
469+
$menuItem,
470+
$level,
471+
$limit,
472+
$id
473+
) . '</li>';
474+
} else {
475+
$output .= $this->_addSubMenu(
476+
$menuItem,
477+
$level,
478+
$limit,
479+
$id);
480+
}
481+
472482
$itemPosition++;
473483
}
474484

app/code/Magento/Bundle/etc/data_object.xml renamed to app/code/Magento/Bundle/etc/service_data_attributes.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
9-
<custom_attributes for="Magento\Catalog\Api\Data\ProductInterface">
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
9+
<extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
1010
<attribute code="bundle_product_options" type="Magento\Bundle\Api\Data\OptionInterface[]" />
11-
</custom_attributes>
11+
</extension_attributes>
1212
</config>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
9+
<extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
10+
<!--
11+
Once this is merged with the branch with the CatalogInventory integration, need to make sure the permission
12+
below is actually used.
13+
<attribute code="stock_item" type="Magento\CatalogInventory\Api\Data\StockItemInterface">
14+
<resources>
15+
<resource ref="Magento_CatalogInventory::cataloginventory"/>
16+
</resources>
17+
</attribute>
18+
-->
19+
</extension_attributes>
20+
</config>

app/code/Magento/GiftMessage/etc/data_object.xml renamed to app/code/Magento/GiftMessage/etc/service_data_attributes.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
9-
<custom_attributes for="Magento\Sales\Api\Data\OrderInterface">
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
9+
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
1010
<attribute code="gift_message" type="Magento\GiftMessage\Api\Data\MessageInterface" />
11-
</custom_attributes>
12-
<custom_attributes for="Magento\Sales\Api\Data\OrderItemInterface">
11+
</extension_attributes>
12+
<extension_attributes for="Magento\Sales\Api\Data\OrderItemInterface">
1313
<attribute code="gift_message" type="Magento\GiftMessage\Api\Data\MessageInterface" />
14-
</custom_attributes>
14+
</extension_attributes>
1515
</config>

app/code/Magento/GroupedProduct/etc/data_object.xml renamed to app/code/Magento/GroupedProduct/etc/service_data_attributes.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
9-
<custom_attributes for="Magento\Catalog\Api\Data\ProductLinkInterface">
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
9+
<extension_attributes for="Magento\Catalog\Api\Data\ProductLinkInterface">
1010
<attribute code="qty" type="float" />
11-
</custom_attributes>
11+
</extension_attributes>
1212
</config>

app/code/Magento/Sales/etc/data_object.xml renamed to app/code/Magento/Sales/etc/service_data_attributes.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
9-
<custom_attributes for="Magento\Sales\Api\Data\OrderInterface">
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/service_data_attributes.xsd">
9+
<extension_attributes for="Magento\Sales\Api\Data\OrderInterface">
1010
<attribute code="applied_taxes" type="Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface[]" />
1111
<attribute code="item_applied_taxes" type="Magento\Tax\Api\Data\OrderTaxDetailsItemInterface[]" />
1212
<attribute code="converting_from_quote" type="boolean" />
13-
</custom_attributes>
13+
</extension_attributes>
1414
</config>

app/code/Magento/Webapi/Controller/Rest/Router/Route.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function getRouteParts()
6969
$this->variables[$key] = substr($value, 1);
7070
$value = null;
7171
}
72-
$result[$key] = strtolower($value);
72+
$result[$key] = $value;
7373
}
7474
return $result;
7575
}
@@ -92,19 +92,12 @@ protected function isVariable($value)
9292
/**
9393
* Retrieve unified requested path
9494
*
95-
* Lowercase all path chunks, except variables names.
96-
* E.g. the path '/V1/Categories/:categoryId' will be converted to '/v1/categories/:categoryId'.
97-
*
9895
* @param string $path
9996
* @return array
10097
*/
10198
protected function getPathParts($path)
10299
{
103-
$result = explode('/', trim($path, '/'));
104-
array_walk($result, function (&$item) {
105-
$item = substr($item, 0, 1) === ":" ? $item : strtolower($item);
106-
});
107-
return $result;
100+
return explode('/', trim($path, '/'));
108101
}
109102

110103
/**

app/code/Magento/Webapi/Controller/Soap/Request/Handler.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Webapi\Controller\Soap\Request as SoapRequest;
1616
use Magento\Framework\Webapi\Exception as WebapiException;
1717
use Magento\Webapi\Model\Soap\Config as SoapConfig;
18+
use Magento\Framework\Reflection\MethodsMap;
1819

1920
/**
2021
* Handler of requests to SOAP server.
@@ -48,6 +49,9 @@ class Handler
4849
/** @var DataObjectProcessor */
4950
protected $_dataObjectProcessor;
5051

52+
/** @var MethodsMap */
53+
protected $methodsMapProcessor;
54+
5155
/**
5256
* Initialize dependencies.
5357
*
@@ -58,6 +62,7 @@ class Handler
5862
* @param SimpleDataObjectConverter $dataObjectConverter
5963
* @param ServiceInputProcessor $serviceInputProcessor
6064
* @param DataObjectProcessor $dataObjectProcessor
65+
* @param MethodsMap $methodsMapProcessor
6166
*/
6267
public function __construct(
6368
SoapRequest $request,
@@ -66,7 +71,8 @@ public function __construct(
6671
AuthorizationInterface $authorization,
6772
SimpleDataObjectConverter $dataObjectConverter,
6873
ServiceInputProcessor $serviceInputProcessor,
69-
DataObjectProcessor $dataObjectProcessor
74+
DataObjectProcessor $dataObjectProcessor,
75+
MethodsMap $methodsMapProcessor
7076
) {
7177
$this->_request = $request;
7278
$this->_objectManager = $objectManager;
@@ -75,6 +81,7 @@ public function __construct(
7581
$this->_dataObjectConverter = $dataObjectConverter;
7682
$this->serviceInputProcessor = $serviceInputProcessor;
7783
$this->_dataObjectProcessor = $dataObjectProcessor;
84+
$this->methodsMapProcessor = $methodsMapProcessor;
7885
}
7986

8087
/**
@@ -149,7 +156,7 @@ protected function _prepareRequestData($serviceClass, $serviceMethod, $arguments
149156
protected function _prepareResponseData($data, $serviceClassName, $serviceMethodName)
150157
{
151158
/** @var string $dataType */
152-
$dataType = $this->_dataObjectProcessor->getMethodReturnType($serviceClassName, $serviceMethodName);
159+
$dataType = $this->methodsMapProcessor->getMethodReturnType($serviceClassName, $serviceMethodName);
153160
$result = null;
154161
if (is_object($data)) {
155162
$result = $this->_dataObjectConverter

app/code/Magento/Webapi/Model/Rest/Config.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function _createRoute($routeData)
6767
/** @var $route \Magento\Webapi\Controller\Rest\Router\Route */
6868
$route = $this->_routeFactory->createRoute(
6969
'Magento\Webapi\Controller\Rest\Router\Route',
70-
$this->_formatRoutePath($routeData[self::KEY_ROUTE_PATH])
70+
$routeData[self::KEY_ROUTE_PATH]
7171
);
7272

7373
$route->setServiceClass($routeData[self::KEY_CLASS])
@@ -78,22 +78,6 @@ protected function _createRoute($routeData)
7878
return $route;
7979
}
8080

81-
/**
82-
* Lowercase all parts of the given route path except for the path parameters.
83-
*
84-
* @param string $routePath The route path (e.g. '/V1/Categories/:categoryId')
85-
* @return string The modified route path (e.g. '/v1/categories/:categoryId')
86-
*/
87-
protected function _formatRoutePath($routePath)
88-
{
89-
$routePathParts = explode('/', $routePath);
90-
$pathParts = [];
91-
foreach ($routePathParts as $pathPart) {
92-
$pathParts[] = substr($pathPart, 0, 1) === ":" ? $pathPart : strtolower($pathPart);
93-
}
94-
return implode('/', $pathParts);
95-
}
96-
9781
/**
9882
* Get service base URL
9983
*

app/code/Magento/Webapi/Test/Unit/Controller/Rest/Router/RouteTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ public function dataProviderRoutes()
9595
['/V1/one/two/:threeValue/four/:fiveValue', '/V1/one/two/3/four/5', ['threeValue' => 3, 'fiveValue' => 5]],
9696

9797
['/v1/One', '/v1/One', []],
98-
['/v1/oNe', '/V1/one', []],
99-
['/v1/onE', '/V1/oNe', []],
10098

101-
['/v1/One/:twoValue', '/V1/one/2', ['twoValue' => 2]],
10299
['/v1/oNe/:TwoValue', '/v1/oNe/2', ['TwoValue' => 2]],
103100
['/v1/onE/:twovalue', '/v1/onE/2', ['twovalue' => 2]],
104101

@@ -108,6 +105,9 @@ public function dataProviderRoutes()
108105
['/V1/one-one/:two_value', '/V1/one-one/2', ['two_value' => 2]],
109106

110107
// Error
108+
['/v1/oNe', '/V1/one', false],
109+
['/v1/onE', '/V1/oNe', false],
110+
['/v1/One/:twoValue', '/V1/one/2', false],
111111
['/V1/one', '/V1/two', false],
112112
['/V1/one/:twoValue', '/V1/one', false],
113113
['/V1/one/two', '/V1/one', false],

app/code/Magento/Webapi/Test/Unit/Controller/Soap/Request/HandlerTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class HandlerTest extends \PHPUnit_Framework_TestCase
4040
/** @var \Magento\Framework\Reflection\DataObjectProcessor|\PHPUnit_Framework_MockObject_MockObject */
4141
protected $_dataObjectProcessorMock;
4242

43+
/** @var \Magento\Framework\Reflection\MethodsMap|\PHPUnit_Framework_MockObject_MockObject */
44+
protected $_methodsMapProcessorMock;
45+
4346
/** @var array */
4447
protected $_arguments;
4548

@@ -67,7 +70,13 @@ protected function setUp()
6770
);
6871
$this->_dataObjectProcessorMock = $this->getMock(
6972
'Magento\Framework\Reflection\DataObjectProcessor',
70-
['getMethodReturnType'],
73+
[],
74+
[],
75+
'',
76+
false);
77+
$this->_methodsMapProcessorMock = $this->getMock(
78+
'Magento\Framework\Reflection\MethodsMap',
79+
[],
7180
[],
7281
'',
7382
false);
@@ -80,7 +89,8 @@ protected function setUp()
8089
$this->_authorizationMock,
8190
$this->_dataObjectConverter,
8291
$this->_serviceInputProcessorMock,
83-
$this->_dataObjectProcessorMock
92+
$this->_dataObjectProcessorMock,
93+
$this->_methodsMapProcessorMock
8494
);
8595
parent::setUp();
8696
}
@@ -128,10 +138,6 @@ public function testCall()
128138
->method('process')
129139
->will($this->returnArgument(2));
130140

131-
$this->_dataObjectProcessorMock->expects($this->any())->method('getMethodReturnType')
132-
->with($className, $methodName)
133-
->will($this->returnValue('string'));
134-
135141
/** Execute SUT. */
136142
$this->assertEquals(
137143
['result' => $serviceResponse],

app/code/Magento/Webapi/Test/Unit/Model/DataObjectProcessorTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ class DataObjectProcessorTest extends \PHPUnit_Framework_TestCase
2323
protected function setup()
2424
{
2525
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
26-
$this->dataObjectProcessor = $objectManager->getObject('Magento\Framework\Reflection\DataObjectProcessor');
26+
$methodsMapProcessor = $objectManager->getObject(
27+
'Magento\Framework\Reflection\MethodsMap',
28+
[
29+
'fieldNamer' => $objectManager->getObject('Magento\Framework\Reflection\FieldNamer'),
30+
'typeProcessor' => $objectManager->getObject('Magento\Framework\Reflection\TypeProcessor'),
31+
]
32+
);
33+
$this->dataObjectProcessor = $objectManager->getObject(
34+
'Magento\Framework\Reflection\DataObjectProcessor',
35+
[
36+
'methodsMapProcessor' => $methodsMapProcessor,
37+
'typeCaster' => $objectManager->getObject('Magento\Framework\Reflection\TypeCaster'),
38+
'fieldNamer' => $objectManager->getObject('Magento\Framework\Reflection\FieldNamer'),
39+
]
40+
);
2741
parent::setUp();
2842
}
2943

app/code/Magento/Webapi/Test/Unit/Model/Files/TestDataInterface.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@
88

99
interface TestDataInterface
1010
{
11+
/**
12+
* @return string
13+
*/
1114
public function getId();
1215

16+
/**
17+
* @return string
18+
*/
1319
public function getAddress();
1420

21+
/**
22+
* @return string
23+
*/
1524
public function isDefaultShipping();
1625

26+
/**
27+
* @return string
28+
*/
1729
public function isRequiredBilling();
1830
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
<type name="Magento\Framework\Xml\Parser" shared="false" />
2323
<type name="Magento\Framework\Code\Scanner\DirectoryScanner" shared="false" />
2424
<type name="Magento\Server\Reflection" shared="false" />
25-
<type name="Magento\Framework\Reflection\DataObjectProcessor">
25+
<type name="Magento\Framework\Reflection\MethodsMap">
2626
<arguments>
2727
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Webapi</argument>
2828
</arguments>
2929
</type>
30+
<type name="Magento\Framework\Reflection\DataObjectProcessor">
31+
<arguments>
32+
<argument name="extensionAttributesProcessor" xsi:type="object">Magento\Framework\Reflection\ExtensionAttributesProcessor\Proxy</argument>
33+
<argument name="customAttributesProcessor" xsi:type="object">Magento\Framework\Reflection\CustomAttributesProcessor\Proxy</argument>
34+
</arguments>
35+
</type>
3036
<type name="Magento\Integration\Model\ConfigBasedIntegrationManager">
3137
<plugin name="webapiSetup" type="Magento\Webapi\Model\Plugin\Manager" />
3238
</type>

0 commit comments

Comments
 (0)