EntityFactory.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Data\Collection;
  7. class EntityFactory implements EntityFactoryInterface
  8. {
  9. /**
  10. * Object Manager instance
  11. *
  12. * @var \Magento\Framework\ObjectManagerInterface
  13. */
  14. protected $_objectManager = null;
  15. /**
  16. * Factory constructor
  17. *
  18. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  19. */
  20. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  21. {
  22. $this->_objectManager = $objectManager;
  23. }
  24. /**
  25. * Create class instance with specified parameters
  26. *
  27. * @param string $className
  28. * @param array $data
  29. * @throws \LogicException
  30. * @return \Magento\Framework\DataObject
  31. */
  32. public function create($className, array $data = [])
  33. {
  34. $model = $this->_objectManager->create($className, $data);
  35. //TODO: fix that when this factory used only for \Magento\Framework\Model\AbstractModel
  36. //if (!$model instanceof \Magento\Framework\Model\AbstractModel) {
  37. // throw new \LogicException($className . ' doesn\'t implement \Magento\Framework\Model\AbstractModel');
  38. //}
  39. return $model;
  40. }
  41. }