ModifierFactory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\DataProvider\Modifier;
  7. use Magento\Framework\ObjectManagerInterface;
  8. /**
  9. * Class Factory
  10. */
  11. class ModifierFactory
  12. {
  13. /**
  14. * Object Manager
  15. *
  16. * @var ObjectManagerInterface
  17. */
  18. protected $objectManager;
  19. /**
  20. * Construct
  21. *
  22. * @param ObjectManagerInterface $objectManager
  23. */
  24. public function __construct(ObjectManagerInterface $objectManager)
  25. {
  26. $this->objectManager = $objectManager;
  27. }
  28. /**
  29. * Create model
  30. *
  31. * @param string $className
  32. * @param array $data
  33. * @return ModifierInterface
  34. * @throws \InvalidArgumentException
  35. */
  36. public function create($className, array $data = [])
  37. {
  38. $model = $this->objectManager->create($className, $data);
  39. if (!$model instanceof ModifierInterface) {
  40. throw new \InvalidArgumentException(
  41. 'Type "' . $className . '" is not instance on ' . ModifierInterface::class
  42. );
  43. }
  44. return $model;
  45. }
  46. }