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 {
17  protected $_objectManager;
18 
24  protected $_types = [
25  \Magento\Tax\Model\ClassModel::TAX_CLASS_TYPE_CUSTOMER => \Magento\Tax\Model\TaxClass\Type\Customer::class,
26  \Magento\Tax\Model\ClassModel::TAX_CLASS_TYPE_PRODUCT => \Magento\Tax\Model\TaxClass\Type\Product::class,
27  ];
28 
32  public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
33  {
34  $this->_objectManager = $objectManager;
35  }
36 
44  public function create(\Magento\Tax\Model\ClassModel $taxClass)
45  {
46  $taxClassType = $taxClass->getClassType();
47  if (!array_key_exists($taxClassType, $this->_types)) {
48  throw new \Magento\Framework\Exception\LocalizedException(
49  __('Invalid type of tax class "%1"', $taxClassType)
50  );
51  }
52  return $this->_objectManager->create(
53  $this->_types[$taxClassType],
54  ['data' => ['id' => $taxClass->getId()]]
55  );
56  }
57 }
create(\Magento\Tax\Model\ClassModel $taxClass)
Definition: Factory.php:44
$objectManager
Definition: bootstrap.php:17
__()
Definition: __.php:13
__construct(\Magento\Framework\ObjectManagerInterface $objectManager)
Definition: Factory.php:32