Publisher.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Config\Reader\Env\Converter;
  7. /**
  8. * Converts publisher related data from env.php to MessageQueue config array
  9. */
  10. class Publisher implements \Magento\Framework\Config\ConverterInterface
  11. {
  12. /**
  13. * Mapping between connection name and default exchange value
  14. * @var array
  15. */
  16. private $connectionToExchangeMap;
  17. /**
  18. * @param array $connectionToExchangeMap
  19. */
  20. public function __construct(
  21. $connectionToExchangeMap = []
  22. ) {
  23. $this->connectionToExchangeMap = $connectionToExchangeMap;
  24. }
  25. /**
  26. * {@inheritDoc}
  27. */
  28. public function convert($source)
  29. {
  30. $publishersConfig = isset($source[\Magento\Framework\MessageQueue\Config\Reader\Env::ENV_PUBLISHERS])
  31. ? $source[\Magento\Framework\MessageQueue\Config\Reader\Env::ENV_PUBLISHERS]
  32. : [];
  33. $connections = [];
  34. if (!empty($publishersConfig)) {
  35. foreach ($publishersConfig as $configuration) {
  36. if (isset($configuration['connections'])) {
  37. $publisherData = [];
  38. foreach ($configuration['connections'] as $connectionName => $config) {
  39. if (isset($this->connectionToExchangeMap[$connectionName])) {
  40. $publisherName = $connectionName . '-' . $this->connectionToExchangeMap[$connectionName];
  41. $config['connection'] = $config['name'];
  42. $config['name'] = $publisherName;
  43. $publisherData[$publisherName] = $config;
  44. $connections = array_replace_recursive($connections, $publisherData);
  45. }
  46. }
  47. }
  48. }
  49. $source[\Magento\Framework\MessageQueue\Config\Reader\Env::ENV_PUBLISHERS] = $connections;
  50. }
  51. return $source;
  52. }
  53. }