Config.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Publisher;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\Phrase;
  9. use \Magento\Framework\MessageQueue\Publisher\Config\PublisherConfigItem\Iterator;
  10. /**
  11. * Publisher config provides access data declared in etc/queue_publisher.xml
  12. */
  13. class Config implements ConfigInterface
  14. {
  15. /**
  16. * Publisher config data iterator.
  17. *
  18. * @var Iterator
  19. */
  20. private $iterator;
  21. /**
  22. * Initialize dependencies.
  23. *
  24. * @param Iterator $iterator
  25. */
  26. public function __construct(Iterator $iterator)
  27. {
  28. $this->iterator = $iterator;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function getPublisher($topic)
  34. {
  35. $publisher = $this->iterator[$topic];
  36. if (!$publisher) {
  37. throw new LocalizedException(
  38. new Phrase("Publisher '%publisher' is not declared.", ['publisher' => $topic])
  39. );
  40. }
  41. return $publisher;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function getPublishers()
  47. {
  48. return $this->iterator;
  49. }
  50. }