QueueFactory.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Process;
  7. use Magento\Framework\ObjectManagerInterface;
  8. use Magento\Framework\Exception\LocalizedException;
  9. use Magento\Framework\Phrase;
  10. /**
  11. * Factory class for @see \Magento\Deploy\Process\Queue
  12. */
  13. class QueueFactory
  14. {
  15. /**
  16. * Object Manager instance
  17. *
  18. * @var ObjectManagerInterface
  19. */
  20. private $objectManager;
  21. /**
  22. * Instance type to create
  23. *
  24. * @var string
  25. */
  26. private $type;
  27. /**
  28. * Factory constructor
  29. *
  30. * @param ObjectManagerInterface $objectManager
  31. * @param string $type
  32. */
  33. public function __construct(ObjectManagerInterface $objectManager, $type = Queue::class)
  34. {
  35. $this->objectManager = $objectManager;
  36. $this->type = $type;
  37. }
  38. /**
  39. * Create class instance with specified parameters
  40. *
  41. * @param array $arguments
  42. * @return Queue
  43. * @throws LocalizedException
  44. */
  45. public function create(array $arguments = [])
  46. {
  47. $queue = $this->objectManager->create($this->type, $arguments);
  48. if (!$queue instanceof Queue) {
  49. throw new LocalizedException(
  50. new Phrase("Wrong queue type specified.")
  51. );
  52. }
  53. return $queue;
  54. }
  55. }