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
|
|
|
* |
8
|
|
|
* @license GPL-3.0 |
9
|
|
|
* |
10
|
|
|
* @author Gerrit Addiks <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Addiks\RDMBundle\Mapping; |
14
|
|
|
|
15
|
|
|
use Addiks\RDMBundle\Mapping\ObjectMappingInterface; |
16
|
|
|
use Doctrine\DBAL\Schema\Column; |
17
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
18
|
|
|
use Webmozart\Assert\Assert; |
19
|
|
|
|
20
|
|
|
final class ObjectMapping implements ObjectMappingInterface |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $className; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array<MappingInterface> |
30
|
|
|
*/ |
31
|
|
|
private $fieldMappings = array(); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var CallDefinitionInterface|null |
35
|
|
|
*/ |
36
|
|
|
private $factory; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var CallDefinitionInterface|null |
40
|
|
|
*/ |
41
|
|
|
private $serializer; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
private $origin; |
47
|
|
|
|
48
|
9 |
|
public function __construct( |
49
|
|
|
string $className, |
50
|
|
|
array $fieldMappings, |
51
|
|
|
string $origin = "undefined", |
52
|
|
|
CallDefinitionInterface $factory = null, |
53
|
|
|
CallDefinitionInterface $serializer = null |
54
|
|
|
) { |
55
|
9 |
|
$this->className = $className; |
56
|
9 |
|
$this->factory = $factory; |
57
|
9 |
|
$this->serializer = $serializer; |
58
|
9 |
|
$this->origin = $origin; |
59
|
|
|
|
60
|
9 |
|
foreach ($fieldMappings as $fieldName => $fieldMapping) { |
61
|
|
|
/** @var MappingInterface $fieldMapping */ |
62
|
|
|
|
63
|
9 |
|
Assert::isInstanceOf($fieldMapping, MappingInterface::class); |
64
|
|
|
|
65
|
9 |
|
$this->fieldMappings[$fieldName] = $fieldMapping; |
66
|
|
|
} |
67
|
9 |
|
} |
68
|
|
|
|
69
|
2 |
|
public function getClassName(): string |
70
|
|
|
{ |
71
|
2 |
|
return $this->className; |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function getFieldMappings(): array |
75
|
|
|
{ |
76
|
2 |
|
return $this->fieldMappings; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function describeOrigin(): string |
80
|
|
|
{ |
81
|
1 |
|
return $this->origin; |
82
|
|
|
} |
83
|
|
|
|
84
|
2 |
|
public function collectDBALColumns(): array |
85
|
|
|
{ |
86
|
|
|
/** @var array<Column> $additionalColumns */ |
87
|
2 |
|
$additionalColumns = array(); |
88
|
|
|
|
89
|
2 |
|
foreach ($this->fieldMappings as $fieldMapping) { |
90
|
|
|
/** @var MappingInterface $fieldMapping */ |
91
|
|
|
|
92
|
2 |
|
$additionalColumns = array_merge( |
93
|
2 |
|
$additionalColumns, |
94
|
2 |
|
$fieldMapping->collectDBALColumns() |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
2 |
|
return $additionalColumns; |
99
|
|
|
} |
100
|
|
|
|
101
|
2 |
|
public function getFactory(): ?CallDefinitionInterface |
102
|
|
|
{ |
103
|
2 |
|
return $this->factory; |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function getSerializer(): ?CallDefinitionInterface |
107
|
|
|
{ |
108
|
1 |
|
return $this->serializer; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|