CommandManagerPool.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Gateway\Command;
  7. use Magento\Framework\Exception\NotFoundException;
  8. use Magento\Framework\ObjectManager\TMap;
  9. use Magento\Framework\ObjectManager\TMapFactory;
  10. /**
  11. * Class CommandManagerPool
  12. * @package Magento\Payment\Gateway\Command
  13. * @api
  14. * @since 100.1.0
  15. */
  16. class CommandManagerPool implements CommandManagerPoolInterface
  17. {
  18. /**
  19. * @var CommandManagerInterface[] | TMap
  20. */
  21. private $executors;
  22. /**
  23. * @param TMapFactory $tmapFactory
  24. * @param array $executors
  25. */
  26. public function __construct(
  27. TMapFactory $tmapFactory,
  28. array $executors = []
  29. ) {
  30. $this->executors = $tmapFactory->createSharedObjectsMap(
  31. [
  32. 'array' => $executors,
  33. 'type' => CommandManagerInterface::class
  34. ]
  35. );
  36. }
  37. /**
  38. * Returns Command executor for defined payment provider
  39. *
  40. * @param string $paymentProviderCode
  41. * @return CommandManagerInterface
  42. * @throws NotFoundException
  43. * @since 100.1.0
  44. */
  45. public function get($paymentProviderCode)
  46. {
  47. if (!isset($this->executors[$paymentProviderCode])) {
  48. throw new NotFoundException(
  49. __('The "%1" command executor isn\'t defined. Verify the executor and try again.', $paymentProviderCode)
  50. );
  51. }
  52. return $this->executors[$paymentProviderCode];
  53. }
  54. }