Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConsumerInstance.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
20  public function validate($configData)
21  {
22  foreach ($configData as $consumerConfig) {
23  $this->validateConsumerInstance($consumerConfig);
24  }
25  }
26 
34  private function validateConsumerInstance($consumerConfig)
35  {
36  $consumerInstance = $consumerConfig['consumerInstance'];
37  if ($consumerInstance == ConsumerInterface::class) {
38  return;
39  }
40  if (!class_exists($consumerInstance)) {
41  throw new \LogicException(
42  sprintf(
43  "'%s' does not exist and thus cannot be used as 'consumerInstance' for '%s' consumer.",
44  $consumerInstance,
45  $consumerConfig['name'],
46  ConsumerInterface::class
47  )
48  );
49  }
50  $implementedInterfaces = class_implements($consumerInstance);
51  if (!in_array(ConsumerInterface::class, $implementedInterfaces)) {
52  throw new \LogicException(
53  sprintf(
54  "'%s' cannot be specified as 'consumerInstance' for '%s' consumer,"
55  . " unless it implements '%s' interface",
56  $consumerInstance,
57  $consumerConfig['name'],
58  ConsumerInterface::class
59  )
60  );
61  }
62  }
63 }