|
0
|
1 |
<?php |
|
|
2 |
/* |
|
|
3 |
* $Id$ |
|
|
4 |
* |
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
16 |
* |
|
|
17 |
* This software consists of voluntary contributions made by many individuals |
|
|
18 |
* and is licensed under the LGPL. For more information, see |
|
|
19 |
* <http://www.doctrine-project.org>. |
|
|
20 |
*/ |
|
|
21 |
|
|
|
22 |
namespace Doctrine\ORM\Mapping\Driver; |
|
|
23 |
|
|
|
24 |
use SimpleXMLElement, |
|
|
25 |
Doctrine\ORM\Mapping\ClassMetadataInfo, |
|
|
26 |
Doctrine\ORM\Mapping\MappingException; |
|
|
27 |
|
|
|
28 |
/** |
|
|
29 |
* XmlDriver is a metadata driver that enables mapping through XML files. |
|
|
30 |
* |
|
|
31 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
|
|
32 |
* @link www.doctrine-project.org |
|
|
33 |
* @since 2.0 |
|
|
34 |
* @version $Revision$ |
|
|
35 |
* @author Benjamin Eberlei <kontakt@beberlei.de> |
|
|
36 |
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> |
|
|
37 |
* @author Jonathan H. Wage <jonwage@gmail.com> |
|
|
38 |
* @author Roman Borschel <roman@code-factory.org> |
|
|
39 |
*/ |
|
|
40 |
class XmlDriver extends AbstractFileDriver |
|
|
41 |
{ |
|
|
42 |
/** |
|
|
43 |
* {@inheritdoc} |
|
|
44 |
*/ |
|
|
45 |
protected $_fileExtension = '.dcm.xml'; |
|
|
46 |
|
|
|
47 |
/** |
|
|
48 |
* {@inheritdoc} |
|
|
49 |
*/ |
|
|
50 |
public function loadMetadataForClass($className, ClassMetadataInfo $metadata) |
|
|
51 |
{ |
|
|
52 |
$xmlRoot = $this->getElement($className); |
|
|
53 |
|
|
|
54 |
if ($xmlRoot->getName() == 'entity') { |
|
|
55 |
$metadata->setCustomRepositoryClass( |
|
|
56 |
isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null |
|
|
57 |
); |
|
|
58 |
if (isset($xmlRoot['read-only']) && $xmlRoot['read-only'] == "true") { |
|
|
59 |
$metadata->markReadOnly(); |
|
|
60 |
} |
|
|
61 |
} else if ($xmlRoot->getName() == 'mapped-superclass') { |
|
|
62 |
$metadata->isMappedSuperclass = true; |
|
|
63 |
} else { |
|
|
64 |
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
// Evaluate <entity...> attributes |
|
|
68 |
$table = array(); |
|
|
69 |
if (isset($xmlRoot['table'])) { |
|
|
70 |
$table['name'] = (string)$xmlRoot['table']; |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
$metadata->setPrimaryTable($table); |
|
|
74 |
|
|
|
75 |
// Evaluate named queries |
|
|
76 |
if (isset($xmlRoot['named-queries'])) { |
|
|
77 |
foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) { |
|
|
78 |
$metadata->addNamedQuery(array( |
|
|
79 |
'name' => (string)$namedQueryElement['name'], |
|
|
80 |
'query' => (string)$namedQueryElement['query'] |
|
|
81 |
)); |
|
|
82 |
} |
|
|
83 |
} |
|
|
84 |
|
|
|
85 |
/* not implemented specially anyway. use table = schema.table |
|
|
86 |
if (isset($xmlRoot['schema'])) { |
|
|
87 |
$metadata->table['schema'] = (string)$xmlRoot['schema']; |
|
|
88 |
}*/ |
|
|
89 |
|
|
|
90 |
if (isset($xmlRoot['inheritance-type'])) { |
|
|
91 |
$inheritanceType = (string)$xmlRoot['inheritance-type']; |
|
|
92 |
$metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType)); |
|
|
93 |
|
|
|
94 |
if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) { |
|
|
95 |
// Evaluate <discriminator-column...> |
|
|
96 |
if (isset($xmlRoot->{'discriminator-column'})) { |
|
|
97 |
$discrColumn = $xmlRoot->{'discriminator-column'}; |
|
|
98 |
$metadata->setDiscriminatorColumn(array( |
|
|
99 |
'name' => (string)$discrColumn['name'], |
|
|
100 |
'type' => (string)$discrColumn['type'], |
|
|
101 |
'length' => (string)$discrColumn['length'] |
|
|
102 |
)); |
|
|
103 |
} else { |
|
|
104 |
$metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255)); |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
// Evaluate <discriminator-map...> |
|
|
108 |
if (isset($xmlRoot->{'discriminator-map'})) { |
|
|
109 |
$map = array(); |
|
|
110 |
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} AS $discrMapElement) { |
|
|
111 |
$map[(string)$discrMapElement['value']] = (string)$discrMapElement['class']; |
|
|
112 |
} |
|
|
113 |
$metadata->setDiscriminatorMap($map); |
|
|
114 |
} |
|
|
115 |
} |
|
|
116 |
} |
|
|
117 |
|
|
|
118 |
|
|
|
119 |
// Evaluate <change-tracking-policy...> |
|
|
120 |
if (isset($xmlRoot['change-tracking-policy'])) { |
|
|
121 |
$metadata->setChangeTrackingPolicy(constant('Doctrine\ORM\Mapping\ClassMetadata::CHANGETRACKING_' |
|
|
122 |
. strtoupper((string)$xmlRoot['change-tracking-policy']))); |
|
|
123 |
} |
|
|
124 |
|
|
|
125 |
// Evaluate <indexes...> |
|
|
126 |
if (isset($xmlRoot->indexes)) { |
|
|
127 |
$metadata->table['indexes'] = array(); |
|
|
128 |
foreach ($xmlRoot->indexes->index as $index) { |
|
|
129 |
$columns = explode(',', (string)$index['columns']); |
|
|
130 |
|
|
|
131 |
if (isset($index['name'])) { |
|
|
132 |
$metadata->table['indexes'][(string)$index['name']] = array( |
|
|
133 |
'columns' => $columns |
|
|
134 |
); |
|
|
135 |
} else { |
|
|
136 |
$metadata->table['indexes'][] = array( |
|
|
137 |
'columns' => $columns |
|
|
138 |
); |
|
|
139 |
} |
|
|
140 |
} |
|
|
141 |
} |
|
|
142 |
|
|
|
143 |
// Evaluate <unique-constraints..> |
|
|
144 |
if (isset($xmlRoot->{'unique-constraints'})) { |
|
|
145 |
$metadata->table['uniqueConstraints'] = array(); |
|
|
146 |
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) { |
|
|
147 |
$columns = explode(',', (string)$unique['columns']); |
|
|
148 |
|
|
|
149 |
if (isset($unique['name'])) { |
|
|
150 |
$metadata->table['uniqueConstraints'][(string)$unique['name']] = array( |
|
|
151 |
'columns' => $columns |
|
|
152 |
); |
|
|
153 |
} else { |
|
|
154 |
$metadata->table['uniqueConstraints'][] = array( |
|
|
155 |
'columns' => $columns |
|
|
156 |
); |
|
|
157 |
} |
|
|
158 |
} |
|
|
159 |
} |
|
|
160 |
|
|
|
161 |
// Evaluate <field ...> mappings |
|
|
162 |
if (isset($xmlRoot->field)) { |
|
|
163 |
foreach ($xmlRoot->field as $fieldMapping) { |
|
|
164 |
$mapping = array( |
|
|
165 |
'fieldName' => (string)$fieldMapping['name'], |
|
|
166 |
'type' => (string)$fieldMapping['type'] |
|
|
167 |
); |
|
|
168 |
|
|
|
169 |
if (isset($fieldMapping['column'])) { |
|
|
170 |
$mapping['columnName'] = (string)$fieldMapping['column']; |
|
|
171 |
} |
|
|
172 |
|
|
|
173 |
if (isset($fieldMapping['length'])) { |
|
|
174 |
$mapping['length'] = (int)$fieldMapping['length']; |
|
|
175 |
} |
|
|
176 |
|
|
|
177 |
if (isset($fieldMapping['precision'])) { |
|
|
178 |
$mapping['precision'] = (int)$fieldMapping['precision']; |
|
|
179 |
} |
|
|
180 |
|
|
|
181 |
if (isset($fieldMapping['scale'])) { |
|
|
182 |
$mapping['scale'] = (int)$fieldMapping['scale']; |
|
|
183 |
} |
|
|
184 |
|
|
|
185 |
if (isset($fieldMapping['unique'])) { |
|
|
186 |
$mapping['unique'] = ((string)$fieldMapping['unique'] == "false") ? false : true; |
|
|
187 |
} |
|
|
188 |
|
|
|
189 |
if (isset($fieldMapping['options'])) { |
|
|
190 |
$mapping['options'] = (array)$fieldMapping['options']; |
|
|
191 |
} |
|
|
192 |
|
|
|
193 |
if (isset($fieldMapping['nullable'])) { |
|
|
194 |
$mapping['nullable'] = ((string)$fieldMapping['nullable'] == "false") ? false : true; |
|
|
195 |
} |
|
|
196 |
|
|
|
197 |
if (isset($fieldMapping['version']) && $fieldMapping['version']) { |
|
|
198 |
$metadata->setVersionMapping($mapping); |
|
|
199 |
} |
|
|
200 |
|
|
|
201 |
if (isset($fieldMapping['column-definition'])) { |
|
|
202 |
$mapping['columnDefinition'] = (string)$fieldMapping['column-definition']; |
|
|
203 |
} |
|
|
204 |
|
|
|
205 |
$metadata->mapField($mapping); |
|
|
206 |
} |
|
|
207 |
} |
|
|
208 |
|
|
|
209 |
// Evaluate <id ...> mappings |
|
|
210 |
$associationIds = array(); |
|
|
211 |
foreach ($xmlRoot->id as $idElement) { |
|
|
212 |
if ((bool)$idElement['association-key'] == true) { |
|
|
213 |
$associationIds[(string)$idElement['fieldName']] = true; |
|
|
214 |
continue; |
|
|
215 |
} |
|
|
216 |
|
|
|
217 |
$mapping = array( |
|
|
218 |
'id' => true, |
|
|
219 |
'fieldName' => (string)$idElement['name'], |
|
|
220 |
'type' => (string)$idElement['type'] |
|
|
221 |
); |
|
|
222 |
|
|
|
223 |
if (isset($idElement['column'])) { |
|
|
224 |
$mapping['columnName'] = (string)$idElement['column']; |
|
|
225 |
} |
|
|
226 |
|
|
|
227 |
$metadata->mapField($mapping); |
|
|
228 |
|
|
|
229 |
if (isset($idElement->generator)) { |
|
|
230 |
$strategy = isset($idElement->generator['strategy']) ? |
|
|
231 |
(string)$idElement->generator['strategy'] : 'AUTO'; |
|
|
232 |
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' |
|
|
233 |
. $strategy)); |
|
|
234 |
} |
|
|
235 |
|
|
|
236 |
// Check for SequenceGenerator/TableGenerator definition |
|
|
237 |
if (isset($idElement->{'sequence-generator'})) { |
|
|
238 |
$seqGenerator = $idElement->{'sequence-generator'}; |
|
|
239 |
$metadata->setSequenceGeneratorDefinition(array( |
|
|
240 |
'sequenceName' => (string)$seqGenerator['sequence-name'], |
|
|
241 |
'allocationSize' => (string)$seqGenerator['allocation-size'], |
|
|
242 |
'initialValue' => (string)$seqGenerator['initial-value'] |
|
|
243 |
)); |
|
|
244 |
} else if (isset($idElement->{'table-generator'})) { |
|
|
245 |
throw MappingException::tableIdGeneratorNotImplemented($className); |
|
|
246 |
} |
|
|
247 |
} |
|
|
248 |
|
|
|
249 |
// Evaluate <one-to-one ...> mappings |
|
|
250 |
if (isset($xmlRoot->{'one-to-one'})) { |
|
|
251 |
foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) { |
|
|
252 |
$mapping = array( |
|
|
253 |
'fieldName' => (string)$oneToOneElement['field'], |
|
|
254 |
'targetEntity' => (string)$oneToOneElement['target-entity'] |
|
|
255 |
); |
|
|
256 |
|
|
|
257 |
if (isset($associationIds[$mapping['fieldName']])) { |
|
|
258 |
$mapping['id'] = true; |
|
|
259 |
} |
|
|
260 |
|
|
|
261 |
if (isset($oneToOneElement['fetch'])) { |
|
|
262 |
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string)$oneToOneElement['fetch']); |
|
|
263 |
} |
|
|
264 |
|
|
|
265 |
if (isset($oneToOneElement['mapped-by'])) { |
|
|
266 |
$mapping['mappedBy'] = (string)$oneToOneElement['mapped-by']; |
|
|
267 |
} else { |
|
|
268 |
if (isset($oneToOneElement['inversed-by'])) { |
|
|
269 |
$mapping['inversedBy'] = (string)$oneToOneElement['inversed-by']; |
|
|
270 |
} |
|
|
271 |
$joinColumns = array(); |
|
|
272 |
|
|
|
273 |
if (isset($oneToOneElement->{'join-column'})) { |
|
|
274 |
$joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'}); |
|
|
275 |
} else if (isset($oneToOneElement->{'join-columns'})) { |
|
|
276 |
foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
|
277 |
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); |
|
|
278 |
} |
|
|
279 |
} |
|
|
280 |
|
|
|
281 |
$mapping['joinColumns'] = $joinColumns; |
|
|
282 |
} |
|
|
283 |
|
|
|
284 |
if (isset($oneToOneElement->cascade)) { |
|
|
285 |
$mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade); |
|
|
286 |
} |
|
|
287 |
|
|
|
288 |
if (isset($oneToOneElement['orphan-removal'])) { |
|
|
289 |
$mapping['orphanRemoval'] = (bool)$oneToOneElement['orphan-removal']; |
|
|
290 |
} |
|
|
291 |
|
|
|
292 |
$metadata->mapOneToOne($mapping); |
|
|
293 |
} |
|
|
294 |
} |
|
|
295 |
|
|
|
296 |
// Evaluate <one-to-many ...> mappings |
|
|
297 |
if (isset($xmlRoot->{'one-to-many'})) { |
|
|
298 |
foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) { |
|
|
299 |
$mapping = array( |
|
|
300 |
'fieldName' => (string)$oneToManyElement['field'], |
|
|
301 |
'targetEntity' => (string)$oneToManyElement['target-entity'], |
|
|
302 |
'mappedBy' => (string)$oneToManyElement['mapped-by'] |
|
|
303 |
); |
|
|
304 |
|
|
|
305 |
if (isset($oneToManyElement['fetch'])) { |
|
|
306 |
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string)$oneToManyElement['fetch']); |
|
|
307 |
} |
|
|
308 |
|
|
|
309 |
if (isset($oneToManyElement->cascade)) { |
|
|
310 |
$mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade); |
|
|
311 |
} |
|
|
312 |
|
|
|
313 |
if (isset($oneToManyElement['orphan-removal'])) { |
|
|
314 |
$mapping['orphanRemoval'] = (bool)$oneToManyElement['orphan-removal']; |
|
|
315 |
} |
|
|
316 |
|
|
|
317 |
if (isset($oneToManyElement->{'order-by'})) { |
|
|
318 |
$orderBy = array(); |
|
|
319 |
foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} AS $orderByField) { |
|
|
320 |
$orderBy[(string)$orderByField['name']] = (string)$orderByField['direction']; |
|
|
321 |
} |
|
|
322 |
$mapping['orderBy'] = $orderBy; |
|
|
323 |
} |
|
|
324 |
|
|
|
325 |
if (isset($oneToManyElement->{'index-by'})) { |
|
|
326 |
$mapping['indexBy'] = (string)$oneToManyElement->{'index-by'}; |
|
|
327 |
} |
|
|
328 |
|
|
|
329 |
$metadata->mapOneToMany($mapping); |
|
|
330 |
} |
|
|
331 |
} |
|
|
332 |
|
|
|
333 |
// Evaluate <many-to-one ...> mappings |
|
|
334 |
if (isset($xmlRoot->{'many-to-one'})) { |
|
|
335 |
foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) { |
|
|
336 |
$mapping = array( |
|
|
337 |
'fieldName' => (string)$manyToOneElement['field'], |
|
|
338 |
'targetEntity' => (string)$manyToOneElement['target-entity'] |
|
|
339 |
); |
|
|
340 |
|
|
|
341 |
if (isset($associationIds[$mapping['fieldName']])) { |
|
|
342 |
$mapping['id'] = true; |
|
|
343 |
} |
|
|
344 |
|
|
|
345 |
if (isset($manyToOneElement['fetch'])) { |
|
|
346 |
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string)$manyToOneElement['fetch']); |
|
|
347 |
} |
|
|
348 |
|
|
|
349 |
if (isset($manyToOneElement['inversed-by'])) { |
|
|
350 |
$mapping['inversedBy'] = (string)$manyToOneElement['inversed-by']; |
|
|
351 |
} |
|
|
352 |
|
|
|
353 |
$joinColumns = array(); |
|
|
354 |
|
|
|
355 |
if (isset($manyToOneElement->{'join-column'})) { |
|
|
356 |
$joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'}); |
|
|
357 |
} else if (isset($manyToOneElement->{'join-columns'})) { |
|
|
358 |
foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
|
359 |
$joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement); |
|
|
360 |
} |
|
|
361 |
} |
|
|
362 |
|
|
|
363 |
$mapping['joinColumns'] = $joinColumns; |
|
|
364 |
|
|
|
365 |
if (isset($manyToOneElement->cascade)) { |
|
|
366 |
$mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade); |
|
|
367 |
} |
|
|
368 |
|
|
|
369 |
if (isset($manyToOneElement->{'orphan-removal'})) { |
|
|
370 |
$mapping['orphanRemoval'] = (bool)$manyToOneElement->{'orphan-removal'}; |
|
|
371 |
} |
|
|
372 |
|
|
|
373 |
$metadata->mapManyToOne($mapping); |
|
|
374 |
} |
|
|
375 |
} |
|
|
376 |
|
|
|
377 |
// Evaluate <many-to-many ...> mappings |
|
|
378 |
if (isset($xmlRoot->{'many-to-many'})) { |
|
|
379 |
foreach ($xmlRoot->{'many-to-many'} as $manyToManyElement) { |
|
|
380 |
$mapping = array( |
|
|
381 |
'fieldName' => (string)$manyToManyElement['field'], |
|
|
382 |
'targetEntity' => (string)$manyToManyElement['target-entity'] |
|
|
383 |
); |
|
|
384 |
|
|
|
385 |
if (isset($manyToManyElement['fetch'])) { |
|
|
386 |
$mapping['fetch'] = constant('Doctrine\ORM\Mapping\ClassMetadata::FETCH_' . (string)$manyToManyElement['fetch']); |
|
|
387 |
} |
|
|
388 |
|
|
|
389 |
if (isset($manyToManyElement['mapped-by'])) { |
|
|
390 |
$mapping['mappedBy'] = (string)$manyToManyElement['mapped-by']; |
|
|
391 |
} else if (isset($manyToManyElement->{'join-table'})) { |
|
|
392 |
if (isset($manyToManyElement['inversed-by'])) { |
|
|
393 |
$mapping['inversedBy'] = (string)$manyToManyElement['inversed-by']; |
|
|
394 |
} |
|
|
395 |
|
|
|
396 |
$joinTableElement = $manyToManyElement->{'join-table'}; |
|
|
397 |
$joinTable = array( |
|
|
398 |
'name' => (string)$joinTableElement['name'] |
|
|
399 |
); |
|
|
400 |
|
|
|
401 |
if (isset($joinTableElement['schema'])) { |
|
|
402 |
$joinTable['schema'] = (string)$joinTableElement['schema']; |
|
|
403 |
} |
|
|
404 |
|
|
|
405 |
foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) { |
|
|
406 |
$joinTable['joinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); |
|
|
407 |
} |
|
|
408 |
|
|
|
409 |
foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) { |
|
|
410 |
$joinTable['inverseJoinColumns'][] = $this->_getJoinColumnMapping($joinColumnElement); |
|
|
411 |
} |
|
|
412 |
|
|
|
413 |
$mapping['joinTable'] = $joinTable; |
|
|
414 |
} |
|
|
415 |
|
|
|
416 |
if (isset($manyToManyElement->cascade)) { |
|
|
417 |
$mapping['cascade'] = $this->_getCascadeMappings($manyToManyElement->cascade); |
|
|
418 |
} |
|
|
419 |
|
|
|
420 |
if (isset($manyToManyElement->{'orphan-removal'})) { |
|
|
421 |
$mapping['orphanRemoval'] = (bool)$manyToManyElement->{'orphan-removal'}; |
|
|
422 |
} |
|
|
423 |
|
|
|
424 |
if (isset($manyToManyElement->{'order-by'})) { |
|
|
425 |
$orderBy = array(); |
|
|
426 |
foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} AS $orderByField) { |
|
|
427 |
$orderBy[(string)$orderByField['name']] = (string)$orderByField['direction']; |
|
|
428 |
} |
|
|
429 |
$mapping['orderBy'] = $orderBy; |
|
|
430 |
} |
|
|
431 |
|
|
|
432 |
if (isset($manyToManyElement->{'index-by'})) { |
|
|
433 |
$mapping['indexBy'] = (string)$manyToManyElement->{'index-by'}; |
|
|
434 |
} |
|
|
435 |
|
|
|
436 |
$metadata->mapManyToMany($mapping); |
|
|
437 |
} |
|
|
438 |
} |
|
|
439 |
|
|
|
440 |
// Evaluate <lifecycle-callbacks...> |
|
|
441 |
if (isset($xmlRoot->{'lifecycle-callbacks'})) { |
|
|
442 |
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { |
|
|
443 |
$metadata->addLifecycleCallback((string)$lifecycleCallback['method'], constant('Doctrine\ORM\Events::' . (string)$lifecycleCallback['type'])); |
|
|
444 |
} |
|
|
445 |
} |
|
|
446 |
} |
|
|
447 |
|
|
|
448 |
/** |
|
|
449 |
* Constructs a joinColumn mapping array based on the information |
|
|
450 |
* found in the given SimpleXMLElement. |
|
|
451 |
* |
|
|
452 |
* @param $joinColumnElement The XML element. |
|
|
453 |
* @return array The mapping array. |
|
|
454 |
*/ |
|
|
455 |
private function _getJoinColumnMapping(SimpleXMLElement $joinColumnElement) |
|
|
456 |
{ |
|
|
457 |
$joinColumn = array( |
|
|
458 |
'name' => (string)$joinColumnElement['name'], |
|
|
459 |
'referencedColumnName' => (string)$joinColumnElement['referenced-column-name'] |
|
|
460 |
); |
|
|
461 |
|
|
|
462 |
if (isset($joinColumnElement['unique'])) { |
|
|
463 |
$joinColumn['unique'] = ((string)$joinColumnElement['unique'] == "false") ? false : true; |
|
|
464 |
} |
|
|
465 |
|
|
|
466 |
if (isset($joinColumnElement['nullable'])) { |
|
|
467 |
$joinColumn['nullable'] = ((string)$joinColumnElement['nullable'] == "false") ? false : true; |
|
|
468 |
} |
|
|
469 |
|
|
|
470 |
if (isset($joinColumnElement['on-delete'])) { |
|
|
471 |
$joinColumn['onDelete'] = (string)$joinColumnElement['on-delete']; |
|
|
472 |
} |
|
|
473 |
|
|
|
474 |
if (isset($joinColumnElement['on-update'])) { |
|
|
475 |
$joinColumn['onUpdate'] = (string)$joinColumnElement['on-update']; |
|
|
476 |
} |
|
|
477 |
|
|
|
478 |
if (isset($joinColumnElement['column-definition'])) { |
|
|
479 |
$joinColumn['columnDefinition'] = (string)$joinColumnElement['column-definition']; |
|
|
480 |
} |
|
|
481 |
|
|
|
482 |
return $joinColumn; |
|
|
483 |
} |
|
|
484 |
|
|
|
485 |
/** |
|
|
486 |
* Gathers a list of cascade options found in the given cascade element. |
|
|
487 |
* |
|
|
488 |
* @param $cascadeElement The cascade element. |
|
|
489 |
* @return array The list of cascade options. |
|
|
490 |
*/ |
|
|
491 |
private function _getCascadeMappings($cascadeElement) |
|
|
492 |
{ |
|
|
493 |
$cascades = array(); |
|
|
494 |
foreach ($cascadeElement->children() as $action) { |
|
|
495 |
// According to the JPA specifications, XML uses "cascade-persist" |
|
|
496 |
// instead of "persist". Here, both variations |
|
|
497 |
// are supported because both YAML and Annotation use "persist" |
|
|
498 |
// and we want to make sure that this driver doesn't need to know |
|
|
499 |
// anything about the supported cascading actions |
|
|
500 |
$cascades[] = str_replace('cascade-', '', $action->getName()); |
|
|
501 |
} |
|
|
502 |
return $cascades; |
|
|
503 |
} |
|
|
504 |
|
|
|
505 |
/** |
|
|
506 |
* {@inheritdoc} |
|
|
507 |
*/ |
|
|
508 |
protected function _loadMappingFile($file) |
|
|
509 |
{ |
|
|
510 |
$result = array(); |
|
|
511 |
$xmlElement = simplexml_load_file($file); |
|
|
512 |
|
|
|
513 |
if (isset($xmlElement->entity)) { |
|
|
514 |
foreach ($xmlElement->entity as $entityElement) { |
|
|
515 |
$entityName = (string)$entityElement['name']; |
|
|
516 |
$result[$entityName] = $entityElement; |
|
|
517 |
} |
|
|
518 |
} else if (isset($xmlElement->{'mapped-superclass'})) { |
|
|
519 |
foreach ($xmlElement->{'mapped-superclass'} as $mappedSuperClass) { |
|
|
520 |
$className = (string)$mappedSuperClass['name']; |
|
|
521 |
$result[$className] = $mappedSuperClass; |
|
|
522 |
} |
|
|
523 |
} |
|
|
524 |
|
|
|
525 |
return $result; |
|
|
526 |
} |
|
|
527 |
} |