1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015 Fabian Grutschus. All rights reserved. |
5
|
|
|
* |
6
|
|
|
* Redistribution and use in source and binary forms, with or without modification, |
7
|
|
|
* are permitted provided that the following conditions are met: |
8
|
|
|
* |
9
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this |
10
|
|
|
* list of conditions and the following disclaimer. |
11
|
|
|
* |
12
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, |
13
|
|
|
* this list of conditions and the following disclaimer in the documentation |
14
|
|
|
* and/or other materials provided with the distribution. |
15
|
|
|
* |
16
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
20
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26
|
|
|
* |
27
|
|
|
* The views and conclusions contained in the software and documentation are those |
28
|
|
|
* of the authors and should not be interpreted as representing official policies, |
29
|
|
|
* either expressed or implied, of the copyright holders. |
30
|
|
|
* |
31
|
|
|
* @author Fabian Grutschus <[email protected]> |
32
|
|
|
* @copyright 2015 Fabian Grutschus. All rights reserved. |
33
|
|
|
* @license BSD-2-Clause |
34
|
|
|
*/ |
35
|
|
|
|
36
|
|
|
namespace Fabiang\DoctrineDynamic\Mapper; |
37
|
|
|
|
38
|
|
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata; |
39
|
|
|
use Fabiang\DoctrineDynamic\Configuration\Entity as EntityConfiguration; |
40
|
|
|
|
41
|
|
|
class MetadataMapper implements Mapper |
42
|
|
|
{ |
43
|
|
|
|
44
|
1 |
|
public function map(ClassMetadata $metadata, EntityConfiguration $configuration) |
45
|
|
|
{ |
46
|
1 |
|
if ($configuration->getRepository()) { |
47
|
1 |
|
$metadata->customRepositoryClassName = $configuration->getRepository(); |
|
|
|
|
48
|
1 |
|
} |
49
|
|
|
|
50
|
1 |
|
foreach ($configuration->getFields() as $field) { |
51
|
1 |
View Code Duplication |
foreach ($field->getOneToOne() as $oneToOne) { |
|
|
|
|
52
|
|
|
$oneToOneConfig = [ |
53
|
1 |
|
'fieldName' => $field->getName(), |
54
|
1 |
|
'targetEntity' => $oneToOne->getTargetEntity(), |
55
|
1 |
|
'inversedBy' => $oneToOne->getInversedBy(), |
56
|
1 |
|
'mappedBy' => $oneToOne->getMappedBy(), |
57
|
1 |
|
]; |
58
|
|
|
|
59
|
1 |
|
$joinColumn = $oneToOne->getJoinColumn(); |
60
|
1 |
|
if (null !== $joinColumn) { |
61
|
1 |
|
$oneToOneConfig['joinColumns'] = [ |
62
|
|
|
[ |
63
|
1 |
|
'name' => $joinColumn->getName(), |
64
|
1 |
|
'referencedColumnName' => $joinColumn->getReferencedColumnName(), |
65
|
|
|
] |
66
|
1 |
|
]; |
67
|
1 |
|
} |
68
|
|
|
|
69
|
1 |
|
$metadata->mapOneToOne($oneToOneConfig); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
View Code Duplication |
foreach ($field->getManyToOne() as $manyToOne) { |
|
|
|
|
73
|
|
|
$manyToOneConfig = [ |
74
|
1 |
|
'fieldName' => $field->getName(), |
75
|
1 |
|
'targetEntity' => $manyToOne->getTargetEntity(), |
76
|
1 |
|
'inversedBy' => $manyToOne->getInversedBy(), |
77
|
1 |
|
]; |
78
|
|
|
|
79
|
1 |
|
$joinColumn = $manyToOne->getJoinColumn(); |
80
|
1 |
|
if (null !== $joinColumn) { |
81
|
1 |
|
$manyToOneConfig['joinColumns'] = [ |
82
|
|
|
[ |
83
|
1 |
|
'name' => $joinColumn->getName(), |
84
|
1 |
|
'referencedColumnName' => $joinColumn->getReferencedColumnName(), |
85
|
|
|
] |
86
|
1 |
|
]; |
87
|
1 |
|
} |
88
|
|
|
|
89
|
1 |
|
$metadata->mapManyToOne($manyToOneConfig); |
90
|
1 |
|
} |
91
|
|
|
|
92
|
1 |
|
foreach ($field->getOneToMany() as $oneToMany) { |
93
|
|
|
$oneToMany = [ |
94
|
1 |
|
'fieldName' => $field->getName(), |
95
|
1 |
|
'targetEntity' => $oneToMany->getTargetEntity(), |
96
|
1 |
|
'mappedBy' => $oneToMany->getMappedBy(), |
97
|
1 |
|
]; |
98
|
|
|
|
99
|
1 |
|
$metadata->mapOneToMany($oneToMany); |
100
|
1 |
|
} |
101
|
|
|
|
102
|
1 |
View Code Duplication |
foreach ($field->getManyToMany() as $manyToMany) { |
|
|
|
|
103
|
|
|
$manyToManyConfig = [ |
104
|
1 |
|
'fieldName' => $field->getName(), |
105
|
1 |
|
'targetEntity' => $manyToMany->getTargetEntity(), |
106
|
1 |
|
'inversedBy' => $manyToMany->getInversedBy(), |
107
|
1 |
|
'mappedBy' => $manyToMany->getMappedBy(), |
108
|
1 |
|
]; |
109
|
|
|
|
110
|
1 |
|
$joinTable = $manyToMany->getJoinTable(); |
111
|
1 |
|
if (null !== $joinTable) { |
112
|
1 |
|
$manyToManyConfig['joinTable'] = [ |
113
|
1 |
|
'name' => $joinTable->getName(), |
114
|
|
|
]; |
115
|
1 |
|
} |
116
|
|
|
|
117
|
1 |
|
$metadata->mapManyToMany($manyToManyConfig); |
118
|
1 |
|
} |
119
|
1 |
|
} |
120
|
1 |
|
} |
121
|
|
|
} |
122
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: