6
6
namespace Magento \Framework \MessageQueue ;
7
7
8
8
use InvalidArgumentException ;
9
+ use Magento \Framework \App \ObjectManager ;
9
10
use Magento \Framework \Exception \LocalizedException ;
10
11
use Magento \Framework \Phrase ;
11
12
use Magento \Framework \Communication \ConfigInterface as CommunicationConfig ;
@@ -20,6 +21,15 @@ class MessageValidator
20
21
*/
21
22
private $ communicationConfig ;
22
23
24
+ /**
25
+ * @param CommunicationConfig|null $communicationConfig
26
+ */
27
+ public function __construct (CommunicationConfig $ communicationConfig = null )
28
+ {
29
+ $ this ->communicationConfig = $ communicationConfig
30
+ ?? ObjectManager::getInstance ()->get (CommunicationConfig::class);
31
+ }
32
+
23
33
/**
24
34
* Identify message data schema by topic.
25
35
*
@@ -30,7 +40,7 @@ class MessageValidator
30
40
*/
31
41
protected function getTopicSchema ($ topic , $ requestType )
32
42
{
33
- $ topicConfig = $ this ->getCommunicationConfig () ->getTopic ($ topic );
43
+ $ topicConfig = $ this ->communicationConfig ->getTopic ($ topic );
34
44
if ($ topicConfig === null ) {
35
45
throw new LocalizedException (new Phrase ('Specified topic "%topic" is not declared. ' , ['topic ' => $ topic ]));
36
46
}
@@ -117,9 +127,7 @@ protected function validatePrimitiveType($message, $messageType, $topic)
117
127
{
118
128
$ compareType = $ messageType ;
119
129
$ realType = $ this ->getRealType ($ message );
120
- if ($ realType == 'array ' && count ($ message ) == 0 ) {
121
- return ;
122
- } elseif ($ realType == 'array ' ) {
130
+ if ($ realType == 'array ' ) {
123
131
$ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
124
132
foreach ($ message as $ subMessage ) {
125
133
$ this ->validatePrimitiveType ($ subMessage , $ compareType , $ topic );
@@ -155,12 +163,14 @@ protected function validateClassType($message, $messageType, $topic)
155
163
$ origMessage = $ message ;
156
164
$ compareType = $ messageType ;
157
165
$ realType = $ this ->getRealType ($ message );
158
- if ($ realType == 'array ' && count ($ message ) == 0 ) {
159
- return ;
160
- } elseif ($ realType == 'array ' && isset ($ message [0 ])) {
161
- $ message = $ message [0 ];
166
+ if ($ realType == 'array ' ) {
162
167
$ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
168
+ foreach ($ message as $ subMessage ) {
169
+ $ this ->validateClassType ($ subMessage , $ compareType , $ topic );
170
+ }
171
+ return ;
163
172
}
173
+
164
174
if (!($ message instanceof $ compareType )) {
165
175
throw new InvalidArgumentException (
166
176
new Phrase (
@@ -189,21 +199,4 @@ private function getRealType($message)
189
199
$ type = $ type == 'double ' ? 'float ' : $ type ;
190
200
return $ type == "integer " ? "int " : $ type ;
191
201
}
192
-
193
- /**
194
- * Get communication config.
195
- *
196
- * @return CommunicationConfig
197
- *
198
- * @deprecated 103.0.0
199
- */
200
- private function getCommunicationConfig ()
201
- {
202
- if ($ this ->communicationConfig === null ) {
203
- $ this ->communicationConfig = \Magento \Framework \App \ObjectManager::getInstance ()->get (
204
- CommunicationConfig::class
205
- );
206
- }
207
- return $ this ->communicationConfig ;
208
- }
209
202
}
0 commit comments