Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Validator.php
Go to the documentation of this file.
1 <?php
7 
12 
16 class Validator extends ConfigValidator
17 {
21  private $methodsMap;
22 
29  public function __construct(
30  TypeProcessor $typeProcessor,
31  MethodsMap $methodsMap
32  ) {
33  $this->methodsMap = $methodsMap;
34  parent::__construct($typeProcessor, $methodsMap);
35  }
36 
44  public function validate($configData, array $xmlConfigData = [])
45  {
46  if (isset($configData[QueueConfig::TOPICS])) {
47  foreach ($configData[QueueConfig::TOPICS] as $topicName => $configDataItem) {
48  $schemaType = $configDataItem[QueueConfig::TOPIC_SCHEMA][QueueConfig::TOPIC_SCHEMA_VALUE];
49  $responseSchemaType =
50  $configDataItem[QueueConfig::TOPIC_RESPONSE_SCHEMA][QueueConfig::TOPIC_SCHEMA_VALUE];
51  $publisherName = $configDataItem[QueueConfig::TOPIC_PUBLISHER];
52  $this->validateSchemaType($schemaType, $topicName);
53  $this->validateResponseSchemaType($responseSchemaType, $topicName);
55  $this->getAvailablePublishers($configData, $xmlConfigData),
56  $publisherName,
57  $topicName
58  );
59  }
60  }
61  if (isset($configData[QueueConfig::CONSUMERS])) {
62  foreach ($configData[QueueConfig::CONSUMERS] as $consumerName => $configDataItem) {
63  $handlers = isset($configDataItem[QueueConfig::CONSUMER_HANDLERS])
64  ? $configDataItem[QueueConfig::CONSUMER_HANDLERS] : [];
65  foreach ($handlers as $handler) {
66  $this->validateHandlerType(
67  $handler[QueueConfig::CONSUMER_CLASS],
68  $handler[QueueConfig::CONSUMER_METHOD],
69  $consumerName
70  );
71  }
72  }
73  }
74  if (isset($configData[QueueConfig::BINDS])) {
75  foreach ($configData[QueueConfig::BINDS] as $configDataItem) {
76  $this->validateBindTopic(
77  $this->getAvailableTopics($configData, $xmlConfigData),
78  $configDataItem[QueueConfig::BIND_TOPIC]
79  );
80  }
81  }
82  }
83 
91  private function getAvailablePublishers($configData, $xmlConfigData)
92  {
93  $envConfigPublishers = isset($configData[QueueConfig::PUBLISHERS]) ? $configData[QueueConfig::PUBLISHERS] : [];
94  $xmlConfigPublishers = isset($xmlConfigData[QueueConfig::PUBLISHERS])
95  ? $xmlConfigData[QueueConfig::PUBLISHERS] : [];
96  return array_unique(
97  array_merge(
98  array_keys($xmlConfigPublishers),
99  array_keys($envConfigPublishers)
100  )
101  );
102  }
103 
111  private function getAvailableTopics($configData, $xmlConfigData)
112  {
113  $envConfigTopics = isset($configData[QueueConfig::TOPICS]) ? $configData[QueueConfig::TOPICS] : [];
114  $xmlConfigTopics = isset($xmlConfigData[QueueConfig::TOPICS]) ? $xmlConfigData[QueueConfig::TOPICS] : [];
115  return array_unique(
116  array_merge(
117  array_keys($xmlConfigTopics),
118  array_keys($envConfigTopics)
119  )
120  );
121  }
122 }
__construct(TypeProcessor $typeProcessor, MethodsMap $methodsMap)
Definition: Validator.php:29
validateResponseSchemaType($responseSchema, $topicName)
Definition: Validator.php:167
validate($configData, array $xmlConfigData=[])
Definition: Validator.php:44
validateTopicPublisher($publishers, $publisherName, $topicName)
Definition: Validator.php:146
catch(\Exception $e) $handler
Definition: index.php:30
validateHandlerType($serviceName, $methodName, $consumerName)
Definition: Validator.php:73