|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Mapping\Driver; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
8
|
|
|
use Doctrine\DBAL\Types\Type; |
|
9
|
|
|
use Doctrine\ORM\Annotation; |
|
10
|
|
|
use Doctrine\ORM\Events; |
|
11
|
|
|
use Doctrine\ORM\Mapping; |
|
12
|
|
|
use Doctrine\ORM\Mapping\Builder; |
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
use ReflectionClass; |
|
|
|
|
|
|
15
|
|
|
use ReflectionMethod; |
|
|
|
|
|
|
16
|
|
|
use SimpleXMLElement; |
|
17
|
|
|
use function array_filter; |
|
|
|
|
|
|
18
|
|
|
use function class_exists; |
|
19
|
|
|
use function constant; |
|
20
|
|
|
use function explode; |
|
21
|
|
|
use function file_get_contents; |
|
22
|
|
|
use function get_class; |
|
23
|
|
|
use function in_array; |
|
24
|
|
|
use function simplexml_load_string; |
|
25
|
|
|
use function sprintf; |
|
26
|
|
|
use function str_replace; |
|
27
|
|
|
use function strtolower; |
|
|
|
|
|
|
28
|
|
|
use function strtoupper; |
|
29
|
|
|
use function var_export; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* XmlDriver is a metadata driver that enables mapping through XML files. |
|
33
|
|
|
*/ |
|
34
|
|
|
class XmlDriver extends FileDriver |
|
35
|
|
|
{ |
|
36
|
|
|
public const DEFAULT_FILE_EXTENSION = '.dcm.xml'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritDoc} |
|
40
|
|
|
*/ |
|
41
|
41 |
|
public function __construct($locator, $fileExtension = self::DEFAULT_FILE_EXTENSION) |
|
42
|
|
|
{ |
|
43
|
41 |
|
parent::__construct($locator, $fileExtension); |
|
44
|
41 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritDoc} |
|
48
|
|
|
*/ |
|
49
|
36 |
|
public function loadMetadataForClass( |
|
50
|
|
|
string $className, |
|
51
|
|
|
?Mapping\ComponentMetadata $parent, |
|
52
|
|
|
Mapping\ClassMetadataBuildingContext $metadataBuildingContext |
|
53
|
|
|
): Mapping\ComponentMetadata |
|
|
|
|
|
|
54
|
|
|
{ |
|
|
|
|
|
|
55
|
36 |
|
$metadata = new Mapping\ClassMetadata($className, $parent, $metadataBuildingContext); |
|
56
|
|
|
|
|
57
|
|
|
/** @var SimpleXMLElement $xmlRoot */ |
|
58
|
36 |
|
$xmlRoot = $this->getElement($className); |
|
59
|
|
|
|
|
60
|
34 |
|
if ($xmlRoot->getName() === 'entity') { |
|
61
|
34 |
|
if (isset($xmlRoot['repository-class'])) { |
|
62
|
|
|
$metadata->setCustomRepositoryClassName((string)$xmlRoot['repository-class']); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
34 |
|
if (isset($xmlRoot['read-only']) && $this->evaluateBoolean($xmlRoot['read-only'])) { |
|
66
|
34 |
|
$metadata->asReadOnly(); |
|
67
|
|
|
} |
|
68
|
5 |
|
} elseif ($xmlRoot->getName() === 'mapped-superclass') { |
|
69
|
5 |
|
if (isset($xmlRoot['repository-class'])) { |
|
70
|
1 |
|
$metadata->setCustomRepositoryClassName((string)$xmlRoot['repository-class']); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
5 |
|
$metadata->isMappedSuperclass = true; |
|
74
|
|
|
} elseif ($xmlRoot->getName() === 'embeddable') { |
|
75
|
|
|
$metadata->isEmbeddedClass = true; |
|
76
|
|
|
} else { |
|
77
|
|
|
throw Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass($className); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// Process table information |
|
81
|
34 |
|
$parent = $metadata->getParent(); |
|
82
|
|
|
|
|
83
|
34 |
|
if ($parent && $parent->inheritanceType === Mapping\InheritanceType::SINGLE_TABLE) { |
|
84
|
2 |
|
$metadata->setTable($parent->table); |
|
85
|
|
|
} else { |
|
86
|
34 |
|
$namingStrategy = $metadataBuildingContext->getNamingStrategy(); |
|
87
|
34 |
|
$tableMetadata = new Mapping\TableMetadata(); |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
34 |
|
$tableMetadata->setName($namingStrategy->classToTableName($metadata->getClassName())); |
|
90
|
|
|
|
|
91
|
|
|
// Evaluate <entity...> attributes |
|
92
|
34 |
|
if (isset($xmlRoot['table'])) { |
|
93
|
12 |
|
$tableMetadata->setName((string)$xmlRoot['table']); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
34 |
|
if (isset($xmlRoot['schema'])) { |
|
97
|
2 |
|
$tableMetadata->setSchema((string)$xmlRoot['schema']); |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
34 |
|
if (isset($xmlRoot->options)) { |
|
101
|
3 |
|
$options = $this->parseOptions($xmlRoot->options->children()); |
|
102
|
|
|
|
|
103
|
3 |
|
foreach ($options as $optionName => $optionValue) { |
|
104
|
3 |
|
$tableMetadata->addOption($optionName, $optionValue); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
// Evaluate <indexes...> |
|
109
|
34 |
|
if (isset($xmlRoot->indexes)) { |
|
110
|
4 |
|
foreach ($xmlRoot->indexes->index as $indexXml) { |
|
111
|
4 |
|
$indexName = isset($indexXml['name']) ? (string)$indexXml['name'] : null; |
|
|
|
|
|
|
112
|
4 |
|
$columns = explode(',', (string)$indexXml['columns']); |
|
|
|
|
|
|
113
|
4 |
|
$isUnique = isset($indexXml['unique']) && $indexXml['unique']; |
|
|
|
|
|
|
114
|
4 |
|
$options = isset($indexXml->options) ? $this->parseOptions($indexXml->options->children()) : []; |
|
|
|
|
|
|
115
|
4 |
|
$flags = isset($indexXml['flags']) ? explode(',', (string)$indexXml['flags']) : []; |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
4 |
|
$tableMetadata->addIndex([ |
|
118
|
4 |
|
'name' => $indexName, |
|
119
|
4 |
|
'columns' => $columns, |
|
120
|
4 |
|
'unique' => $isUnique, |
|
121
|
4 |
|
'options' => $options, |
|
122
|
4 |
|
'flags' => $flags, |
|
123
|
|
|
]); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
// Evaluate <unique-constraints..> |
|
128
|
|
|
|
|
129
|
34 |
|
if (isset($xmlRoot->{'unique-constraints'})) { |
|
130
|
3 |
|
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $uniqueXml) { |
|
131
|
3 |
|
$indexName = isset($uniqueXml['name']) ? (string)$uniqueXml['name'] : null; |
|
|
|
|
|
|
132
|
3 |
|
$columns = explode(',', (string)$uniqueXml['columns']); |
|
|
|
|
|
|
133
|
3 |
|
$options = isset($uniqueXml->options) ? $this->parseOptions($uniqueXml->options->children()) : []; |
|
|
|
|
|
|
134
|
3 |
|
$flags = isset($uniqueXml['flags']) ? explode(',', (string)$uniqueXml['flags']) : []; |
|
|
|
|
|
|
135
|
|
|
|
|
136
|
3 |
|
$tableMetadata->addUniqueConstraint([ |
|
137
|
3 |
|
'name' => $indexName, |
|
138
|
3 |
|
'columns' => $columns, |
|
139
|
3 |
|
'options' => $options, |
|
140
|
3 |
|
'flags' => $flags, |
|
141
|
|
|
]); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
34 |
|
$metadata->setTable($tableMetadata); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
// Evaluate second level cache |
|
149
|
34 |
|
if (isset($xmlRoot->cache)) { |
|
150
|
2 |
|
$cacheBuilder = new Builder\CacheMetadataBuilder($metadataBuildingContext); |
|
151
|
|
|
|
|
152
|
|
|
$cacheBuilder |
|
153
|
2 |
|
->withEntityClassMetadata($metadata) |
|
154
|
2 |
|
->withCacheAnnotation($this->convertCacheElementToCacheAnnotation($xmlRoot->cache)); |
|
155
|
|
|
|
|
156
|
2 |
|
$metadata->setCache($cacheBuilder->build()); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
34 |
|
if (isset($xmlRoot['inheritance-type'])) { |
|
160
|
10 |
|
$inheritanceType = strtoupper((string)$xmlRoot['inheritance-type']); |
|
|
|
|
|
|
161
|
|
|
|
|
162
|
10 |
|
$metadata->setInheritanceType( |
|
163
|
10 |
|
constant(sprintf('%s::%s', Mapping\InheritanceType::class, $inheritanceType)) |
|
164
|
|
|
); |
|
165
|
|
|
|
|
166
|
10 |
|
if ($metadata->inheritanceType !== Mapping\InheritanceType::NONE) { |
|
167
|
10 |
|
$discriminatorColumn = new Mapping\DiscriminatorColumnMetadata(); |
|
168
|
|
|
|
|
169
|
10 |
|
$discriminatorColumn->setTableName($metadata->getTableName()); |
|
170
|
10 |
|
$discriminatorColumn->setColumnName('dtype'); |
|
171
|
10 |
|
$discriminatorColumn->setType(Type::getType('string')); |
|
172
|
10 |
|
$discriminatorColumn->setLength(255); |
|
173
|
|
|
|
|
174
|
|
|
// Evaluate <discriminator-column...> |
|
175
|
10 |
|
if (isset($xmlRoot->{'discriminator-column'})) { |
|
176
|
8 |
|
$discriminatorColumnMapping = $xmlRoot->{'discriminator-column'}; |
|
177
|
8 |
|
$typeName = (string)($discriminatorColumnMapping['type'] ?? 'string'); |
|
|
|
|
|
|
178
|
|
|
|
|
179
|
8 |
|
$discriminatorColumn->setType(Type::getType($typeName)); |
|
180
|
8 |
|
$discriminatorColumn->setColumnName((string)$discriminatorColumnMapping['name']); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
8 |
|
if (isset($discriminatorColumnMapping['column-definition'])) { |
|
183
|
1 |
|
$discriminatorColumn->setColumnDefinition((string)$discriminatorColumnMapping['column-definition']); |
|
|
|
|
|
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
8 |
|
if (isset($discriminatorColumnMapping['length'])) { |
|
187
|
3 |
|
$discriminatorColumn->setLength((int)$discriminatorColumnMapping['length']); |
|
|
|
|
|
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
10 |
|
$metadata->setDiscriminatorColumn($discriminatorColumn); |
|
192
|
|
|
|
|
193
|
|
|
// Evaluate <discriminator-map...> |
|
194
|
10 |
|
if (isset($xmlRoot->{'discriminator-map'})) { |
|
195
|
10 |
|
$map = []; |
|
196
|
|
|
|
|
197
|
10 |
|
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) { |
|
198
|
10 |
|
$map[(string)$discrMapElement['value']] = (string)$discrMapElement['class']; |
|
|
|
|
|
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
10 |
|
$metadata->setDiscriminatorMap($map); |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
// Evaluate <change-tracking-policy...> |
|
207
|
34 |
|
if (isset($xmlRoot['change-tracking-policy'])) { |
|
208
|
|
|
$changeTrackingPolicy = strtoupper((string)$xmlRoot['change-tracking-policy']); |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
$metadata->setChangeTrackingPolicy( |
|
211
|
|
|
constant(sprintf('%s::%s', Mapping\ChangeTrackingPolicy::class, $changeTrackingPolicy)) |
|
212
|
|
|
); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
// Evaluate <field ...> mappings |
|
216
|
34 |
|
if (isset($xmlRoot->field)) { |
|
217
|
20 |
|
foreach ($xmlRoot->field as $fieldElement) { |
|
218
|
20 |
|
$fieldName = (string)$fieldElement['name']; |
|
|
|
|
|
|
219
|
20 |
|
$fieldMetadata = $this->convertFieldElementToFieldMetadata($fieldElement, $fieldName, $metadata, $metadataBuildingContext); |
|
220
|
|
|
|
|
221
|
20 |
|
$metadata->addProperty($fieldMetadata); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
34 |
|
if (isset($xmlRoot->embedded)) { |
|
226
|
|
|
foreach ($xmlRoot->embedded as $embeddedMapping) { |
|
227
|
|
|
$columnPrefix = isset($embeddedMapping['column-prefix']) |
|
228
|
|
|
? (string)$embeddedMapping['column-prefix'] |
|
|
|
|
|
|
229
|
|
|
: null; |
|
230
|
|
|
|
|
231
|
|
|
$useColumnPrefix = isset($embeddedMapping['use-column-prefix']) |
|
232
|
|
|
? $this->evaluateBoolean($embeddedMapping['use-column-prefix']) |
|
233
|
|
|
: true; |
|
234
|
|
|
|
|
235
|
|
|
$mapping = [ |
|
236
|
|
|
'fieldName' => (string)$embeddedMapping['name'], |
|
|
|
|
|
|
237
|
|
|
'class' => (string)$embeddedMapping['class'], |
|
|
|
|
|
|
238
|
|
|
'columnPrefix' => $useColumnPrefix ? $columnPrefix : false, |
|
239
|
|
|
]; |
|
240
|
|
|
|
|
241
|
|
|
$metadata->mapEmbedded($mapping); |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
// Evaluate <id ...> mappings |
|
246
|
34 |
|
$associationIds = []; |
|
247
|
|
|
|
|
248
|
34 |
|
foreach ($xmlRoot->id as $idElement) { |
|
249
|
29 |
|
$fieldName = (string)$idElement['name']; |
|
|
|
|
|
|
250
|
|
|
|
|
251
|
29 |
|
if (isset($idElement['association-key']) && $this->evaluateBoolean($idElement['association-key'])) { |
|
252
|
2 |
|
$associationIds[$fieldName] = true; |
|
253
|
|
|
|
|
254
|
2 |
|
continue; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
28 |
|
$fieldMetadata = $this->convertFieldElementToFieldMetadata($idElement, $fieldName, $metadata, $metadataBuildingContext); |
|
258
|
|
|
|
|
259
|
28 |
|
$fieldMetadata->setPrimaryKey(true); |
|
260
|
|
|
|
|
261
|
|
|
// Prevent PK and version on same field |
|
262
|
28 |
|
if ($fieldMetadata->isVersioned()) { |
|
263
|
|
|
throw Mapping\MappingException::cannotVersionIdField($className, $fieldName); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
28 |
|
if (isset($idElement->generator)) { |
|
267
|
27 |
|
$strategy = (string)($idElement->generator['strategy'] ?? 'AUTO'); |
|
|
|
|
|
|
268
|
|
|
|
|
269
|
27 |
|
$idGeneratorType = constant(sprintf('%s::%s', Mapping\GeneratorType::class, strtoupper($strategy))); |
|
270
|
|
|
|
|
271
|
27 |
|
if ($idGeneratorType !== Mapping\GeneratorType::NONE) { |
|
272
|
20 |
|
$idGeneratorDefinition = []; |
|
273
|
|
|
|
|
274
|
|
|
// Check for SequenceGenerator/TableGenerator definition |
|
275
|
20 |
|
if (isset($idElement->{'sequence-generator'})) { |
|
276
|
3 |
|
$seqGenerator = $idElement->{'sequence-generator'}; |
|
|
|
|
|
|
277
|
|
|
$idGeneratorDefinition = [ |
|
278
|
3 |
|
'sequenceName' => (string)$seqGenerator['sequence-name'], |
|
|
|
|
|
|
279
|
3 |
|
'allocationSize' => (string)$seqGenerator['allocation-size'], |
|
|
|
|
|
|
280
|
|
|
]; |
|
281
|
17 |
|
} elseif (isset($idElement->{'custom-id-generator'})) { |
|
282
|
2 |
|
$customGenerator = $idElement->{'custom-id-generator'}; |
|
283
|
|
|
|
|
284
|
|
|
$idGeneratorDefinition = [ |
|
285
|
2 |
|
'class' => (string)$customGenerator['class'], |
|
|
|
|
|
|
286
|
|
|
'arguments' => [], |
|
287
|
|
|
]; |
|
288
|
|
|
|
|
289
|
2 |
|
if (!isset($idGeneratorDefinition['class'])) { |
|
|
|
|
|
|
290
|
|
|
throw new Mapping\MappingException( |
|
291
|
|
|
sprintf('Cannot instantiate custom generator, no class has been defined') |
|
292
|
|
|
); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
2 |
|
if (!class_exists($idGeneratorDefinition['class'])) { |
|
|
|
|
|
|
296
|
|
|
throw new Mapping\MappingException( |
|
297
|
2 |
|
sprintf('Cannot instantiate custom generator : %s', var_export($idGeneratorDefinition, true)) |
|
298
|
|
|
); |
|
299
|
|
|
} |
|
300
|
15 |
|
} elseif (isset($idElement->{'table-generator'})) { |
|
301
|
|
|
throw Mapping\MappingException::tableIdGeneratorNotImplemented($className); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
20 |
|
$fieldMetadata->setValueGenerator( |
|
305
|
20 |
|
new Mapping\ValueGeneratorMetadata($idGeneratorType, $idGeneratorDefinition) |
|
306
|
|
|
); |
|
307
|
|
|
} |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
28 |
|
$metadata->addProperty($fieldMetadata); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
// Evaluate <one-to-one ...> mappings |
|
314
|
34 |
|
if (isset($xmlRoot->{'one-to-one'})) { |
|
315
|
7 |
|
foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) { |
|
316
|
7 |
|
$association = new Mapping\OneToOneAssociationMetadata((string)$oneToOneElement['field']); |
|
|
|
|
|
|
317
|
7 |
|
$targetEntity = (string)$oneToOneElement['target-entity']; |
|
|
|
|
|
|
318
|
|
|
|
|
319
|
7 |
|
$association->setTargetEntity($targetEntity); |
|
320
|
|
|
|
|
321
|
7 |
|
if (isset($associationIds[$association->getName()])) { |
|
322
|
|
|
$association->setPrimaryKey(true); |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
7 |
|
if (isset($oneToOneElement['fetch'])) { |
|
326
|
3 |
|
$association->setFetchMode( |
|
327
|
3 |
|
constant(sprintf('%s::%s', Mapping\FetchMode::class, (string)$oneToOneElement['fetch'])) |
|
|
|
|
|
|
328
|
|
|
); |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
7 |
|
if (isset($oneToOneElement['mapped-by'])) { |
|
332
|
3 |
|
$association->setMappedBy((string)$oneToOneElement['mapped-by']); |
|
|
|
|
|
|
333
|
3 |
|
$association->setOwningSide(false); |
|
334
|
|
|
} else { |
|
335
|
5 |
|
if (isset($oneToOneElement['inversed-by'])) { |
|
336
|
4 |
|
$association->setInversedBy((string)$oneToOneElement['inversed-by']); |
|
|
|
|
|
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
5 |
|
$joinColumns = []; |
|
340
|
|
|
|
|
341
|
5 |
|
if (isset($oneToOneElement->{'join-column'})) { |
|
342
|
5 |
|
$joinColumns[] = $this->convertJoinColumnElementToJoinColumnMetadata($oneToOneElement->{'join-column'}); |
|
343
|
|
|
} elseif (isset($oneToOneElement->{'join-columns'})) { |
|
344
|
|
|
foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
345
|
|
|
$joinColumns[] = $this->convertJoinColumnElementToJoinColumnMetadata($joinColumnElement); |
|
346
|
|
|
} |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
5 |
|
$association->setJoinColumns($joinColumns); |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
7 |
|
if (isset($oneToOneElement->cascade)) { |
|
353
|
7 |
|
$association->setCascade($this->getCascadeMappings($oneToOneElement->cascade)); |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
7 |
|
if (isset($oneToOneElement['orphan-removal'])) { |
|
357
|
|
|
$association->setOrphanRemoval($this->evaluateBoolean($oneToOneElement['orphan-removal'])); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
// Evaluate second level cache |
|
361
|
7 |
|
if (isset($oneToOneElement->cache)) { |
|
362
|
|
|
$cacheBuilder = new Builder\CacheMetadataBuilder($metadataBuildingContext); |
|
363
|
|
|
|
|
364
|
|
|
$cacheBuilder |
|
365
|
|
|
->withEntityClassMetadata($metadata) |
|
366
|
|
|
->withFieldName($association->getName()) |
|
367
|
|
|
->withCacheAnnotation($this->convertCacheElementToCacheAnnotation($oneToOneElement->cache)); |
|
368
|
|
|
|
|
369
|
|
|
$association->setCache($cacheBuilder->build()); |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
7 |
|
$metadata->addProperty($association); |
|
373
|
|
|
} |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
// Evaluate <one-to-many ...> mappings |
|
377
|
34 |
|
if (isset($xmlRoot->{'one-to-many'})) { |
|
378
|
9 |
|
foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) { |
|
379
|
9 |
|
$association = new Mapping\OneToManyAssociationMetadata((string)$oneToManyElement['field']); |
|
|
|
|
|
|
380
|
9 |
|
$targetEntity = (string)$oneToManyElement['target-entity']; |
|
|
|
|
|
|
381
|
|
|
|
|
382
|
9 |
|
$association->setTargetEntity($targetEntity); |
|
383
|
9 |
|
$association->setOwningSide(false); |
|
384
|
9 |
|
$association->setMappedBy((string)$oneToManyElement['mapped-by']); |
|
|
|
|
|
|
385
|
|
|
|
|
386
|
9 |
|
if (isset($associationIds[$association->getName()])) { |
|
387
|
|
|
throw Mapping\MappingException::illegalToManyIdentifierAssociation($className, $association->getName()); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
9 |
|
if (isset($oneToManyElement['fetch'])) { |
|
391
|
|
|
$association->setFetchMode( |
|
392
|
|
|
constant(sprintf('%s::%s', Mapping\FetchMode::class, (string)$oneToManyElement['fetch'])) |
|
|
|
|
|
|
393
|
|
|
); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
9 |
|
if (isset($oneToManyElement->cascade)) { |
|
397
|
6 |
|
$association->setCascade($this->getCascadeMappings($oneToManyElement->cascade)); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
9 |
|
if (isset($oneToManyElement['orphan-removal'])) { |
|
401
|
3 |
|
$association->setOrphanRemoval($this->evaluateBoolean($oneToManyElement['orphan-removal'])); |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
9 |
|
if (isset($oneToManyElement->{'order-by'})) { |
|
405
|
5 |
|
$orderBy = []; |
|
406
|
|
|
|
|
407
|
5 |
|
foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { |
|
408
|
5 |
|
$orderBy[(string)$orderByField['name']] = isset($orderByField['direction']) |
|
|
|
|
|
|
409
|
4 |
|
? (string)$orderByField['direction'] |
|
|
|
|
|
|
410
|
1 |
|
: Criteria::ASC; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
5 |
|
$association->setOrderBy($orderBy); |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
9 |
|
if (isset($oneToManyElement['index-by'])) { |
|
417
|
3 |
|
$association->setIndexedBy((string)$oneToManyElement['index-by']); |
|
|
|
|
|
|
418
|
6 |
|
} elseif (isset($oneToManyElement->{'index-by'})) { |
|
419
|
|
|
throw new InvalidArgumentException('<index-by /> is not a valid tag'); |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
// Evaluate second level cache |
|
423
|
9 |
|
if (isset($oneToManyElement->cache)) { |
|
424
|
1 |
|
$cacheBuilder = new Builder\CacheMetadataBuilder($metadataBuildingContext); |
|
425
|
|
|
|
|
426
|
|
|
$cacheBuilder |
|
427
|
1 |
|
->withEntityClassMetadata($metadata) |
|
428
|
1 |
|
->withFieldName($association->getName()) |
|
429
|
1 |
|
->withCacheAnnotation($this->convertCacheElementToCacheAnnotation($oneToManyElement->cache)); |
|
430
|
|
|
|
|
431
|
1 |
|
$association->setCache($cacheBuilder->build()); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
9 |
|
$metadata->addProperty($association); |
|
435
|
|
|
} |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
// Evaluate <many-to-one ...> mappings |
|
439
|
34 |
|
if (isset($xmlRoot->{'many-to-one'})) { |
|
440
|
8 |
|
foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) { |
|
441
|
8 |
|
$association = new Mapping\ManyToOneAssociationMetadata((string)$manyToOneElement['field']); |
|
|
|
|
|
|
442
|
8 |
|
$targetEntity = (string)$manyToOneElement['target-entity']; |
|
|
|
|
|
|
443
|
|
|
|
|
444
|
8 |
|
$association->setTargetEntity($targetEntity); |
|
445
|
|
|
|
|
446
|
8 |
|
if (isset($associationIds[$association->getName()])) { |
|
447
|
2 |
|
$association->setPrimaryKey(true); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
8 |
|
if (isset($manyToOneElement['fetch'])) { |
|
451
|
|
|
$association->setFetchMode( |
|
452
|
|
|
constant('Doctrine\ORM\Mapping\FetchMode::' . (string)$manyToOneElement['fetch']) |
|
|
|
|
|
|
453
|
|
|
); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
8 |
|
if (isset($manyToOneElement['inversed-by'])) { |
|
457
|
2 |
|
$association->setInversedBy((string)$manyToOneElement['inversed-by']); |
|
|
|
|
|
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
8 |
|
$joinColumns = []; |
|
461
|
|
|
|
|
462
|
8 |
|
if (isset($manyToOneElement->{'join-column'})) { |
|
463
|
7 |
|
$joinColumns[] = $this->convertJoinColumnElementToJoinColumnMetadata($manyToOneElement->{'join-column'}); |
|
464
|
1 |
|
} elseif (isset($manyToOneElement->{'join-columns'})) { |
|
465
|
1 |
|
foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
466
|
1 |
|
$joinColumns[] = $this->convertJoinColumnElementToJoinColumnMetadata($joinColumnElement); |
|
467
|
|
|
} |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
8 |
|
$association->setJoinColumns($joinColumns); |
|
471
|
|
|
|
|
472
|
8 |
|
if (isset($manyToOneElement->cascade)) { |
|
473
|
4 |
|
$association->setCascade($this->getCascadeMappings($manyToOneElement->cascade)); |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
// Evaluate second level cache |
|
477
|
8 |
|
if (isset($manyToOneElement->cache)) { |
|
478
|
1 |
|
$cacheBuilder = new Builder\CacheMetadataBuilder($metadataBuildingContext); |
|
479
|
|
|
|
|
480
|
|
|
$cacheBuilder |
|
481
|
1 |
|
->withEntityClassMetadata($metadata) |
|
482
|
1 |
|
->withFieldName($association->getName()) |
|
483
|
1 |
|
->withCacheAnnotation($this->convertCacheElementToCacheAnnotation($manyToOneElement->cache)); |
|
484
|
|
|
|
|
485
|
1 |
|
$association->setCache($cacheBuilder->build()); |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
8 |
|
$metadata->addProperty($association); |
|
489
|
|
|
} |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
// Evaluate <many-to-many ...> mappings |
|
493
|
33 |
|
if (isset($xmlRoot->{'many-to-many'})) { |
|
494
|
14 |
|
foreach ($xmlRoot->{'many-to-many'} as $manyToManyElement) { |
|
495
|
14 |
|
$association = new Mapping\ManyToManyAssociationMetadata((string)$manyToManyElement['field']); |
|
|
|
|
|
|
496
|
14 |
|
$targetEntity = (string)$manyToManyElement['target-entity']; |
|
|
|
|
|
|
497
|
|
|
|
|
498
|
14 |
|
$association->setTargetEntity($targetEntity); |
|
499
|
|
|
|
|
500
|
14 |
|
if (isset($associationIds[$association->getName()])) { |
|
501
|
|
|
throw Mapping\MappingException::illegalToManyIdentifierAssociation($className, $association->getName()); |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
14 |
|
if (isset($manyToManyElement['fetch'])) { |
|
505
|
4 |
|
$association->setFetchMode( |
|
506
|
4 |
|
constant(sprintf('%s::%s', Mapping\FetchMode::class, (string)$manyToManyElement['fetch'])) |
|
|
|
|
|
|
507
|
|
|
); |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
14 |
|
if (isset($manyToManyElement['orphan-removal'])) { |
|
511
|
|
|
$association->setOrphanRemoval($this->evaluateBoolean($manyToManyElement['orphan-removal'])); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
14 |
|
if (isset($manyToManyElement['mapped-by'])) { |
|
515
|
5 |
|
$association->setMappedBy((string)$manyToManyElement['mapped-by']); |
|
|
|
|
|
|
516
|
5 |
|
$association->setOwningSide(false); |
|
517
|
10 |
|
} elseif (isset($manyToManyElement->{'join-table'})) { |
|
518
|
8 |
|
if (isset($manyToManyElement['inversed-by'])) { |
|
519
|
5 |
|
$association->setInversedBy((string)$manyToManyElement['inversed-by']); |
|
|
|
|
|
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
8 |
|
$joinTableElement = $manyToManyElement->{'join-table'}; |
|
523
|
8 |
|
$joinTable = new Mapping\JoinTableMetadata(); |
|
|
|
|
|
|
524
|
|
|
|
|
525
|
8 |
|
if (isset($joinTableElement['name'])) { |
|
526
|
8 |
|
$joinTable->setName((string)$joinTableElement['name']); |
|
|
|
|
|
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
8 |
|
if (isset($joinTableElement['schema'])) { |
|
530
|
|
|
$joinTable->setSchema((string)$joinTableElement['schema']); |
|
|
|
|
|
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
8 |
|
if (isset($joinTableElement->{'join-columns'})) { |
|
534
|
8 |
|
foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
535
|
8 |
|
$joinColumn = $this->convertJoinColumnElementToJoinColumnMetadata($joinColumnElement); |
|
536
|
|
|
|
|
537
|
8 |
|
$joinTable->addJoinColumn($joinColumn); |
|
538
|
|
|
} |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
8 |
|
if (isset($joinTableElement->{'inverse-join-columns'})) { |
|
542
|
8 |
|
foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { |
|
543
|
8 |
|
$joinColumn = $this->convertJoinColumnElementToJoinColumnMetadata($joinColumnElement); |
|
544
|
|
|
|
|
545
|
8 |
|
$joinTable->addInverseJoinColumn($joinColumn); |
|
546
|
|
|
} |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
8 |
|
$association->setJoinTable($joinTable); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
14 |
|
if (isset($manyToManyElement->cascade)) { |
|
553
|
8 |
|
$association->setCascade($this->getCascadeMappings($manyToManyElement->cascade)); |
|
554
|
|
|
} |
|
555
|
|
|
|
|
556
|
14 |
|
if (isset($manyToManyElement->{'order-by'})) { |
|
557
|
1 |
|
$orderBy = []; |
|
558
|
|
|
|
|
559
|
1 |
|
foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) { |
|
560
|
1 |
|
$orderBy[(string)$orderByField['name']] = isset($orderByField['direction']) |
|
|
|
|
|
|
561
|
|
|
? (string)$orderByField['direction'] |
|
|
|
|
|
|
562
|
1 |
|
: Criteria::ASC; |
|
563
|
|
|
} |
|
564
|
|
|
|
|
565
|
1 |
|
$association->setOrderBy($orderBy); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
14 |
|
if (isset($manyToManyElement['index-by'])) { |
|
569
|
|
|
$association->setIndexedBy((string)$manyToManyElement['index-by']); |
|
|
|
|
|
|
570
|
14 |
|
} elseif (isset($manyToManyElement->{'index-by'})) { |
|
571
|
|
|
throw new InvalidArgumentException('<index-by /> is not a valid tag'); |
|
572
|
|
|
} |
|
573
|
|
|
|
|
574
|
|
|
// Evaluate second level cache |
|
575
|
14 |
|
if (isset($manyToManyElement->cache)) { |
|
576
|
|
|
$cacheBuilder = new Builder\CacheMetadataBuilder($metadataBuildingContext); |
|
577
|
|
|
|
|
578
|
|
|
$cacheBuilder |
|
579
|
|
|
->withEntityClassMetadata($metadata) |
|
580
|
|
|
->withFieldName($association->getName()) |
|
581
|
|
|
->withCacheAnnotation($this->convertCacheElementToCacheAnnotation($manyToManyElement->cache)); |
|
582
|
|
|
|
|
583
|
|
|
$association->setCache($cacheBuilder->build()); |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
14 |
|
$metadata->addProperty($association); |
|
587
|
|
|
} |
|
588
|
|
|
} |
|
589
|
|
|
|
|
590
|
|
|
// Evaluate association-overrides |
|
591
|
33 |
|
if (isset($xmlRoot->{'attribute-overrides'})) { |
|
592
|
2 |
|
foreach ($xmlRoot->{'attribute-overrides'}->{'attribute-override'} as $overrideElement) { |
|
593
|
2 |
|
$fieldName = (string)$overrideElement['name']; |
|
|
|
|
|
|
594
|
|
|
|
|
595
|
2 |
|
foreach ($overrideElement->field as $fieldElement) { |
|
596
|
2 |
|
$fieldMetadata = $this->convertFieldElementToFieldMetadata($fieldElement, $fieldName, $metadata, $metadataBuildingContext); |
|
597
|
|
|
|
|
598
|
2 |
|
$metadata->setPropertyOverride($fieldMetadata); |
|
599
|
|
|
} |
|
600
|
|
|
} |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
// Evaluate association-overrides |
|
604
|
33 |
|
if (isset($xmlRoot->{'association-overrides'})) { |
|
605
|
4 |
|
foreach ($xmlRoot->{'association-overrides'}->{'association-override'} as $overrideElement) { |
|
606
|
4 |
|
$fieldName = (string)$overrideElement['name']; |
|
|
|
|
|
|
607
|
4 |
|
$property = $metadata->getProperty($fieldName); |
|
|
|
|
|
|
608
|
|
|
|
|
609
|
4 |
|
if (!$property) { |
|
|
|
|
|
|
610
|
|
|
throw Mapping\MappingException::invalidOverrideFieldName($metadata->getClassName(), $fieldName); |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
4 |
|
$existingClass = get_class($property); |
|
614
|
4 |
|
$override = new $existingClass($fieldName); |
|
|
|
|
|
|
615
|
|
|
|
|
616
|
|
|
// Check for join-columns |
|
617
|
4 |
|
if (isset($overrideElement->{'join-columns'})) { |
|
618
|
2 |
|
$joinColumns = []; |
|
619
|
|
|
|
|
620
|
2 |
|
foreach ($overrideElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
621
|
2 |
|
$joinColumns[] = $this->convertJoinColumnElementToJoinColumnMetadata($joinColumnElement); |
|
622
|
|
|
} |
|
623
|
|
|
|
|
624
|
2 |
|
$override->setJoinColumns($joinColumns); |
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
// Check for join-table |
|
628
|
4 |
|
if ($overrideElement->{'join-table'}) { |
|
629
|
2 |
|
$joinTableElement = $overrideElement->{'join-table'}; |
|
630
|
2 |
|
$joinTable = new Mapping\JoinTableMetadata(); |
|
|
|
|
|
|
631
|
|
|
|
|
632
|
2 |
|
if (isset($joinTableElement['name'])) { |
|
633
|
2 |
|
$joinTable->setName((string)$joinTableElement['name']); |
|
|
|
|
|
|
634
|
|
|
} |
|
635
|
|
|
|
|
636
|
2 |
|
if (isset($joinTableElement['schema'])) { |
|
637
|
|
|
$joinTable->setSchema((string)$joinTableElement['schema']); |
|
|
|
|
|
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
2 |
|
if (isset($joinTableElement->{'join-columns'})) { |
|
641
|
2 |
|
foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
642
|
2 |
|
$joinColumn = $this->convertJoinColumnElementToJoinColumnMetadata($joinColumnElement); |
|
643
|
|
|
|
|
644
|
2 |
|
$joinTable->addJoinColumn($joinColumn); |
|
645
|
|
|
} |
|
646
|
|
|
} |
|
647
|
|
|
|
|
648
|
2 |
|
if (isset($joinTableElement->{'inverse-join-columns'})) { |
|
649
|
2 |
|
foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { |
|
650
|
2 |
|
$joinColumn = $this->convertJoinColumnElementToJoinColumnMetadata($joinColumnElement); |
|
651
|
|
|
|
|
652
|
2 |
|
$joinTable->addInverseJoinColumn($joinColumn); |
|
653
|
|
|
} |
|
654
|
|
|
} |
|
655
|
|
|
|
|
656
|
2 |
|
$override->setJoinTable($joinTable); |
|
657
|
|
|
} |
|
658
|
|
|
|
|
659
|
|
|
// Check for inversed-by |
|
660
|
4 |
|
if (isset($overrideElement->{'inversed-by'})) { |
|
661
|
1 |
|
$override->setInversedBy((string)$overrideElement->{'inversed-by'}['name']); |
|
|
|
|
|
|
662
|
|
|
} |
|
663
|
|
|
|
|
664
|
|
|
// Check for fetch |
|
665
|
4 |
|
if (isset($overrideElement['fetch'])) { |
|
666
|
1 |
|
$override->setFetchMode( |
|
667
|
1 |
|
constant('Doctrine\ORM\Mapping\FetchMode::' . (string)$overrideElement['fetch']) |
|
|
|
|
|
|
668
|
|
|
); |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
4 |
|
$metadata->setPropertyOverride($override); |
|
672
|
|
|
} |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
// Evaluate <lifecycle-callbacks...> |
|
676
|
33 |
|
if (isset($xmlRoot->{'lifecycle-callbacks'})) { |
|
677
|
3 |
|
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { |
|
678
|
3 |
|
$eventName = constant(Events::class . '::' . (string)$lifecycleCallback['type']); |
|
|
|
|
|
|
679
|
3 |
|
$methodName = (string)$lifecycleCallback['method']; |
|
|
|
|
|
|
680
|
|
|
|
|
681
|
3 |
|
$metadata->addLifecycleCallback($eventName, $methodName); |
|
682
|
|
|
} |
|
683
|
|
|
} |
|
684
|
|
|
|
|
685
|
|
|
// Evaluate entity listener |
|
686
|
33 |
|
if (isset($xmlRoot->{'entity-listeners'})) { |
|
687
|
2 |
|
foreach ($xmlRoot->{'entity-listeners'}->{'entity-listener'} as $listenerElement) { |
|
688
|
2 |
|
$listenerClassName = (string)$listenerElement['class']; |
|
|
|
|
|
|
689
|
|
|
|
|
690
|
2 |
|
if (!class_exists($listenerClassName)) { |
|
|
|
|
|
|
691
|
|
|
throw Mapping\MappingException::entityListenerClassNotFound( |
|
692
|
|
|
$listenerClassName, |
|
693
|
|
|
$metadata->getClassName() |
|
694
|
|
|
); |
|
695
|
|
|
} |
|
696
|
|
|
|
|
697
|
2 |
|
foreach ($listenerElement as $callbackElement) { |
|
698
|
2 |
|
$eventName = (string)$callbackElement['type']; |
|
|
|
|
|
|
699
|
2 |
|
$methodName = (string)$callbackElement['method']; |
|
|
|
|
|
|
700
|
|
|
|
|
701
|
2 |
|
$metadata->addEntityListener($eventName, $listenerClassName, $methodName); |
|
702
|
|
|
} |
|
703
|
|
|
} |
|
704
|
|
|
} |
|
705
|
|
|
|
|
706
|
33 |
|
return $metadata; |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
/** |
|
710
|
|
|
* Parses (nested) option elements. |
|
711
|
|
|
* |
|
712
|
|
|
* @param SimpleXMLElement $options The XML element. |
|
713
|
|
|
* |
|
714
|
|
|
* @return mixed[] The options array. |
|
715
|
|
|
*/ |
|
716
|
4 |
|
private function parseOptions(SimpleXMLElement $options) |
|
717
|
|
|
{ |
|
718
|
4 |
|
$array = []; |
|
719
|
|
|
|
|
720
|
|
|
/** @var SimpleXMLElement $option */ |
|
721
|
4 |
|
foreach ($options as $option) { |
|
722
|
4 |
|
if ($option->count()) { |
|
723
|
3 |
|
$value = $this->parseOptions($option->children()); |
|
724
|
|
|
} else { |
|
725
|
4 |
|
$value = (string)$option; |
|
|
|
|
|
|
726
|
|
|
} |
|
727
|
|
|
|
|
728
|
4 |
|
$attributes = $option->attributes(); |
|
729
|
|
|
|
|
730
|
4 |
|
if (isset($attributes->name)) { |
|
731
|
4 |
|
$nameAttribute = (string)$attributes->name; |
|
|
|
|
|
|
732
|
4 |
|
$array[$nameAttribute] = in_array($nameAttribute, ['unsigned', 'fixed'], true) |
|
733
|
3 |
|
? $this->evaluateBoolean($value) |
|
734
|
4 |
|
: $value; |
|
735
|
|
|
} else { |
|
736
|
|
|
$array[] = $value; |
|
737
|
|
|
} |
|
738
|
|
|
} |
|
739
|
|
|
|
|
740
|
4 |
|
return $array; |
|
741
|
|
|
} |
|
742
|
|
|
|
|
743
|
|
|
/** |
|
744
|
|
|
* @return Mapping\FieldMetadata |
|
745
|
|
|
* |
|
746
|
|
|
* @throws Mapping\MappingException |
|
747
|
|
|
*/ |
|
748
|
30 |
|
private function convertFieldElementToFieldMetadata( |
|
749
|
|
|
SimpleXMLElement $fieldElement, |
|
750
|
|
|
string $fieldName, |
|
751
|
|
|
Mapping\ClassMetadata $metadata, |
|
752
|
|
|
Mapping\ClassMetadataBuildingContext $metadataBuildingContext |
|
753
|
|
|
) |
|
754
|
|
|
{ |
|
|
|
|
|
|
755
|
30 |
|
$className = $metadata->getClassName(); |
|
|
|
|
|
|
756
|
30 |
|
$isVersioned = isset($fieldElement['version']) && $fieldElement['version']; |
|
|
|
|
|
|
757
|
30 |
|
$fieldMetadata = new Mapping\FieldMetadata($fieldName); |
|
758
|
30 |
|
$fieldType = isset($fieldElement['type']) ? (string)$fieldElement['type'] : 'string'; |
|
|
|
|
|
|
759
|
30 |
|
$columnName = isset($fieldElement['column']) |
|
|
|
|
|
|
760
|
20 |
|
? (string)$fieldElement['column'] |
|
|
|
|
|
|
761
|
30 |
|
: $metadataBuildingContext->getNamingStrategy()->propertyToColumnName($fieldName, $className); |
|
762
|
|
|
|
|
763
|
30 |
|
$fieldMetadata->setType(Type::getType($fieldType)); |
|
764
|
30 |
|
$fieldMetadata->setVersioned($isVersioned); |
|
765
|
30 |
|
$fieldMetadata->setColumnName($columnName); |
|
766
|
|
|
|
|
767
|
30 |
|
if (isset($fieldElement['length'])) { |
|
768
|
6 |
|
$fieldMetadata->setLength((int)$fieldElement['length']); |
|
|
|
|
|
|
769
|
|
|
} |
|
770
|
|
|
|
|
771
|
30 |
|
if (isset($fieldElement['precision'])) { |
|
772
|
1 |
|
$fieldMetadata->setPrecision((int)$fieldElement['precision']); |
|
|
|
|
|
|
773
|
|
|
} |
|
774
|
|
|
|
|
775
|
30 |
|
if (isset($fieldElement['scale'])) { |
|
776
|
1 |
|
$fieldMetadata->setScale((int)$fieldElement['scale']); |
|
|
|
|
|
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
30 |
|
if (isset($fieldElement['unique'])) { |
|
780
|
7 |
|
$fieldMetadata->setUnique($this->evaluateBoolean($fieldElement['unique'])); |
|
781
|
|
|
} |
|
782
|
|
|
|
|
783
|
30 |
|
if (isset($fieldElement['nullable'])) { |
|
784
|
7 |
|
$fieldMetadata->setNullable($this->evaluateBoolean($fieldElement['nullable'])); |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
30 |
|
if (isset($fieldElement['column-definition'])) { |
|
788
|
4 |
|
$fieldMetadata->setColumnDefinition((string)$fieldElement['column-definition']); |
|
|
|
|
|
|
789
|
|
|
} |
|
790
|
|
|
|
|
791
|
30 |
|
if (isset($fieldElement->options)) { |
|
792
|
3 |
|
$fieldMetadata->setOptions($this->parseOptions($fieldElement->options->children())); |
|
793
|
|
|
} |
|
794
|
|
|
|
|
795
|
|
|
// Prevent column duplication |
|
796
|
30 |
|
if ($metadata->checkPropertyDuplication($columnName)) { |
|
797
|
|
|
throw Mapping\MappingException::duplicateColumnName($className, $columnName); |
|
798
|
|
|
} |
|
799
|
|
|
|
|
800
|
30 |
|
return $fieldMetadata; |
|
801
|
|
|
} |
|
802
|
|
|
|
|
803
|
|
|
/** |
|
804
|
|
|
* Constructs a joinColumn mapping array based on the information |
|
805
|
|
|
* found in the given SimpleXMLElement. |
|
806
|
|
|
* |
|
807
|
|
|
* @param SimpleXMLElement $joinColumnElement The XML element. |
|
808
|
|
|
* |
|
809
|
|
|
* @return Mapping\JoinColumnMetadata |
|
810
|
|
|
*/ |
|
811
|
13 |
|
private function convertJoinColumnElementToJoinColumnMetadata(SimpleXMLElement $joinColumnElement) |
|
812
|
|
|
{ |
|
813
|
13 |
|
$joinColumnMetadata = new Mapping\JoinColumnMetadata(); |
|
814
|
|
|
|
|
815
|
13 |
|
$joinColumnMetadata->setColumnName((string)$joinColumnElement['name']); |
|
|
|
|
|
|
816
|
13 |
|
$joinColumnMetadata->setReferencedColumnName((string)$joinColumnElement['referenced-column-name']); |
|
|
|
|
|
|
817
|
|
|
|
|
818
|
13 |
|
if (isset($joinColumnElement['column-definition'])) { |
|
819
|
3 |
|
$joinColumnMetadata->setColumnDefinition((string)$joinColumnElement['column-definition']); |
|
|
|
|
|
|
820
|
|
|
} |
|
821
|
|
|
|
|
822
|
13 |
|
if (isset($joinColumnElement['field-name'])) { |
|
823
|
|
|
$joinColumnMetadata->setAliasedName((string)$joinColumnElement['field-name']); |
|
|
|
|
|
|
824
|
|
|
} |
|
825
|
|
|
|
|
826
|
13 |
|
if (isset($joinColumnElement['nullable'])) { |
|
827
|
4 |
|
$joinColumnMetadata->setNullable($this->evaluateBoolean($joinColumnElement['nullable'])); |
|
828
|
|
|
} |
|
829
|
|
|
|
|
830
|
13 |
|
if (isset($joinColumnElement['unique'])) { |
|
831
|
3 |
|
$joinColumnMetadata->setUnique($this->evaluateBoolean($joinColumnElement['unique'])); |
|
832
|
|
|
} |
|
833
|
|
|
|
|
834
|
13 |
|
if (isset($joinColumnElement['on-delete'])) { |
|
835
|
3 |
|
$joinColumnMetadata->setOnDelete(strtoupper((string)$joinColumnElement['on-delete'])); |
|
|
|
|
|
|
836
|
|
|
} |
|
837
|
|
|
|
|
838
|
13 |
|
return $joinColumnMetadata; |
|
839
|
|
|
} |
|
840
|
|
|
|
|
841
|
|
|
/** |
|
842
|
|
|
* Parse the given Cache as CacheMetadata |
|
843
|
|
|
*/ |
|
844
|
2 |
|
private function convertCacheElementToCacheAnnotation(SimpleXMLElement $cacheMapping): Annotation\Cache |
|
|
|
|
|
|
845
|
|
|
{ |
|
846
|
2 |
|
$cacheAnnotation = new Annotation\Cache(); |
|
847
|
|
|
|
|
848
|
2 |
|
if (isset($cacheMapping['region'])) { |
|
849
|
|
|
$cacheAnnotation->region = (string) $cacheMapping['region']; |
|
850
|
|
|
} |
|
851
|
|
|
|
|
852
|
2 |
|
if (isset($cacheMapping['usage'])) { |
|
853
|
2 |
|
$cacheAnnotation->usage = strtoupper((string) $cacheMapping['usage']); |
|
854
|
|
|
} |
|
855
|
|
|
|
|
856
|
2 |
|
return $cacheAnnotation; |
|
857
|
|
|
} |
|
858
|
|
|
|
|
859
|
|
|
/** |
|
860
|
|
|
* Gathers a list of cascade options found in the given cascade element. |
|
861
|
|
|
* |
|
862
|
|
|
* @param SimpleXMLElement $cascadeElement The cascade element. |
|
863
|
|
|
* |
|
864
|
|
|
* @return string[] The list of cascade options. |
|
865
|
|
|
*/ |
|
866
|
10 |
|
private function getCascadeMappings(SimpleXMLElement $cascadeElement) |
|
867
|
|
|
{ |
|
868
|
10 |
|
$cascades = []; |
|
869
|
|
|
|
|
870
|
|
|
/** @var SimpleXMLElement $action */ |
|
871
|
10 |
|
foreach ($cascadeElement->children() as $action) { |
|
872
|
|
|
// According to the JPA specifications, XML uses "cascade-persist" |
|
873
|
|
|
// instead of "persist". Here, both variations are supported |
|
874
|
|
|
// because Annotation use "persist" and we want to make sure that |
|
875
|
|
|
// this driver doesn't need to know anything about the supported |
|
876
|
|
|
// cascading actions |
|
877
|
10 |
|
$cascades[] = str_replace('cascade-', '', $action->getName()); |
|
878
|
|
|
} |
|
879
|
|
|
|
|
880
|
10 |
|
return $cascades; |
|
881
|
|
|
} |
|
882
|
|
|
|
|
883
|
|
|
/** |
|
884
|
|
|
* {@inheritDoc} |
|
885
|
|
|
*/ |
|
886
|
36 |
|
protected function loadMappingFile($file) |
|
887
|
|
|
{ |
|
888
|
36 |
|
$result = []; |
|
889
|
|
|
// Note: we do not use `simplexml_load_file()` because of https://bugs.php.net/bug.php?id=62577 |
|
890
|
36 |
|
$xmlElement = simplexml_load_string(file_get_contents($file)); |
|
891
|
|
|
|
|
892
|
36 |
|
if (isset($xmlElement->entity)) { |
|
893
|
35 |
|
foreach ($xmlElement->entity as $entityElement) { |
|
894
|
35 |
|
$entityName = (string) $entityElement['name']; |
|
895
|
35 |
|
$result[$entityName] = $entityElement; |
|
896
|
|
|
} |
|
897
|
6 |
|
} elseif (isset($xmlElement->{'mapped-superclass'})) { |
|
898
|
5 |
|
foreach ($xmlElement->{'mapped-superclass'} as $mappedSuperClass) { |
|
899
|
5 |
|
$className = (string) $mappedSuperClass['name']; |
|
900
|
5 |
|
$result[$className] = $mappedSuperClass; |
|
901
|
|
|
} |
|
902
|
1 |
|
} elseif (isset($xmlElement->embeddable)) { |
|
903
|
|
|
foreach ($xmlElement->embeddable as $embeddableElement) { |
|
904
|
|
|
$embeddableName = (string) $embeddableElement['name']; |
|
905
|
|
|
$result[$embeddableName] = $embeddableElement; |
|
906
|
|
|
} |
|
907
|
|
|
} |
|
908
|
|
|
|
|
909
|
36 |
|
return $result; |
|
910
|
|
|
} |
|
911
|
|
|
|
|
912
|
|
|
/** |
|
913
|
|
|
* @param mixed $element |
|
914
|
|
|
* |
|
915
|
|
|
* @return bool |
|
916
|
|
|
*/ |
|
917
|
9 |
|
protected function evaluateBoolean($element) |
|
918
|
|
|
{ |
|
919
|
9 |
|
$flag = (string) $element; |
|
920
|
|
|
|
|
921
|
9 |
|
return $flag === 'true' || $flag === '1'; |
|
922
|
|
|
} |
|
923
|
|
|
} |
|
924
|
|
|
|