Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Mapper.php
Go to the documentation of this file.
1 <?php
7 
11 class Mapper implements MapperInterface
12 {
16  private $config;
17 
23  public function __construct(
24  $config = []
25  ) {
26  $this->config = $config;
27  }
28 
33  {
34  if (isset($this->config[$entityType])) {
35  foreach ($this->config[$entityType] as $databaseFieldName => $entityFieldName) {
36  if (!$entityFieldName) {
37  throw new \LogicException('Incorrect configuration for ' . $entityType);
38  }
39  if (isset($data[$entityFieldName])) {
40  $data[$databaseFieldName] = $data[$entityFieldName];
41  unset($data[$entityFieldName]);
42  }
43  }
44  }
45  return $data;
46  }
47 
52  {
53  if (isset($this->config[$entityType])) {
54  foreach ($this->config[$entityType] as $databaseFieldName => $entityFieldName) {
55  if (!$entityFieldName) {
56  throw new \LogicException('Incorrect configuration for ' . $entityType);
57  }
58  if (isset($data[$databaseFieldName])) {
59  $data[$entityFieldName] = $data[$databaseFieldName];
60  unset($data[$databaseFieldName]);
61  }
62  }
63  }
64  return $data;
65  }
66 }
entityToDatabase($entityType, $data)
Definition: Mapper.php:32
databaseToEntity($entityType, $data)
Definition: Mapper.php:51