Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Factory.php
Go to the documentation of this file.
1 <?php
11 
12 class Factory
13 {
19  protected $_objectManager;
20 
24  public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
25  {
26  $this->_objectManager = $objectManager;
27  }
28 
34  public function create($className)
35  {
36  if (!$className) {
37  throw new \InvalidArgumentException('Incorrect class name');
38  }
39 
40  $attributeCollection = $this->_objectManager->create($className);
41 
42  if (!$attributeCollection instanceof \Magento\Framework\Data\Collection) {
43  throw new \InvalidArgumentException(
44  sprintf(
45  "Attribute factory class \"%s\" must implement \Magento\Framework\Data\Collection.",
46  get_class($attributeCollection)
47  )
48  );
49  }
50  return $attributeCollection;
51  }
52 }
$objectManager
Definition: bootstrap.php:17
__construct(\Magento\Framework\ObjectManagerInterface $objectManager)
Definition: Factory.php:24
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31