Factory.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * This file is part of the Klarna Order Management module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Ordermanagement\Model\Api;
  11. /**
  12. * Class Factory
  13. *
  14. * @package Klarna\Ordermanagement\Model\Api
  15. */
  16. class Factory
  17. {
  18. /**
  19. * Object manager
  20. *
  21. * @var \Magento\Framework\ObjectManagerInterface
  22. */
  23. private $objectManager;
  24. /**
  25. * Construct
  26. *
  27. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  28. */
  29. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  30. {
  31. $this->objectManager = $objectManager;
  32. }
  33. /**
  34. * Creates new instances of API models
  35. *
  36. * @param string $className
  37. * @return \Klarna\Ordermanagement\Api\ApiInterface
  38. * @throws \Magento\Framework\Exception\LocalizedException
  39. */
  40. public function create($className)
  41. {
  42. $method = $this->objectManager->create($className);
  43. if (!$method instanceof \Klarna\Ordermanagement\Api\ApiInterface) {
  44. throw new \Magento\Framework\Exception\LocalizedException(
  45. __('%1 class doesn\'t implement \Klarna\Ordermanagement\Api\ApiInterface', $className)
  46. );
  47. }
  48. return $method;
  49. }
  50. }