Factory.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model\Method;
  7. /**
  8. * Class \Magento\Payment\Model\Method\Factory
  9. */
  10. class Factory
  11. {
  12. /**
  13. * Object manager
  14. *
  15. * @var \Magento\Framework\ObjectManagerInterface
  16. */
  17. protected $_objectManager;
  18. /**
  19. * Construct
  20. *
  21. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  22. */
  23. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  24. {
  25. $this->_objectManager = $objectManager;
  26. }
  27. /**
  28. * Creates new instances of payment method models
  29. *
  30. * @param string $className
  31. * @param array $data
  32. * @return \Magento\Payment\Model\MethodInterface
  33. * @throws \Magento\Framework\Exception\LocalizedException
  34. */
  35. public function create($className, $data = [])
  36. {
  37. $method = $this->_objectManager->create($className, $data);
  38. if (!$method instanceof \Magento\Payment\Model\MethodInterface) {
  39. throw new \Magento\Framework\Exception\LocalizedException(
  40. __('%1 class doesn\'t implement \Magento\Payment\Model\MethodInterface', $className)
  41. );
  42. }
  43. return $method;
  44. }
  45. }