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