ArrayPool.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Option;
  7. /**
  8. * Array optioned object factory
  9. */
  10. class ArrayPool
  11. {
  12. /**
  13. * @var \Magento\Framework\ObjectManagerInterface
  14. */
  15. protected $_objectManager;
  16. /**
  17. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  18. */
  19. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  20. {
  21. $this->_objectManager = $objectManager;
  22. }
  23. /**
  24. * Get array optioned object
  25. *
  26. * @param string $model
  27. * @throws \InvalidArgumentException
  28. * @return \Magento\Framework\Data\OptionSourceInterface
  29. */
  30. public function get($model)
  31. {
  32. $modelInstance = $this->_objectManager->get($model);
  33. if (false == $modelInstance instanceof \Magento\Framework\Data\OptionSourceInterface) {
  34. throw new \InvalidArgumentException($model
  35. . 'doesn\'t implement \Magento\Framework\Data\OptionSourceInterface');
  36. }
  37. return $modelInstance;
  38. }
  39. }