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
|
|
|
use Addiks\RDMBundle\Mapping\ObjectMapping; |
17
|
|
|
use Webmozart\Assert\Assert; |
18
|
|
|
|
19
|
|
|
final class EntityMapping implements EntityMappingInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $className; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array<MappingInterface> |
29
|
|
|
*/ |
30
|
|
|
private $fieldMappings = array(); |
31
|
|
|
|
32
|
27 |
|
public function __construct(string $className, array $fieldMappings) |
33
|
|
|
{ |
34
|
27 |
|
$this->className = $className; |
35
|
|
|
|
36
|
27 |
|
foreach ($fieldMappings as $fieldName => $fieldMapping) { |
37
|
|
|
/** @var MappingInterface $fieldMapping */ |
38
|
|
|
|
39
|
25 |
|
Assert::isInstanceOf($fieldMapping, MappingInterface::class); |
40
|
|
|
|
41
|
25 |
|
$this->fieldMappings[$fieldName] = $fieldMapping; |
42
|
|
|
} |
43
|
27 |
|
} |
44
|
|
|
|
45
|
5 |
|
public function getEntityClassName(): string |
46
|
|
|
{ |
47
|
5 |
|
return $this->className; |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
public function getClassName(): string |
51
|
|
|
{ |
52
|
1 |
|
return $this->className; |
53
|
|
|
} |
54
|
|
|
|
55
|
12 |
|
public function getFieldMappings(): array |
56
|
|
|
{ |
57
|
12 |
|
return $this->fieldMappings; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function describeOrigin(): string |
61
|
|
|
{ |
62
|
1 |
|
return $this->className; |
63
|
|
|
} |
64
|
|
|
|
65
|
10 |
|
public function collectDBALColumns(): array |
66
|
|
|
{ |
67
|
|
|
/** @var array<Column> $additionalColumns */ |
68
|
10 |
|
$additionalColumns = array(); |
69
|
|
|
|
70
|
10 |
|
foreach ($this->fieldMappings as $fieldMapping) { |
71
|
|
|
/** @var MappingInterface $fieldMapping */ |
72
|
|
|
|
73
|
10 |
|
$additionalColumns = array_merge( |
74
|
10 |
|
$additionalColumns, |
75
|
10 |
|
$fieldMapping->collectDBALColumns() |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
10 |
|
return $additionalColumns; |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
public function getFactory(): ?CallDefinitionInterface |
83
|
|
|
{ |
84
|
1 |
|
return null; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
public function getSerializer(): ?CallDefinitionInterface |
88
|
|
|
{ |
89
|
1 |
|
return null; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|