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,12 +127,14 @@ 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 ' && isset ($ message [0 ])) {
123
- $ realType = $ this ->getRealType ($ message [0 ]);
130
+ if ($ realType == 'array ' ) {
124
131
$ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
132
+ foreach ($ message as $ subMessage ) {
133
+ $ this ->validatePrimitiveType ($ subMessage , $ compareType , $ topic );
134
+ }
135
+ return ;
125
136
}
137
+
126
138
if ($ realType !== $ compareType ) {
127
139
throw new InvalidArgumentException (
128
140
new Phrase (
@@ -151,12 +163,14 @@ protected function validateClassType($message, $messageType, $topic)
151
163
$ origMessage = $ message ;
152
164
$ compareType = $ messageType ;
153
165
$ realType = $ this ->getRealType ($ message );
154
- if ($ realType == 'array ' && count ($ message ) == 0 ) {
155
- return ;
156
- } elseif ($ realType == 'array ' && isset ($ message [0 ])) {
157
- $ message = $ message [0 ];
166
+ if ($ realType == 'array ' ) {
158
167
$ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
168
+ foreach ($ message as $ subMessage ) {
169
+ $ this ->validateClassType ($ subMessage , $ compareType , $ topic );
170
+ }
171
+ return ;
159
172
}
173
+
160
174
if (!($ message instanceof $ compareType )) {
161
175
throw new InvalidArgumentException (
162
176
new Phrase (
@@ -185,21 +199,4 @@ private function getRealType($message)
185
199
$ type = $ type == 'double ' ? 'float ' : $ type ;
186
200
return $ type == "integer " ? "int " : $ type ;
187
201
}
188
-
189
- /**
190
- * Get communication config.
191
- *
192
- * @return CommunicationConfig
193
- *
194
- * @deprecated 103.0.0
195
- */
196
- private function getCommunicationConfig ()
197
- {
198
- if ($ this ->communicationConfig === null ) {
199
- $ this ->communicationConfig = \Magento \Framework \App \ObjectManager::getInstance ()->get (
200
- CommunicationConfig::class
201
- );
202
- }
203
- return $ this ->communicationConfig ;
204
- }
205
202
}
0 commit comments