Skip to content

Commit 7988331

Browse files
author
Oleksii Korshenko
authored
Merge pull request #442 from magento-okapis/MAGETWO-56207-multiple-rabbitmq-connections
Improvements: - MAGETWO-56305: Message Queue Configuration via remote services - MAGETWO-56288: Sorted Object List in di.xml
2 parents 0a6c5b2 + 9adc0a6 commit 7988331

File tree

7 files changed

+91
-1
lines changed

7 files changed

+91
-1
lines changed

lib/internal/Magento/Framework/Communication/Config/ReflectionGenerator.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class ReflectionGenerator
1515
{
1616
const DEFAULT_HANDLER = 'defaultHandler';
17+
1718
/**
1819
* @var MethodsMap
1920
*/
@@ -79,4 +80,23 @@ public function generateTopicConfigForServiceMethod($topicName, $serviceType, $s
7980
?: [self::DEFAULT_HANDLER => $methodMetadata[Config::SCHEMA_METHOD_HANDLER]]
8081
];
8182
}
83+
84+
/**
85+
* Generate topic name based on service type and method name.
86+
*
87+
* Perform the following conversion:
88+
* \Magento\Customer\Api\RepositoryInterface + getById => magento.customer.api.repositoryInterface.getById
89+
*
90+
* @param string $typeName
91+
* @param string $methodName
92+
* @return string
93+
*/
94+
public function generateTopicName($typeName, $methodName)
95+
{
96+
$parts = explode('\\', ltrim($typeName, '\\'));
97+
foreach ($parts as &$part) {
98+
$part = lcfirst($part);
99+
}
100+
return implode('.', $parts) . '.' . $methodName;
101+
}
82102
}

lib/internal/Magento/Framework/Data/Argument/Interpreter/ArrayType.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,40 @@ public function evaluate(array $data)
3939
throw new \InvalidArgumentException('Array items are expected.');
4040
}
4141
$result = [];
42+
$items = $this->sortItems($items);
4243
foreach ($items as $itemKey => $itemData) {
4344
$result[$itemKey] = $this->itemInterpreter->evaluate($itemData);
4445
}
4546
return $result;
4647
}
48+
49+
/**
50+
* Sort items by sort order attribute.
51+
*
52+
* @param array $items
53+
* @return array
54+
*/
55+
private function sortItems($items)
56+
{
57+
uasort(
58+
$items,
59+
function ($firstItem, $secondItem) {
60+
$firstValue = 0;
61+
$secondValue = 0;
62+
if (isset($firstItem['sortOrder'])) {
63+
$firstValue = intval($firstItem['sortOrder']);
64+
}
65+
66+
if (isset($secondItem['sortOrder'])) {
67+
$secondValue = intval($secondItem['sortOrder']);
68+
}
69+
70+
if ($firstValue == $secondValue) {
71+
return 0;
72+
}
73+
return $firstValue < $secondValue ? -1 : 1;
74+
}
75+
);
76+
return $items;
77+
}
4778
}

lib/internal/Magento/Framework/Data/Test/Unit/Argument/Interpreter/ArrayTypeTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ public function evaluateDataProvider()
8787
'key3' => '-value 3-',
8888
],
8989
],
90+
'sorted array items' => [
91+
[
92+
'item' => [
93+
'key1' => ['value' => 'value 1', 'sortOrder' => 50],
94+
'key2' => ['value' => 'value 2'],
95+
'key3' => ['value' => 'value 3', 'sortOrder' => 10],
96+
'key4' => ['value' => 'value 4'],
97+
],
98+
],
99+
[
100+
'key2' => '-value 2-',
101+
'key4' => '-value 4-',
102+
'key3' => '-value 3-',
103+
'key1' => '-value 1-',
104+
],
105+
],
90106
];
91107
}
92108
}

lib/internal/Magento/Framework/ObjectManager/ObjectManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function get($type)
7575

7676
/**
7777
* Configure di instance
78+
* Note: All arguments should be pre-processed (sort order, translations, etc) before passing to method configure.
7879
*
7980
* @param array $configuration
8081
* @return void

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Config/_files/invalidConfigXmlArray.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,21 @@
155155
"Element 'argument': Duplicate key-sequence ['same_param_name'] in key identity-constraint"
156156
. " 'argumentName'.\nLine: 6\n"
157157
],
158-
]
158+
],
159+
'sorted_object_list_with_invalid_sortOrder_attribute_value' => [
160+
'<?xml version="1.0"?>
161+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
162+
<type name="Some_Name">
163+
<arguments>
164+
<argument name="sorted_object_list" xsi:type="array">
165+
<item name="someObject" xsi:type="object" sortOrder="false">Some_Class_Name</item>
166+
</argument>
167+
</arguments>
168+
</type>
169+
</config>',
170+
[
171+
"Element 'item', attribute 'sortOrder': 'false' is not a valid value of the atomic type 'xs:integer'." .
172+
"\nLine: 6\n"
173+
],
174+
],
159175
];

lib/internal/Magento/Framework/ObjectManager/Test/Unit/Config/_files/valid_config.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
</item>
5858
</argument>
5959
<argument name="baseController" xsi:type="string">some_value</argument>
60+
<argument name="sortedList" xsi:type="array">
61+
<item name="itemTwo" xsi:type="object" sortOrder="20">Instance_test_name_two</item>
62+
<item name="itemOne" xsi:type="object">Instance_test_name_one</item>
63+
<item name="itemThree" xsi:type="object" sortOrder="30">Instance_test_name_three</item>
64+
</argument>
6065
</arguments>
6166
</type>
6267
</config>

lib/internal/Magento/Framework/ObjectManager/etc/config.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<xs:complexContent>
2121
<xs:extension base="object">
2222
<xs:attribute name="shared" use="optional" type="xs:boolean"/>
23+
<xs:attribute name="sortOrder" use="optional" type="xs:integer"/>
2324
</xs:extension>
2425
</xs:complexContent>
2526
</xs:complexType>

0 commit comments

Comments
 (0)