Config.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Topology;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\Phrase;
  9. use Magento\Framework\MessageQueue\Topology\Config\ExchangeConfigItem\Iterator as ExchangeIterator;
  10. use Magento\Framework\MessageQueue\Topology\Config\QueueConfigItem\Iterator as QueueIterator;
  11. /**
  12. * Topology config provides access to data declared in etc/queue_topology.xml
  13. */
  14. class Config implements ConfigInterface
  15. {
  16. /**
  17. * Exchange config data iterator.
  18. *
  19. * @var ExchangeIterator
  20. */
  21. private $exchangeIterator;
  22. /**
  23. * Exchange config data iterator.
  24. *
  25. * @var ExchangeIterator
  26. */
  27. private $queueIterator;
  28. /**
  29. * Initialize dependencies.
  30. *
  31. * @param ExchangeIterator $exchangeIterator
  32. * @param QueueIterator $queueIterator
  33. */
  34. public function __construct(ExchangeIterator $exchangeIterator, QueueIterator $queueIterator)
  35. {
  36. $this->exchangeIterator = $exchangeIterator;
  37. $this->queueIterator = $queueIterator;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function getExchange($name, $connection)
  43. {
  44. $topology = $this->exchangeIterator[$name . '--' . $connection];
  45. if (!$topology) {
  46. throw new LocalizedException(
  47. new Phrase(
  48. 'The "%exchange" exchange is not declared for the "%connection" connection. Verify and try again.',
  49. [
  50. 'exchange' => $name,
  51. 'connection' => $connection
  52. ]
  53. )
  54. );
  55. }
  56. return $topology;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function getExchanges()
  62. {
  63. return $this->exchangeIterator;
  64. }
  65. /**
  66. * {@inheritdoc}
  67. */
  68. public function getQueues()
  69. {
  70. return $this->queueIterator;
  71. }
  72. }