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\Drivers; |
12
|
|
|
|
13
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface; |
14
|
|
|
use Addiks\RDMBundle\Mapping\EntityMappingInterface; |
15
|
|
|
use Addiks\RDMBundle\Mapping\MappingInterface; |
16
|
|
|
use Addiks\RDMBundle\Mapping\EntityMapping; |
17
|
|
|
|
18
|
|
|
final class MappingDriverChain implements MappingDriverInterface |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array<MappingDriverInterface> |
23
|
|
|
*/ |
24
|
|
|
private $innerDrivers = array(); |
25
|
|
|
|
26
|
8 |
|
public function __construct(array $innerDrivers = array()) |
27
|
|
|
{ |
28
|
8 |
|
foreach ($innerDrivers as $innerDriver) { |
29
|
|
|
/** @var MappingDriverInterface $innerDriver */ |
30
|
|
|
|
31
|
8 |
|
$this->addInnerMetadataDriver($innerDriver); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
8 |
|
public function loadRDMMetadataForClass(string $className): ?EntityMappingInterface |
36
|
|
|
{ |
37
|
|
|
/** @var ?EntityMappingInterface $mapping */ |
38
|
8 |
|
$mapping = null; |
39
|
|
|
|
40
|
|
|
/** @var array<MappingInterface> $fieldMappings */ |
41
|
8 |
|
$fieldMappings = array(); |
42
|
|
|
|
43
|
8 |
|
foreach ($this->innerDrivers as $innerDriver) { |
44
|
|
|
/** @var MappingDriverInterface $innerDriver */ |
45
|
|
|
|
46
|
|
|
/** @var ?EntityMappingInterface $driverMapping */ |
47
|
8 |
|
$driverMapping = $innerDriver->loadRDMMetadataForClass($className); |
48
|
|
|
|
49
|
8 |
|
if ($driverMapping instanceof EntityMappingInterface) { |
50
|
7 |
|
$fieldMappings = array_merge($fieldMappings, $driverMapping->getFieldMappings()); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
8 |
|
if (!empty($fieldMappings)) { |
55
|
7 |
|
$mapping = new EntityMapping($className, $fieldMappings); |
56
|
|
|
} |
57
|
|
|
|
58
|
8 |
|
return $mapping; |
59
|
|
|
} |
60
|
|
|
|
61
|
8 |
|
private function addInnerMetadataDriver(MappingDriverInterface $innerDriver): void |
62
|
|
|
{ |
63
|
8 |
|
$this->innerDrivers[] = $innerDriver; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|