1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
8
|
|
|
use Doctrine\ORM\Reflection\ReflectionService; |
9
|
|
|
use Doctrine\ORM\Sequencing\Planning\AssociationValueGeneratorExecutor; |
10
|
|
|
use Doctrine\ORM\Sequencing\Planning\ValueGenerationExecutor; |
11
|
|
|
use ReflectionProperty; |
12
|
|
|
|
13
|
|
|
class AssociationMetadata implements Property |
14
|
|
|
{ |
15
|
|
|
/** @var ClassMetadata */ |
16
|
|
|
private $declaringClass; |
17
|
|
|
|
18
|
|
|
/** @var ReflectionProperty */ |
19
|
|
|
private $reflection; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
private $name; |
23
|
|
|
|
24
|
|
|
/** @var bool */ |
25
|
|
|
protected $primaryKey = false; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
private $fetchMode = FetchMode::LAZY; |
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
private $targetEntity; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
private $sourceEntity; |
35
|
|
|
|
36
|
|
|
/** @var string|null */ |
37
|
|
|
private $mappedBy; |
38
|
|
|
|
39
|
|
|
/** @var string|null */ |
40
|
|
|
private $inversedBy; |
41
|
|
|
|
42
|
|
|
/** @var string[] */ |
43
|
|
|
private $cascade = []; |
44
|
|
|
|
45
|
|
|
/** @var bool */ |
46
|
|
|
private $owningSide = true; |
47
|
|
|
|
48
|
|
|
/** @var bool */ |
49
|
|
|
private $orphanRemoval = false; |
50
|
|
|
|
51
|
|
|
/** @var CacheMetadata|null */ |
52
|
|
|
private $cache; |
53
|
|
|
|
54
|
324 |
|
public function __construct(string $name) |
55
|
|
|
{ |
56
|
324 |
|
$this->name = $name; |
57
|
324 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
625 |
|
public function getDeclaringClass() : ComponentMetadata |
63
|
|
|
{ |
64
|
625 |
|
return $this->declaringClass; |
65
|
|
|
} |
66
|
|
|
|
67
|
292 |
|
public function setDeclaringClass(ComponentMetadata $declaringClass) : void |
68
|
|
|
{ |
69
|
292 |
|
$this->declaringClass = $declaringClass; |
|
|
|
|
70
|
292 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
727 |
|
public function getName() : string |
76
|
|
|
{ |
77
|
727 |
|
return $this->name; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function setName($name) : void |
84
|
|
|
{ |
85
|
|
|
$this->name = $name; |
86
|
|
|
} |
87
|
|
|
|
88
|
47 |
|
public function setPrimaryKey(bool $isPrimaryKey) : void |
89
|
|
|
{ |
90
|
47 |
|
$this->primaryKey = $isPrimaryKey; |
91
|
47 |
|
} |
92
|
|
|
|
93
|
986 |
|
public function isPrimaryKey() : bool |
94
|
|
|
{ |
95
|
986 |
|
return $this->primaryKey; |
96
|
|
|
} |
97
|
|
|
|
98
|
1337 |
|
public function getTargetEntity() : string |
99
|
|
|
{ |
100
|
1337 |
|
return $this->targetEntity; |
101
|
|
|
} |
102
|
|
|
|
103
|
293 |
|
public function setTargetEntity(string $targetEntity) : void |
104
|
|
|
{ |
105
|
293 |
|
$this->targetEntity = $targetEntity; |
106
|
293 |
|
} |
107
|
|
|
|
108
|
831 |
|
public function getSourceEntity() : string |
109
|
|
|
{ |
110
|
831 |
|
return $this->sourceEntity; |
111
|
|
|
} |
112
|
|
|
|
113
|
292 |
|
public function setSourceEntity(string $sourceEntity) : void |
114
|
|
|
{ |
115
|
292 |
|
$this->sourceEntity = $sourceEntity; |
116
|
292 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return string[] |
120
|
|
|
*/ |
121
|
1066 |
|
public function getCascade() : array |
122
|
|
|
{ |
123
|
1066 |
|
return $this->cascade; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param string[] $cascade |
128
|
|
|
*/ |
129
|
289 |
|
public function setCascade(array $cascade) : void |
130
|
|
|
{ |
131
|
289 |
|
$this->cascade = $cascade; |
132
|
289 |
|
} |
133
|
|
|
|
134
|
158 |
|
public function setOwningSide(bool $owningSide) : void |
135
|
|
|
{ |
136
|
158 |
|
$this->owningSide = $owningSide; |
137
|
158 |
|
} |
138
|
|
|
|
139
|
1308 |
|
public function isOwningSide() : bool |
140
|
|
|
{ |
141
|
1308 |
|
return $this->owningSide; |
142
|
|
|
} |
143
|
|
|
|
144
|
580 |
|
public function getFetchMode() : string |
145
|
|
|
{ |
146
|
580 |
|
return $this->fetchMode; |
147
|
|
|
} |
148
|
|
|
|
149
|
360 |
|
public function setFetchMode(string $fetchMode) : void |
150
|
|
|
{ |
151
|
360 |
|
$this->fetchMode = $fetchMode; |
152
|
360 |
|
} |
153
|
|
|
|
154
|
1015 |
|
public function getMappedBy() : ?string |
155
|
|
|
{ |
156
|
1015 |
|
return $this->mappedBy; |
157
|
|
|
} |
158
|
|
|
|
159
|
163 |
|
public function setMappedBy(string $mappedBy) : void |
160
|
|
|
{ |
161
|
163 |
|
$this->mappedBy = $mappedBy; |
162
|
163 |
|
} |
163
|
|
|
|
164
|
969 |
|
public function getInversedBy() : ?string |
165
|
|
|
{ |
166
|
969 |
|
return $this->inversedBy; |
167
|
|
|
} |
168
|
|
|
|
169
|
162 |
|
public function setInversedBy(?string $inversedBy = null) : void |
170
|
|
|
{ |
171
|
162 |
|
$this->inversedBy = $inversedBy; |
172
|
162 |
|
} |
173
|
|
|
|
174
|
218 |
|
public function setOrphanRemoval(bool $orphanRemoval) : void |
175
|
|
|
{ |
176
|
218 |
|
$this->orphanRemoval = $orphanRemoval; |
177
|
218 |
|
} |
178
|
|
|
|
179
|
314 |
|
public function isOrphanRemoval() : bool |
180
|
|
|
{ |
181
|
314 |
|
return $this->orphanRemoval; |
182
|
|
|
} |
183
|
|
|
|
184
|
595 |
|
public function getCache() : ?CacheMetadata |
185
|
|
|
{ |
186
|
595 |
|
return $this->cache; |
187
|
|
|
} |
188
|
|
|
|
189
|
66 |
|
public function setCache(?CacheMetadata $cache = null) : void |
190
|
|
|
{ |
191
|
66 |
|
$this->cache = $cache; |
192
|
66 |
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* {@inheritdoc} |
196
|
|
|
*/ |
197
|
887 |
|
public function setValue($object, $value) : void |
198
|
|
|
{ |
199
|
887 |
|
$this->reflection->setValue($object, $value); |
200
|
887 |
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* {@inheritdoc} |
204
|
|
|
*/ |
205
|
929 |
|
public function getValue($object) |
206
|
|
|
{ |
207
|
929 |
|
return $this->reflection->getValue($object); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* {@inheritdoc} |
212
|
|
|
*/ |
213
|
|
|
public function isAssociation() : bool |
214
|
|
|
{ |
215
|
|
|
return true; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* {@inheritdoc} |
220
|
|
|
*/ |
221
|
|
|
public function isField() : bool |
222
|
|
|
{ |
223
|
|
|
return false; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* {@inheritdoc} |
228
|
|
|
*/ |
229
|
1694 |
|
public function setReflectionProperty(ReflectionProperty $reflectionProperty) : void |
230
|
|
|
{ |
231
|
1694 |
|
$this->reflection = $reflectionProperty; |
232
|
1694 |
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* {@inheritdoc} |
236
|
|
|
*/ |
237
|
1446 |
|
public function wakeupReflection(ReflectionService $reflectionService) : void |
238
|
|
|
{ |
239
|
1446 |
|
$this->setReflectionProperty( |
240
|
1446 |
|
$reflectionService->getAccessibleProperty($this->declaringClass->getClassName(), $this->name) |
|
|
|
|
241
|
|
|
); |
242
|
1446 |
|
} |
243
|
|
|
|
244
|
250 |
|
public function getValueGenerationExecutor(AbstractPlatform $platform) : ?ValueGenerationExecutor |
245
|
|
|
{ |
246
|
250 |
|
return $this->isPrimaryKey() /* It is impossible to have a ToManyAssociation while being primary! */ |
247
|
41 |
|
? new AssociationValueGeneratorExecutor() |
248
|
250 |
|
: null; |
249
|
|
|
} |
250
|
|
|
|
251
|
52 |
|
public function __clone() |
252
|
|
|
{ |
253
|
52 |
|
if ($this->cache) { |
254
|
12 |
|
$this->cache = clone $this->cache; |
255
|
|
|
} |
256
|
52 |
|
} |
257
|
|
|
} |
258
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.