|
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\MappingInterface; |
|
16
|
|
|
use Webmozart\Assert\Assert; |
|
17
|
|
|
use Doctrine\DBAL\Schema\Column; |
|
18
|
|
|
use Addiks\RDMBundle\Mapping\ArrayMappingInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class ArrayMapping implements ArrayMappingInterface |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var array<MappingInterface> |
|
25
|
|
|
*/ |
|
26
|
|
|
private $entryMappings = array(); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $origin; |
|
32
|
|
|
|
|
33
|
6 |
|
public function __construct(array $entryMappings, string $origin = "unknown") |
|
34
|
|
|
{ |
|
35
|
6 |
|
$this->origin = $origin; |
|
36
|
|
|
|
|
37
|
6 |
|
foreach ($entryMappings as $key => $entryMapping) { |
|
38
|
|
|
/** @var MappingInterface $entryMapping */ |
|
39
|
|
|
|
|
40
|
6 |
|
Assert::isInstanceOf($entryMapping, MappingInterface::class); |
|
41
|
|
|
|
|
42
|
6 |
|
$this->entryMappings[$key] = $entryMapping; |
|
43
|
|
|
} |
|
44
|
6 |
|
} |
|
45
|
|
|
|
|
46
|
2 |
|
public function getEntryMappings(): array |
|
47
|
|
|
{ |
|
48
|
2 |
|
return $this->entryMappings; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
public function describeOrigin(): string |
|
52
|
|
|
{ |
|
53
|
1 |
|
return $this->origin; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
public function collectDBALColumns(): array |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var array<Column> $dbalColumns */ |
|
59
|
2 |
|
$dbalColumns = array(); |
|
60
|
|
|
|
|
61
|
2 |
|
foreach ($this->entryMappings as $entryMapping) { |
|
62
|
|
|
/** @var MappingInterface $entryMapping */ |
|
63
|
|
|
|
|
64
|
2 |
|
$dbalColumns = array_merge( |
|
65
|
2 |
|
$dbalColumns, |
|
66
|
2 |
|
$entryMapping->collectDBALColumns() |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
2 |
|
return $dbalColumns; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|