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\DriverFactories; |
12
|
|
|
|
13
|
|
|
use Doctrine\Persistence\Mapping\Driver\MappingDriver; |
14
|
|
|
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; |
15
|
|
|
use Addiks\RDMBundle\Mapping\DriverFactories\MappingDriverFactoryInterface; |
16
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface; |
17
|
|
|
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverChain as RDMMappingDriverChain; |
18
|
|
|
|
19
|
|
|
final class MappingDriverChainFactory implements MappingDriverFactoryInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var MappingDriverFactoryInterface |
24
|
|
|
*/ |
25
|
|
|
private $rootMetadataDriverFactory; |
26
|
|
|
|
27
|
7 |
|
public function __construct(MappingDriverFactoryInterface $rootMetadataDriverFactory) |
28
|
|
|
{ |
29
|
7 |
|
$this->rootMetadataDriverFactory = $rootMetadataDriverFactory; |
30
|
|
|
} |
31
|
|
|
|
32
|
7 |
|
public function createRDMMappingDriver( |
33
|
|
|
MappingDriver $mappingDriver |
34
|
|
|
): ?MappingDriverInterface { |
35
|
|
|
/** @var ?MappingDriverInterface $rdmMetadataDriver */ |
36
|
7 |
|
$rdmMetadataDriver = null; |
37
|
|
|
|
38
|
7 |
|
if ($mappingDriver instanceof MappingDriverChain) { |
39
|
|
|
/** @var MappingDriverChain $mappingDriverChain */ |
40
|
7 |
|
$mappingDriverChain = $mappingDriver; |
41
|
|
|
|
42
|
|
|
/** @var array<MappingDriverFactoryInterface> $subRDMMetadataDrivers */ |
43
|
7 |
|
$subRDMMetadataDrivers = array(); |
44
|
|
|
|
45
|
7 |
|
foreach ($mappingDriverChain->getDrivers() as $subMappingDriver) { |
46
|
|
|
/** @var MappingDriver $subMappingDriver */ |
47
|
|
|
|
48
|
7 |
|
$subRDMMetadataDriver = $this->rootMetadataDriverFactory->createRDMMappingDriver( |
49
|
|
|
$subMappingDriver |
50
|
|
|
); |
51
|
|
|
|
52
|
7 |
|
if ($subRDMMetadataDriver instanceof MappingDriverInterface) { |
53
|
7 |
|
$subRDMMetadataDrivers[] = $subRDMMetadataDriver; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
7 |
|
$rdmMetadataDriver = new RDMMappingDriverChain($subRDMMetadataDrivers); |
58
|
|
|
} |
59
|
|
|
|
60
|
7 |
|
return $rdmMetadataDriver; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|