Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExchangeFactory.php
Go to the documentation of this file.
1 <?php
7 
15 {
19  private $exchangeFactories;
20 
24  private $connectionTypeResolver;
25 
32  protected $objectManager = null;
33 
42  public function __construct(
43  \Magento\Framework\MessageQueue\ConnectionTypeResolver $connectionTypeResolver,
45  array $exchangeFactories = []
46  ) {
47  $this->objectManager = $objectManager;
48  $this->exchangeFactories = $exchangeFactories;
49  $this->connectionTypeResolver = $connectionTypeResolver;
50  }
51 
56  public function create($connectionName, array $data = [])
57  {
58  $connectionType = $this->connectionTypeResolver->getConnectionType($connectionName);
59 
60  if (!isset($this->exchangeFactories[$connectionType])) {
61  throw new \LogicException("Not found exchange for connection name '{$connectionName}' in config");
62  }
63 
64  $factory = $this->exchangeFactories[$connectionType];
65  $exchange = $factory->create($connectionName, $data);
66 
67  if (!$exchange instanceof ExchangeInterface) {
68  $exchangeInterface = \Magento\Framework\MessageQueue\Bulk\ExchangeInterface::class;
69  throw new \LogicException(
70  "Exchange for connection name '{$connectionName}' " .
71  "does not implement interface '{$exchangeInterface}'"
72  );
73  }
74  return $exchange;
75  }
76 }
__construct(\Magento\Framework\MessageQueue\ConnectionTypeResolver $connectionTypeResolver, \Magento\Framework\ObjectManagerInterface $objectManager, array $exchangeFactories=[])