|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class EntityClassMetadata |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
abstract class EntityClassMetadata extends ComponentMetadata |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var string The name of the Entity */ |
|
14
|
|
|
protected $entityName; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string|null The name of the custom repository class used for the entity class. |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $customRepositoryClassName; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Property|null The field which is used for versioning in optimistic locking (if any). |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $declaredVersion; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Whether this class describes the mapping of a read-only class. |
|
28
|
|
|
* That means it is never considered for change-tracking in the UnitOfWork. |
|
29
|
|
|
* It is a very helpful performance optimization for entities that are immutable, |
|
30
|
|
|
* either in your domain or through the relation database (coming from a view, |
|
31
|
|
|
* or a history table for example). |
|
32
|
|
|
* |
|
33
|
|
|
* @var bool |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $readOnly = false; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* List of all sub-classes (descendants) metadata. |
|
39
|
|
|
* |
|
40
|
|
|
* @var SubClassMetadata[] |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $subClasses = []; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* READ-ONLY: The named native queries allowed to be called directly from Repository. |
|
46
|
|
|
* |
|
47
|
|
|
* A native SQL named query definition has the following structure: |
|
48
|
|
|
* <pre> |
|
49
|
|
|
* array( |
|
50
|
|
|
* 'name' => <query name>, |
|
51
|
|
|
* 'query' => <sql query>, |
|
52
|
|
|
* 'resultClass' => <class of the result>, |
|
53
|
|
|
* 'resultSetMapping' => <name of a SqlResultSetMapping> |
|
54
|
|
|
* ) |
|
55
|
|
|
* </pre> |
|
56
|
|
|
* |
|
57
|
|
|
* @var string[][] |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $namedNativeQueries = []; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* READ-ONLY: The mappings of the results of native SQL queries. |
|
63
|
|
|
* |
|
64
|
|
|
* A native result mapping definition has the following structure: |
|
65
|
|
|
* <pre> |
|
66
|
|
|
* array( |
|
67
|
|
|
* 'name' => <result name>, |
|
68
|
|
|
* 'entities' => array(<entity result mapping>), |
|
69
|
|
|
* 'columns' => array(<column result mapping>) |
|
70
|
|
|
* ) |
|
71
|
|
|
* </pre> |
|
72
|
|
|
* |
|
73
|
|
|
* @var mixed[][] |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $sqlResultSetMappings = []; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* READ-ONLY: The registered lifecycle callbacks for entities of this class. |
|
79
|
|
|
* |
|
80
|
|
|
* @var string[][] |
|
81
|
|
|
*/ |
|
82
|
|
|
protected $lifecycleCallbacks = []; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* READ-ONLY: The registered entity listeners. |
|
86
|
|
|
* |
|
87
|
|
|
* @var string[][] |
|
88
|
|
|
*/ |
|
89
|
|
|
protected $entityListeners = []; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* READ-ONLY: The field names of all fields that are part of the identifier/primary key |
|
93
|
|
|
* of the mapped entity class. |
|
94
|
|
|
* |
|
95
|
|
|
* @var string[] |
|
96
|
|
|
*/ |
|
97
|
|
|
protected $identifier = []; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* READ-ONLY: The primary table metadata. |
|
101
|
|
|
* |
|
102
|
|
|
* @var TableMetadata |
|
103
|
|
|
*/ |
|
104
|
|
|
protected $table; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* MappedSuperClassMetadata constructor. |
|
108
|
|
|
*/ |
|
109
|
|
|
public function __construct(string $className, ClassMetadataBuildingContext $metadataBuildingContext) |
|
110
|
|
|
{ |
|
111
|
|
|
parent::__construct($className); |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
$this->entityName = $className; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function getEntityName() : string |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->entityName; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function setEntityName(string $entityName) : void |
|
122
|
|
|
{ |
|
123
|
|
|
$this->entityName = $entityName; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function getCustomRepositoryClassName() : ?string |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->customRepositoryClassName; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function setCustomRepositoryClassName(?string $customRepositoryClassName) : void |
|
132
|
|
|
{ |
|
133
|
|
|
$this->customRepositoryClassName = $customRepositoryClassName; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function getDeclaredVersion() : ?Property |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->declaredVersion; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function setDeclaredVersion(Property $property) : void |
|
142
|
|
|
{ |
|
143
|
|
|
$this->declaredVersion = $property; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getVersion() : ?Property |
|
147
|
|
|
{ |
|
148
|
|
|
/** @var ComponentMetadata|null $parent */ |
|
149
|
|
|
$parent = $this->parent; |
|
150
|
|
|
$version = $this->declaredVersion; |
|
151
|
|
|
|
|
152
|
|
|
if ($parent && ! $version) { |
|
153
|
|
|
$version = $parent->getVersion(); |
|
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
return $version; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function isVersioned() : bool |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->getVersion() !== null; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function setReadOnly(bool $readOnly) : void |
|
165
|
|
|
{ |
|
166
|
|
|
$this->readOnly = $readOnly; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function isReadOnly() : bool |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->readOnly; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* |
|
176
|
|
|
* @throws MappingException |
|
177
|
|
|
*/ |
|
178
|
|
|
public function addSubClass(SubClassMetadata $subClassMetadata) : void |
|
179
|
|
|
{ |
|
180
|
|
|
$superClassMetadata = $this->getSuperClass(); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
while ($superClassMetadata !== null) { |
|
183
|
|
|
if ($superClassMetadata->entityName === $subClassMetadata->entityName) { |
|
184
|
|
|
throw new MappingException( |
|
185
|
|
|
sprintf( |
|
186
|
|
|
'Circular inheritance mapping detected: "%s" have itself as superclass when extending "%s".', |
|
187
|
|
|
$subClassMetadata->entityName, |
|
188
|
|
|
$superClassMetadata->entityName |
|
189
|
|
|
) |
|
190
|
|
|
); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
$superClassMetadata->subClasses[] = $subClassMetadata; |
|
194
|
|
|
|
|
195
|
|
|
$superClassMetadata = $superClassMetadata->parent; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
$this->subClasses[] = $subClassMetadata; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function hasSubClasses() : bool |
|
202
|
|
|
{ |
|
203
|
|
|
return (bool) $this->subClasses; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function getSubClassIterator() : \Iterator |
|
207
|
|
|
{ |
|
208
|
|
|
$iterator = new \AppendIterator(); |
|
209
|
|
|
|
|
210
|
|
|
foreach ($this->subClasses as $subClassMetadata) { |
|
211
|
|
|
$iterator->append($subClassMetadata->getSubClassIterator()); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
$iterator->append(new \ArrayIterator($this->subClasses)); |
|
215
|
|
|
|
|
216
|
|
|
return $iterator; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Gets a named native query. |
|
221
|
|
|
* |
|
222
|
|
|
* @param string $queryName The native query name. |
|
223
|
|
|
* |
|
224
|
|
|
* @return string[] |
|
225
|
|
|
* |
|
226
|
|
|
* @throws MappingException |
|
227
|
|
|
* |
|
228
|
|
|
* @todo guilhermeblanco This should return an object instead |
|
229
|
|
|
*/ |
|
230
|
|
|
public function getNamedNativeQuery($queryName) : array |
|
231
|
|
|
{ |
|
232
|
|
|
if (! isset($this->namedNativeQueries[$queryName])) { |
|
233
|
|
|
throw MappingException::queryNotFound($this->entityName, $queryName); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
return $this->namedNativeQueries[$queryName]; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Gets all named native queries of the class. |
|
241
|
|
|
* |
|
242
|
|
|
* @return string[][] |
|
243
|
|
|
*/ |
|
244
|
|
|
public function getNamedNativeQueries() : array |
|
245
|
|
|
{ |
|
246
|
|
|
return $this->namedNativeQueries; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Gets the result set mapping. |
|
251
|
|
|
* |
|
252
|
|
|
* @param string $name The result set mapping name. |
|
253
|
|
|
* |
|
254
|
|
|
* @return mixed[] |
|
255
|
|
|
* |
|
256
|
|
|
* @throws MappingException |
|
257
|
|
|
* |
|
258
|
|
|
* @todo guilhermeblanco This should return an object instead |
|
259
|
|
|
*/ |
|
260
|
|
|
public function getSqlResultSetMapping($name) : array |
|
261
|
|
|
{ |
|
262
|
|
|
if (! isset($this->sqlResultSetMappings[$name])) { |
|
263
|
|
|
throw MappingException::resultMappingNotFound($this->entityName, $name); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
return $this->sqlResultSetMappings[$name]; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Gets all sql result set mappings of the class. |
|
271
|
|
|
* |
|
272
|
|
|
* @return mixed[][] |
|
273
|
|
|
*/ |
|
274
|
|
|
public function getSqlResultSetMappings() : array |
|
275
|
|
|
{ |
|
276
|
|
|
return $this->sqlResultSetMappings; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* {@inheritdoc} |
|
281
|
|
|
*/ |
|
282
|
|
|
public function addDeclaredProperty(Property $property) : void |
|
283
|
|
|
{ |
|
284
|
|
|
parent::addDeclaredProperty($property); |
|
285
|
|
|
|
|
286
|
|
|
if ($property instanceof VersionFieldMetadata) { |
|
287
|
|
|
$this->setDeclaredVersion($property); |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
abstract public function getRootClass() : RootClassMetadata; |
|
292
|
|
|
} |
|
293
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.