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,9 +127,7 @@ 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 ' ) {
130+ if ($ realType == 'array ' ) {
123131 $ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
124132 foreach ($ message as $ subMessage ) {
125133 $ this ->validatePrimitiveType ($ subMessage , $ compareType , $ topic );
@@ -155,12 +163,14 @@ protected function validateClassType($message, $messageType, $topic)
155163 $ origMessage = $ message ;
156164 $ compareType = $ messageType ;
157165 $ 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 ' ) {
162167 $ compareType = preg_replace ('/\[\]/ ' , '' , $ messageType );
168+ foreach ($ message as $ subMessage ) {
169+ $ this ->validateClassType ($ subMessage , $ compareType , $ topic );
170+ }
171+ return ;
163172 }
173+
164174 if (!($ message instanceof $ compareType )) {
165175 throw new InvalidArgumentException (
166176 new Phrase (
@@ -189,21 +199,4 @@ private function getRealType($message)
189199 $ type = $ type == 'double ' ? 'float ' : $ type ;
190200 return $ type == "integer " ? "int " : $ type ;
191201 }
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- }
209202}
0 commit comments