Config.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Communication;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\Communication\Config\Data as ConfigData;
  9. use Magento\Framework\Phrase;
  10. /**
  11. * Class for accessing to communication configuration.
  12. */
  13. class Config implements ConfigInterface
  14. {
  15. /**
  16. * @var ConfigData
  17. */
  18. protected $data;
  19. /**
  20. * Initialize dependencies.
  21. *
  22. * @param ConfigData $configData
  23. */
  24. public function __construct(ConfigData $configData)
  25. {
  26. $this->data = $configData;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getTopic($topicName)
  32. {
  33. $data = $this->data->get(self::TOPICS . '/' . $topicName);
  34. if ($data === null) {
  35. throw new LocalizedException(
  36. new Phrase('Topic "%topic" is not configured.', ['topic' => $topicName])
  37. );
  38. }
  39. return $data;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function getTopicHandlers($topicName)
  45. {
  46. $topicData = $this->getTopic($topicName);
  47. return $topicData[self::TOPIC_HANDLERS];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function getTopics()
  53. {
  54. return $this->data->get(self::TOPICS) ?: [];
  55. }
  56. }