FieldsetPool.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Indexer;
  7. use Magento\Framework\ObjectManagerInterface;
  8. /**
  9. * @api Retrieve Fieldset when implementing custom Indexer\Action
  10. * @since 100.0.2
  11. */
  12. class FieldsetPool
  13. {
  14. /**
  15. * @var ObjectManagerInterface
  16. */
  17. protected $objectManager;
  18. /**
  19. * @param ObjectManagerInterface $objectManager
  20. */
  21. public function __construct(ObjectManagerInterface $objectManager)
  22. {
  23. $this->objectManager = $objectManager;
  24. }
  25. /**
  26. * Get fieldset class instance
  27. *
  28. * @param string $fieldsetClass
  29. * @throws \InvalidArgumentException
  30. * @return FieldsetInterface
  31. */
  32. public function get($fieldsetClass)
  33. {
  34. $handler = $this->objectManager->get($fieldsetClass);
  35. if (!$handler instanceof FieldsetInterface) {
  36. throw new \InvalidArgumentException(
  37. $fieldsetClass . ' doesn\'t implement \Magento\Framework\Indexer\FieldsetInterface'
  38. );
  39. }
  40. return $handler;
  41. }
  42. }