|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2018 Gerrit Addiks. |
|
4
|
|
|
* This package (including this file) was released under the terms of the GPL-3.0. |
|
5
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
6
|
|
|
* If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
|
7
|
|
|
* @license GPL-3.0 |
|
8
|
|
|
* @author Gerrit Addiks <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Addiks\RDMBundle\Mapping; |
|
12
|
|
|
|
|
13
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
|
14
|
|
|
use Addiks\RDMBundle\Mapping\EntityMappingInterface; |
|
15
|
|
|
use Doctrine\DBAL\Schema\Column; |
|
16
|
|
|
|
|
17
|
|
|
final class EntityMapping implements EntityMappingInterface |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $className; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var array<MappingInterface> |
|
27
|
|
|
*/ |
|
28
|
|
|
private $fieldMappings = array(); |
|
29
|
|
|
|
|
30
|
25 |
|
public function __construct(string $className, array $fieldMappings) |
|
31
|
|
|
{ |
|
32
|
25 |
|
$this->className = $className; |
|
33
|
|
|
|
|
34
|
25 |
|
foreach ($fieldMappings as $fieldName => $fieldMapping) { |
|
35
|
|
|
/** @var MappingInterface $fieldMapping */ |
|
36
|
|
|
|
|
37
|
23 |
|
$this->addFieldMapping($fieldName, $fieldMapping); |
|
38
|
|
|
} |
|
39
|
25 |
|
} |
|
40
|
|
|
|
|
41
|
5 |
|
public function getEntityClassName(): string |
|
42
|
|
|
{ |
|
43
|
5 |
|
return $this->className; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
12 |
|
public function getFieldMappings(): array |
|
47
|
|
|
{ |
|
48
|
12 |
|
return $this->fieldMappings; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
public function describeOrigin(): string |
|
52
|
|
|
{ |
|
53
|
1 |
|
return $this->className; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
10 |
|
public function collectDBALColumns(): array |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var array<Column> $additionalColumns */ |
|
59
|
10 |
|
$additionalColumns = array(); |
|
60
|
|
|
|
|
61
|
10 |
|
foreach ($this->fieldMappings as $fieldMapping) { |
|
62
|
|
|
/** @var MappingInterface $fieldMapping */ |
|
63
|
|
|
|
|
64
|
10 |
|
$additionalColumns = array_merge( |
|
65
|
10 |
|
$additionalColumns, |
|
66
|
10 |
|
$fieldMapping->collectDBALColumns() |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
10 |
|
return $additionalColumns; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
23 |
|
private function addFieldMapping(string $fieldName, MappingInterface $fieldMapping): void |
|
74
|
|
|
{ |
|
75
|
23 |
|
$this->fieldMappings[$fieldName] = $fieldMapping; |
|
76
|
23 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|