66namespace Magento \Framework \MessageQueue ;
77
88use InvalidArgumentException ;
9+ use Magento \Framework \App \ObjectManager ;
910use Magento \Framework \Exception \LocalizedException ;
1011use Magento \Framework \Phrase ;
1112use Magento \Framework \Communication \ConfigInterface as CommunicationConfig ;
@@ -20,6 +21,15 @@ class MessageValidator
2021 */
2122 private $ communicationConfig ;
2223
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+
2333 /**
2434 * Identify message data schema by topic.
2535 *
@@ -30,7 +40,7 @@ class MessageValidator
3040 */
3141 protected function getTopicSchema ($ topic , $ requestType )
3242 {
33- $ topicConfig = $ this ->getCommunicationConfig () ->getTopic ($ topic );
43+ $ topicConfig = $ this ->communicationConfig ->getTopic ($ topic );
3444 if ($ topicConfig === null ) {
3545 throw new LocalizedException (new Phrase ('Specified topic "%topic" is not declared. ' , ['topic ' => $ topic ]));
3646 }
@@ -117,12 +127,14 @@ protected function validatePrimitiveType($message, $messageType, $topic)
117127 {
118128 $ compareType = $ messageType ;
119129 $ 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 ' ) {
124131 $ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
132+ foreach ($ message as $ subMessage ) {
133+ $ this ->validatePrimitiveType ($ subMessage , $ compareType , $ topic );
134+ }
135+ return ;
125136 }
137+
126138 if ($ realType !== $ compareType ) {
127139 throw new InvalidArgumentException (
128140 new Phrase (
@@ -151,12 +163,14 @@ protected function validateClassType($message, $messageType, $topic)
151163 $ origMessage = $ message ;
152164 $ compareType = $ messageType ;
153165 $ 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 ' ) {
158167 $ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
168+ foreach ($ message as $ subMessage ) {
169+ $ this ->validateClassType ($ subMessage , $ compareType , $ topic );
170+ }
171+ return ;
159172 }
173+
160174 if (!($ message instanceof $ compareType )) {
161175 throw new InvalidArgumentException (
162176 new Phrase (
@@ -185,21 +199,4 @@ private function getRealType($message)
185199 $ type = $ type == 'double ' ? 'float ' : $ type ;
186200 return $ type == "integer " ? "int " : $ type ;
187201 }
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- }
205202}
0 commit comments