QueueRepository.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue;
  7. /**
  8. * Queue factory
  9. */
  10. class QueueRepository
  11. {
  12. /**
  13. * @var \Magento\Framework\ObjectManagerInterface
  14. */
  15. private $objectManager;
  16. /**
  17. * @var QueueInterface[]
  18. */
  19. private $queueInstances;
  20. /**
  21. * @var QueueFactoryInterface
  22. */
  23. private $queueFactory;
  24. /**
  25. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  26. * @param string[] $queues
  27. *
  28. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  29. */
  30. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, array $queues = [])
  31. {
  32. $this->objectManager = $objectManager;
  33. }
  34. /**
  35. * Get queue instance by connection name and queue name.
  36. *
  37. * @param string $connectionName
  38. * @param string $queueName
  39. * @return QueueInterface
  40. * @throws \LogicException
  41. */
  42. public function get($connectionName, $queueName)
  43. {
  44. if (!isset($this->queueInstances[$connectionName][$queueName])) {
  45. $queue = $this->getQueueFactory()->create($queueName, $connectionName);
  46. $this->queueInstances[$connectionName][$queueName] = $queue;
  47. }
  48. return $this->queueInstances[$connectionName][$queueName];
  49. }
  50. /**
  51. * Get queue factory.
  52. *
  53. * @return QueueFactoryInterface
  54. * @deprecated 102.0.1
  55. */
  56. private function getQueueFactory()
  57. {
  58. if ($this->queueFactory === null) {
  59. $this->queueFactory = $this->objectManager->get(QueueFactoryInterface::class);
  60. }
  61. return $this->queueFactory;
  62. }
  63. }