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 
10 
14 class Validator
15 {
19  private $typeProcessor;
20 
24  private $methodsMap;
25 
32  public function __construct(
33  TypeProcessor $typeProcessor,
34  MethodsMap $methodsMap
35  ) {
36  $this->typeProcessor = $typeProcessor;
37  $this->methodsMap = $methodsMap;
38  }
39 
45  public function validateResponseSchemaType($responseSchema, $topicName)
46  {
47  try {
48  $this->validateType($responseSchema);
49  } catch (\Exception $e) {
50  throw new \LogicException(
51  sprintf(
52  'Response schema definition for topic "%s" should reference existing type or service class. '
53  . 'Given "%s"',
54  $topicName,
55  $responseSchema
56  )
57  );
58  }
59  }
60 
66  public function validateRequestSchemaType($requestSchema, $topicName)
67  {
68  try {
69  $this->validateType($requestSchema);
70  } catch (\Exception $e) {
71  throw new \LogicException(
72  sprintf(
73  'Request schema definition for topic "%s" should reference existing service class. '
74  . 'Given "%s"',
75  $topicName,
76  $requestSchema
77  )
78  );
79  }
80  }
81 
89  public function validateResponseHandlersType($serviceName, $methodName, $handlerName, $topicName)
90  {
91  try {
92  $this->methodsMap->getMethodParams($serviceName, $methodName);
93  } catch (\Exception $e) {
94  throw new \LogicException(
95  sprintf(
96  'Service method specified in the definition of handler "%s" for topic "%s"'
97  . ' is not available. Given "%s"',
98  $handlerName,
99  $topicName,
100  $serviceName . '::' . $methodName
101  )
102  );
103  }
104  }
105 
113  protected function validateType($typeName)
114  {
115  if ($this->typeProcessor->isTypeSimple($typeName)) {
116  return $this;
117  }
118  if ($this->typeProcessor->isArrayType($typeName)) {
119  $arrayItemType = $this->typeProcessor->getArrayItemType($typeName);
120  $this->methodsMap->getMethodsMap($arrayItemType);
121  } else {
122  $this->methodsMap->getMethodsMap($typeName);
123  }
124  return $this;
125  }
126 }
__construct(TypeProcessor $typeProcessor, MethodsMap $methodsMap)
Definition: Validator.php:32
validateRequestSchemaType($requestSchema, $topicName)
Definition: Validator.php:66
validateResponseSchemaType($responseSchema, $topicName)
Definition: Validator.php:45
validateResponseHandlersType($serviceName, $methodName, $handlerName, $topicName)
Definition: Validator.php:89