BackendFactory.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Model\Config;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class BackendFactory
  12. {
  13. /**
  14. * Object manager
  15. *
  16. * @var \Magento\Framework\ObjectManagerInterface
  17. */
  18. protected $_objectManager;
  19. /**
  20. * @param \Magento\Framework\ObjectManagerInterface $objectmanager
  21. */
  22. public function __construct(\Magento\Framework\ObjectManagerInterface $objectmanager)
  23. {
  24. $this->_objectManager = $objectmanager;
  25. }
  26. /**
  27. * Create backend model by name
  28. *
  29. * @param string $modelName
  30. * @param array $arguments The object arguments
  31. * @return \Magento\Framework\App\Config\ValueInterface
  32. * @throws \InvalidArgumentException
  33. */
  34. public function create($modelName, array $arguments = [])
  35. {
  36. $model = $this->_objectManager->create($modelName, $arguments);
  37. if (!$model instanceof \Magento\Framework\App\Config\ValueInterface) {
  38. throw new \InvalidArgumentException('Invalid config field backend model: ' . $modelName);
  39. }
  40. return $model;
  41. }
  42. }