Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataMapperFactory.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
23  private $objectManager;
24 
28  private $dataMappers;
29 
34  public function __construct(
35  ObjectManagerInterface $objectManager,
36  array $dataMappers = []
37  ) {
38  $this->objectManager = $objectManager;
39  $this->dataMappers = $dataMappers;
40  }
41 
50  public function create($entityType)
51  {
52  if (!isset($this->dataMappers[$entityType])) {
53  throw new NoSuchEntityException(
54  __(
55  'There is no such data mapper "%1" for interface %2',
57  BatchDataMapperInterface::class
58  )
59  );
60  }
61  $dataMapperClass = $this->dataMappers[$entityType];
62  $dataMapperEntity = $this->objectManager->create($dataMapperClass);
63  if (!$dataMapperEntity instanceof BatchDataMapperInterface) {
65  __(
66  'Data mapper "%1" must implement interface %2',
67  $dataMapperClass,
68  BatchDataMapperInterface::class
69  )
70  );
71  }
72 
73  return $dataMapperEntity;
74  }
75 }
$objectManager
Definition: bootstrap.php:17
__()
Definition: __.php:13
__construct(ObjectManagerInterface $objectManager, array $dataMappers=[])