Publisher.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\WebapiAsync\Code\Generator\Config\RemoteServiceReader;
  8. use Magento\AsynchronousOperations\Model\ConfigInterface as WebApiAsyncConfig;
  9. /**
  10. * Remote service reader with auto generated configuration for queue_publisher.xml
  11. */
  12. class Publisher implements \Magento\Framework\Config\ReaderInterface
  13. {
  14. /**
  15. * @var WebApiAsyncConfig
  16. */
  17. private $webapiAsyncConfig;
  18. /**
  19. * Initialize dependencies.
  20. *
  21. * @param WebApiAsyncConfig $webapiAsyncConfig
  22. */
  23. public function __construct(
  24. WebApiAsyncConfig $webapiAsyncConfig
  25. ) {
  26. $this->webapiAsyncConfig = $webapiAsyncConfig;
  27. }
  28. /**
  29. * Generate publisher configuration based on remote services declarations
  30. *
  31. * @param string|null $scope
  32. * @return array
  33. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  34. */
  35. public function read($scope = null)
  36. {
  37. $asyncServicesData = $this->webapiAsyncConfig->getServices();
  38. $result = [];
  39. foreach ($asyncServicesData as $serviceData) {
  40. $topicName = $serviceData[WebApiAsyncConfig::SERVICE_PARAM_KEY_TOPIC];
  41. $result[$topicName] =
  42. [
  43. 'topic' => $topicName,
  44. 'disabled' => false,
  45. 'connections' => [
  46. 'amqp' => [
  47. 'name' => 'amqp',
  48. 'exchange' => 'magento',
  49. 'disabled' => false,
  50. ],
  51. ],
  52. ];
  53. }
  54. return $result;
  55. }
  56. }