BindingInstaller.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Amqp\Topology;
  7. use Magento\Framework\MessageQueue\Topology\Config\ExchangeConfigItem\BindingInterface;
  8. use PhpAmqpLib\Channel\AMQPChannel;
  9. /**
  10. * {@inheritdoc}
  11. */
  12. class BindingInstaller implements BindingInstallerInterface
  13. {
  14. /**
  15. * @var BindingInstallerInterface[]
  16. */
  17. private $installers;
  18. /**
  19. * Initialize dependencies.
  20. *
  21. * @param BindingInstallerInterface[] $installers
  22. */
  23. public function __construct(array $installers)
  24. {
  25. $this->installers = $installers;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function install(AMQPChannel $channel, BindingInterface $binding, $exchangeName)
  31. {
  32. $this->getInstaller($binding->getDestinationType())->install($channel, $binding, $exchangeName);
  33. }
  34. /**
  35. * Get binding installer by type.
  36. *
  37. * @param string $type
  38. * @return BindingInstallerInterface
  39. */
  40. private function getInstaller($type)
  41. {
  42. if (!isset($this->installers[$type])) {
  43. throw new \InvalidArgumentException(sprintf('Installer type [%s] is not configured', $type));
  44. }
  45. return $this->installers[$type];
  46. }
  47. }