SourceFactory.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\ResourceConnection;
  7. class SourceFactory
  8. {
  9. /**
  10. * @var \Magento\Framework\ObjectManagerInterface
  11. */
  12. protected $objectManager;
  13. /**
  14. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  15. */
  16. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  17. {
  18. $this->objectManager = $objectManager;
  19. }
  20. /**
  21. * Get source class instance by class name
  22. *
  23. * @param string $className
  24. * @throws \InvalidArgumentException
  25. * @return SourceProviderInterface
  26. */
  27. public function create($className)
  28. {
  29. $source = $this->objectManager->create($className);
  30. if (!$source instanceof SourceProviderInterface) {
  31. throw new \InvalidArgumentException(
  32. $className . ' doesn\'t implement \Magento\Framework\App\ResourceConnection\SourceProviderInterface'
  33. );
  34. }
  35. return $source;
  36. }
  37. }