CommandPool.php 1.3 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\ObjectManager\TMap;
  8. use Magento\Payment\Gateway\CommandInterface;
  9. use Magento\Framework\Exception\NotFoundException;
  10. use Magento\Framework\ObjectManager\TMapFactory;
  11. /**
  12. * Class CommandPool
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class CommandPool implements CommandPoolInterface
  17. {
  18. /**
  19. * @var CommandInterface[] | TMap
  20. */
  21. private $commands;
  22. /**
  23. * @param TMapFactory $tmapFactory
  24. * @param array $commands
  25. */
  26. public function __construct(
  27. TMapFactory $tmapFactory,
  28. array $commands = []
  29. ) {
  30. $this->commands = $tmapFactory->create(
  31. [
  32. 'array' => $commands,
  33. 'type' => CommandInterface::class
  34. ]
  35. );
  36. }
  37. /**
  38. * Retrieves operation
  39. *
  40. * @param string $commandCode
  41. * @return CommandInterface
  42. * @throws NotFoundException
  43. */
  44. public function get($commandCode)
  45. {
  46. if (!isset($this->commands[$commandCode])) {
  47. throw new NotFoundException(
  48. __('The "%1" command doesn\'t exist. Verify the command and try again.', $commandCode)
  49. );
  50. }
  51. return $this->commands[$commandCode];
  52. }
  53. }