Factory.php 1.2 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\Specification;
  7. use Magento\Framework\ObjectManagerInterface;
  8. use Magento\Payment\Model\Method\SpecificationInterface;
  9. /**
  10. * Specification Factory
  11. */
  12. class Factory
  13. {
  14. /**
  15. * Object Manager
  16. *
  17. * @var ObjectManagerInterface
  18. */
  19. protected $objectManager;
  20. /**
  21. * Factory constructor
  22. *
  23. * @param ObjectManagerInterface $objectManager
  24. */
  25. public function __construct(ObjectManagerInterface $objectManager)
  26. {
  27. $this->objectManager = $objectManager;
  28. }
  29. /**
  30. * Create specification instance
  31. *
  32. * @param string $specificationClass
  33. * @return SpecificationInterface
  34. * @throws \InvalidArgumentException
  35. */
  36. public function create($specificationClass)
  37. {
  38. $specification = $this->objectManager->get($specificationClass);
  39. if (!$specification instanceof SpecificationInterface) {
  40. throw new \InvalidArgumentException('Specification must implement SpecificationInterface');
  41. }
  42. return $specification;
  43. }
  44. }