Config.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Consumer;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\MessageQueue\Consumer\Config\ConsumerConfigItem\Iterator;
  9. use Magento\Framework\Phrase;
  10. /**
  11. * {@inheritdoc}
  12. */
  13. class Config implements ConfigInterface
  14. {
  15. /**
  16. * Item 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 getConsumer($name)
  34. {
  35. $consumer = $this->iterator[$name];
  36. if (!$consumer) {
  37. throw new LocalizedException(new Phrase("Consumer '%consumer' is not declared.", ['consumer' => $name]));
  38. }
  39. return $consumer;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function getConsumers()
  45. {
  46. return $this->iterator;
  47. }
  48. }