@@ -78,18 +78,18 @@ public function getServices()
78
78
public function getTopicName ($ routeUrl , $ httpMethod )
79
79
{
80
80
$ services = $ this ->getServices ();
81
- $ topicName = $ this ->generateTopicNameByRouteData (
81
+ $ lookupKey = $ this ->generateLookupKeyByRouteData (
82
82
$ routeUrl ,
83
83
$ httpMethod
84
84
);
85
85
86
- if (array_key_exists ($ topicName , $ services ) === false ) {
86
+ if (array_key_exists ($ lookupKey , $ services ) === false ) {
87
87
throw new LocalizedException (
88
- __ ('WebapiAsync config for "%topicName " does not exist. ' , ['topicName ' => $ topicName ])
88
+ __ ('WebapiAsync config for "%lookupKey " does not exist. ' , ['lookupKey ' => $ lookupKey ])
89
89
);
90
90
}
91
91
92
- return $ services [$ topicName ][self ::SERVICE_PARAM_KEY_TOPIC ];
92
+ return $ services [$ lookupKey ][self ::SERVICE_PARAM_KEY_TOPIC ];
93
93
}
94
94
95
95
/**
@@ -105,11 +105,18 @@ private function generateTopicsDataFromWebapiConfig()
105
105
$ serviceInterface = $ httpMethodData [Converter::KEY_SERVICE ][Converter::KEY_SERVICE_CLASS ];
106
106
$ serviceMethod = $ httpMethodData [Converter::KEY_SERVICE ][Converter::KEY_SERVICE_METHOD ];
107
107
108
- $ topicName = $ this ->generateTopicNameByRouteData (
108
+ $ lookupKey = $ this ->generateLookupKeyByRouteData (
109
109
$ routeUrl ,
110
110
$ httpMethod
111
111
);
112
- $ services [$ topicName ] = [
112
+
113
+ $ topicName = $ this ->generateTopicNameFromService (
114
+ $ serviceInterface ,
115
+ $ serviceMethod ,
116
+ $ httpMethod
117
+ );
118
+
119
+ $ services [$ lookupKey ] = [
113
120
self ::SERVICE_PARAM_KEY_INTERFACE => $ serviceInterface ,
114
121
self ::SERVICE_PARAM_KEY_METHOD => $ serviceMethod ,
115
122
self ::SERVICE_PARAM_KEY_TOPIC => $ topicName ,
@@ -122,7 +129,7 @@ private function generateTopicsDataFromWebapiConfig()
122
129
}
123
130
124
131
/**
125
- * Generate topic name based on service type and method name.
132
+ * Generate lookup key name based on route and method
126
133
*
127
134
* Perform the following conversion:
128
135
* self::TOPIC_PREFIX + /V1/products + POST => async.V1.products.POST
@@ -131,19 +138,39 @@ private function generateTopicsDataFromWebapiConfig()
131
138
* @param string $httpMethod
132
139
* @return string
133
140
*/
134
- private function generateTopicNameByRouteData ($ routeUrl , $ httpMethod )
141
+ private function generateLookupKeyByRouteData ($ routeUrl , $ httpMethod )
135
142
{
136
- return self ::TOPIC_PREFIX . $ this ->generateTopicName ($ routeUrl , $ httpMethod , '/ ' , false );
143
+ return self ::TOPIC_PREFIX . $ this ->generateKey ($ routeUrl , $ httpMethod , '/ ' , false );
137
144
}
138
145
139
146
/**
147
+ * Generate topic name based on service type and method name.
148
+ *
149
+ * Perform the following conversion:
150
+ * self::TOPIC_PREFIX + Magento\Catalog\Api\ProductRepositoryInterface + save + POST
151
+ * => async.magento.catalog.api.productrepositoryinterface.save.POST
152
+ *
153
+ * @param string $serviceMethod
154
+ * @param string $serviceInterface
155
+ * @param string $httpMethod
156
+ * @return string
157
+ */
158
+ private function generateTopicNameFromService ($ serviceInterface , $ serviceMethod , $ httpMethod )
159
+ {
160
+ $ typeName = strtolower (sprintf ('%s.%s ' , $ serviceInterface , $ serviceMethod ));
161
+ return self ::TOPIC_PREFIX . $ this ->generateKey ($ typeName , $ httpMethod , '\\' , false );
162
+ }
163
+
164
+ /**
165
+ * Join and simplify input type and method into a string that can be used as an array key
166
+ *
140
167
* @param string $typeName
141
168
* @param string $methodName
142
169
* @param string $delimiter
143
170
* @param bool $lcfirst
144
171
* @return string
145
172
*/
146
- private function generateTopicName ($ typeName , $ methodName , $ delimiter = '\\' , $ lcfirst = true )
173
+ private function generateKey ($ typeName , $ methodName , $ delimiter = '\\' , $ lcfirst = true )
147
174
{
148
175
$ parts = explode ($ delimiter , ltrim ($ typeName , $ delimiter ));
149
176
foreach ($ parts as &$ part ) {
0 commit comments