Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Handlers.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class Handlers implements ValidatorInterface
15 {
19  private $methodsMap;
20 
26  public function __construct(MethodsMap $methodsMap)
27  {
28  $this->methodsMap = $methodsMap;
29  }
30 
34  public function validate($configData)
35  {
36  foreach ($configData as $consumerConfig) {
37  $consumerName = $consumerConfig['name'];
38  if (!is_array($consumerConfig['handlers'])) {
39  throw new \LogicException(
40  sprintf(
41  "'handlers' element must be an array for consumer '%s'",
42  $consumerName
43  )
44  );
45  }
46  foreach ($consumerConfig['handlers'] as $handler) {
47  $this->validateHandler($handler, $consumerName);
48  }
49  }
50  }
51 
60  private function validateHandler($handler, $consumerName)
61  {
62  if (!isset($handler['type']) || !isset($handler['method'])) {
63  throw new \LogicException(
64  sprintf(
65  "'%s' consumer declaration is invalid. "
66  . "Every handler element must be an array. It must contain 'type' and 'method' elements.",
67  $consumerName
68  )
69  );
70  }
71  try {
72  $this->methodsMap->getMethodParams($handler['type'], $handler['method']);
73  } catch (\Exception $e) {
74  throw new \LogicException(
75  sprintf(
76  'Service method specified as handler for of consumer "%s" is not available. Given "%s"',
77  $consumerName,
78  $handler['type'] . '::' . $handler['method']
79  )
80  );
81  }
82  }
83 }
catch(\Exception $e) $handler
Definition: index.php:30