Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Mapper Class Reference
Inheritance diagram for Mapper:
MapperInterface

Public Member Functions

 __construct ( $config=[])
 
 entityToDatabase ($entityType, $data)
 
 databaseToEntity ($entityType, $data)
 

Detailed Description

Class Mapper

Definition at line 11 of file Mapper.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $config = [])

Initialize dependencies.

Parameters
array$config

Definition at line 23 of file Mapper.php.

25  {
26  $this->config = $config;
27  }

Member Function Documentation

◆ databaseToEntity()

databaseToEntity (   $entityType,
  $data 
)

{Map database field name to entity field name

Parameters
string$entityType
array$data
Returns
array
Exceptions
}

Implements MapperInterface.

Definition at line 51 of file Mapper.php.

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  }

◆ entityToDatabase()

entityToDatabase (   $entityType,
  $data 
)

{Map entity field name to database field name

Parameters
string$entityType
array$data
Returns
array
Exceptions
}

Implements MapperInterface.

Definition at line 32 of file Mapper.php.

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  }

The documentation for this class was generated from the following file: