ValueFactory.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\App\Config;
  7. /**
  8. * Factory class
  9. */
  10. class ValueFactory
  11. {
  12. /**
  13. * Object Manager instance
  14. *
  15. * @var \Magento\Framework\ObjectManagerInterface
  16. */
  17. protected $_objectManager = null;
  18. /**
  19. * Instance name to create
  20. *
  21. * @var string
  22. */
  23. protected $_instanceName = null;
  24. /**
  25. * Factory constructor
  26. *
  27. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  28. * @param string $instanceName
  29. */
  30. public function __construct(
  31. \Magento\Framework\ObjectManagerInterface $objectManager,
  32. $instanceName = \Magento\Framework\App\Config\ValueInterface::class
  33. ) {
  34. $this->_objectManager = $objectManager;
  35. $this->_instanceName = $instanceName;
  36. }
  37. /**
  38. * Create class instance with specified parameters
  39. *
  40. * @param array $data
  41. * @return \Magento\Framework\App\Config\ValueInterface
  42. * @throws \InvalidArgumentException
  43. */
  44. public function create(array $data = [])
  45. {
  46. $model = $this->_objectManager->create($this->_instanceName, $data);
  47. if (!$model instanceof \Magento\Framework\App\Config\ValueInterface) {
  48. throw new \InvalidArgumentException('Invalid config field model: ' . $this->_instanceName);
  49. }
  50. return $model;
  51. }
  52. }