Failed Conditions
Pull Request — master (#6593)
by Thomas
16:12
created

XmlExporter::exportClassMetadata()   F

Complexity

Conditions 88
Paths > 20000

Size

Total Lines 356
Code Lines 203

Duplication

Lines 3
Ratio 0.84 %

Code Coverage

Tests 159
CRAP Score 140.116

Importance

Changes 0
Metric Value
dl 3
loc 356
ccs 159
cts 196
cp 0.8112
rs 2
c 0
b 0
f 0
cc 88
eloc 203
nc 4294967295
nop 1
crap 140.116

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Tools\Export\Driver;
21
22
use Doctrine\ORM\Mapping\ClassMetadataInfo;
23
use SimpleXMLElement;
24
25
/**
26
 * ClassMetadata exporter for Doctrine XML mapping files.
27
 *
28
 * @link    www.doctrine-project.org
29
 * @since   2.0
30
 * @author  Jonathan Wage <[email protected]>
31
 */
32
class XmlExporter extends AbstractExporter
33
{
34
    /**
35
     * @var string
36
     */
37
    protected $_extension = '.dcm.xml';
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 3
    public function exportClassMetadata(ClassMetadataInfo $metadata): string
43
    {
44 3
        $xml = new SimpleXmlElement('<?xml version="1.0" encoding="utf-8"?><doctrine-mapping ' .
45
            'xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" ' .
46
            'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' .
47 3
            'xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" />');
48
49 3
        if ($metadata->isMappedSuperclass) {
50
            $root = $xml->addChild('mapped-superclass');
51
        } else {
52 3
            $root = $xml->addChild('entity');
53
        }
54
55 3
        if ($metadata->customRepositoryClassName) {
56
            $root->addAttribute('repository-class', $metadata->customRepositoryClassName);
57
        }
58
59 3
        $root->addAttribute('name', $metadata->name);
60
61 3
        if (isset($metadata->table['name'])) {
62 1
            $root->addAttribute('table', $metadata->table['name']);
63
        }
64
65 3
        if (isset($metadata->table['schema'])) {
66
            $root->addAttribute('schema', $metadata->table['schema']);
67
        }
68
69 3
        if ($metadata->inheritanceType && $metadata->inheritanceType !== ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
70
            $root->addAttribute('inheritance-type', $this->_getInheritanceTypeString($metadata->inheritanceType));
71
        }
72
73 3
        if (isset($metadata->table['options'])) {
74 1
            $optionsXml = $root->addChild('options');
75
76 1
            $this->exportTableOptions($optionsXml, $metadata->table['options']);
77
        }
78
79 3
        if ($metadata->discriminatorColumn) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $metadata->discriminatorColumn of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
80
            $discriminatorColumnXml = $root->addChild('discriminator-column');
81
            $discriminatorColumnXml->addAttribute('name', $metadata->discriminatorColumn['name']);
82
            $discriminatorColumnXml->addAttribute('type', $metadata->discriminatorColumn['type']);
83
84
            if (isset($metadata->discriminatorColumn['length'])) {
85
                $discriminatorColumnXml->addAttribute('length', $metadata->discriminatorColumn['length']);
86
            }
87
        }
88
89 3
        if ($metadata->discriminatorMap) {
90
            $discriminatorMapXml = $root->addChild('discriminator-map');
91
92
            foreach ($metadata->discriminatorMap as $value => $className) {
93
                $discriminatorMappingXml = $discriminatorMapXml->addChild('discriminator-mapping');
94
                $discriminatorMappingXml->addAttribute('value', $value);
95
                $discriminatorMappingXml->addAttribute('class', $className);
96
            }
97
        }
98
99 3
        $trackingPolicy = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy);
100
101 3
        if ( $trackingPolicy != 'DEFERRED_IMPLICIT') {
102
            $root->addChild('change-tracking-policy', $trackingPolicy);
103
        }
104
105 3
        if (isset($metadata->table['indexes'])) {
106
            $indexesXml = $root->addChild('indexes');
107
108
            foreach ($metadata->table['indexes'] as $name => $index) {
109
                $indexXml = $indexesXml->addChild('index');
110
                $indexXml->addAttribute('name', $name);
111
                $indexXml->addAttribute('columns', implode(',', $index['columns']));
112
                if (isset($index['flags'])) {
113
                    $indexXml->addAttribute('flags', implode(',', $index['flags']));
114
                }
115
            }
116
        }
117
118 3
        if (isset($metadata->table['uniqueConstraints'])) {
119
            $uniqueConstraintsXml = $root->addChild('unique-constraints');
120
121
            foreach ($metadata->table['uniqueConstraints'] as $name => $unique) {
122
                $uniqueConstraintXml = $uniqueConstraintsXml->addChild('unique-constraint');
123
                $uniqueConstraintXml->addAttribute('name', $name);
124
                $uniqueConstraintXml->addAttribute('columns', implode(',', $unique['columns']));
125
            }
126
        }
127
128 3
        $fields = $metadata->fieldMappings;
129
130 3
        $id = [];
131 3
        foreach ($fields as $name => $field) {
132 3
            if (isset($field['id']) && $field['id']) {
133 2
                $id[$name] = $field;
134 3
                unset($fields[$name]);
135
            }
136
        }
137
138 3
        foreach ($metadata->associationMappings as $name => $assoc) {
139 1
            if (isset($assoc['id']) && $assoc['id']) {
140
                $id[$name] = [
141 1
                    'fieldName' => $name,
142
                    'associationKey' => true
143
                ];
144
            }
145
        }
146
147 3 View Code Duplication
        if ( ! $metadata->isIdentifierComposite && $idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148 2
            $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType;
149
        }
150
151 3
        if ($id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $id of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
152 2
            foreach ($id as $field) {
153 2
                $idXml = $root->addChild('id');
154 2
                $idXml->addAttribute('name', $field['fieldName']);
155
156 2
                if (isset($field['type'])) {
157 2
                    $idXml->addAttribute('type', $field['type']);
158
                }
159
160 2
                if (isset($field['columnName'])) {
161 2
                    $idXml->addAttribute('column', $field['columnName']);
162
                }
163
164 2
                if (isset($field['length'])) {
165
                    $idXml->addAttribute('length', $field['length']);
166
                }
167
168 2
                if (isset($field['associationKey']) && $field['associationKey']) {
169
                    $idXml->addAttribute('association-key', 'true');
170
                }
171
172 2
                if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
173 2
                    $generatorXml = $idXml->addChild('generator');
174 2
                    $generatorXml->addAttribute('strategy', $idGeneratorType);
175
176 2
                    $this->exportSequenceInformation($idXml, $metadata);
177
                }
178
            }
179
        }
180
181 3
        if ($fields) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $fields of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
182 2
            foreach ($fields as $field) {
183 2
                $fieldXml = $root->addChild('field');
184 2
                $fieldXml->addAttribute('name', $field['fieldName']);
185 2
                $fieldXml->addAttribute('type', $field['type']);
186
187 2
                if (isset($field['columnName'])) {
188 2
                    $fieldXml->addAttribute('column', $field['columnName']);
189
                }
190
191 2
                if (isset($field['length'])) {
192 1
                    $fieldXml->addAttribute('length', $field['length']);
193
                }
194
195 2
                if (isset($field['precision'])) {
196
                    $fieldXml->addAttribute('precision', $field['precision']);
197
                }
198
199 2
                if (isset($field['scale'])) {
200
                    $fieldXml->addAttribute('scale', $field['scale']);
201
                }
202
203 2
                if (isset($field['unique']) && $field['unique']) {
204 1
                    $fieldXml->addAttribute('unique', $field['unique'] ? 'true' : 'false');
205
                }
206
207 2
                if (isset($field['options'])) {
208 2
                    $optionsXml = $fieldXml->addChild('options');
209 2
                    foreach ($field['options'] as $key => $value) {
210 2
                        $optionXml = $optionsXml->addChild('option', $value);
211 2
                        $optionXml->addAttribute('name', $key);
212
                    }
213
                }
214
215 2
                if (isset($field['version'])) {
216
                    $fieldXml->addAttribute('version', $field['version']);
217
                }
218
219 2
                if (isset($field['columnDefinition'])) {
220 1
                    $fieldXml->addAttribute('column-definition', $field['columnDefinition']);
221
                }
222
223 2
                if (isset($field['nullable'])) {
224 2
                    $fieldXml->addAttribute('nullable', $field['nullable'] ? 'true' : 'false');
225
                }
226
            }
227
        }
228
229
        $orderMap = [
230 3
            ClassMetadataInfo::ONE_TO_ONE,
231
            ClassMetadataInfo::ONE_TO_MANY,
232
            ClassMetadataInfo::MANY_TO_ONE,
233
            ClassMetadataInfo::MANY_TO_MANY,
234
        ];
235
236 3
        uasort($metadata->associationMappings, function($m1, $m2) use (&$orderMap){
237 1
            $a1 = array_search($m1['type'], $orderMap);
238 1
            $a2 = array_search($m2['type'], $orderMap);
239
240 1
            return strcmp($a1, $a2);
241 3
        });
242
243 3
        foreach ($metadata->associationMappings as $associationMapping) {
244 1
            $associationMappingXml = null;
245 1
            if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) {
246 1
                $associationMappingXml = $root->addChild('one-to-one');
247 1
            } elseif ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) {
248 1
                $associationMappingXml = $root->addChild('many-to-one');
249 1
            } elseif ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) {
250 1
                $associationMappingXml = $root->addChild('one-to-many');
251 1
            } elseif ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) {
252 1
                $associationMappingXml = $root->addChild('many-to-many');
253
            }
254
255 1
            $associationMappingXml->addAttribute('field', $associationMapping['fieldName']);
256 1
            $associationMappingXml->addAttribute('target-entity', $associationMapping['targetEntity']);
257
258 1
            if (isset($associationMapping['mappedBy'])) {
259 1
                $associationMappingXml->addAttribute('mapped-by', $associationMapping['mappedBy']);
260
            }
261
262 1
            if (isset($associationMapping['inversedBy'])) {
263 1
                $associationMappingXml->addAttribute('inversed-by', $associationMapping['inversedBy']);
264
            }
265
266 1
            if (isset($associationMapping['indexBy'])) {
267
                $associationMappingXml->addAttribute('index-by', $associationMapping['indexBy']);
268
            }
269
270 1
            if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval'] !== false) {
271 1
                $associationMappingXml->addAttribute('orphan-removal', 'true');
272
            }
273
274 1
            if (isset($associationMapping['fetch'])) {
275 1
                $associationMappingXml->addAttribute('fetch', $this->_getFetchModeString($associationMapping['fetch']));
276
            }
277
278 1
            $cascade = [];
279 1
            if ($associationMapping['isCascadeRemove']) {
280 1
                $cascade[] = 'cascade-remove';
281
            }
282
283 1
            if ($associationMapping['isCascadePersist']) {
284 1
                $cascade[] = 'cascade-persist';
285
            }
286
287 1
            if ($associationMapping['isCascadeRefresh']) {
288 1
                $cascade[] = 'cascade-refresh';
289
            }
290
291 1
            if ($associationMapping['isCascadeMerge']) {
292 1
                $cascade[] = 'cascade-merge';
293
            }
294
295 1
            if ($associationMapping['isCascadeDetach']) {
296 1
                $cascade[] = 'cascade-detach';
297
            }
298
299 1
            if (count($cascade) === 5) {
300 1
                $cascade  = ['cascade-all'];
301
            }
302
303 1
            if ($cascade) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $cascade of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
304 1
                $cascadeXml = $associationMappingXml->addChild('cascade');
305
306 1
                foreach ($cascade as $type) {
307 1
                    $cascadeXml->addChild($type);
308
                }
309
            }
310
311 1
            if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) {
312 1
                $joinTableXml = $associationMappingXml->addChild('join-table');
313 1
                $joinTableXml->addAttribute('name', $associationMapping['joinTable']['name']);
314 1
                $joinColumnsXml = $joinTableXml->addChild('join-columns');
315
316 1
                foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) {
317 1
                    $joinColumnXml = $joinColumnsXml->addChild('join-column');
318 1
                    $joinColumnXml->addAttribute('name', $joinColumn['name']);
319 1
                    $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']);
320
321 1
                    if (isset($joinColumn['onDelete'])) {
322 1
                        $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']);
323
                    }
324
                }
325
326 1
                $inverseJoinColumnsXml = $joinTableXml->addChild('inverse-join-columns');
327
328 1
                foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $inverseJoinColumn) {
329 1
                    $inverseJoinColumnXml = $inverseJoinColumnsXml->addChild('join-column');
330 1
                    $inverseJoinColumnXml->addAttribute('name', $inverseJoinColumn['name']);
331 1
                    $inverseJoinColumnXml->addAttribute('referenced-column-name', $inverseJoinColumn['referencedColumnName']);
332
333 1
                    if (isset($inverseJoinColumn['onDelete'])) {
334
                        $inverseJoinColumnXml->addAttribute('on-delete', $inverseJoinColumn['onDelete']);
335
                    }
336
337 1
                    if (isset($inverseJoinColumn['columnDefinition'])) {
338 1
                        $inverseJoinColumnXml->addAttribute('column-definition', $inverseJoinColumn['columnDefinition']);
339
                    }
340
341 1
                    if (isset($inverseJoinColumn['nullable'])) {
342
                        $inverseJoinColumnXml->addAttribute('nullable', $inverseJoinColumn['nullable']);
343
                    }
344
345 1
                    if (isset($inverseJoinColumn['orderBy'])) {
346 1
                        $inverseJoinColumnXml->addAttribute('order-by', $inverseJoinColumn['orderBy']);
347
                    }
348
                }
349
            }
350 1
            if (isset($associationMapping['joinColumns'])) {
351 1
                $joinColumnsXml = $associationMappingXml->addChild('join-columns');
352
353 1
                foreach ($associationMapping['joinColumns'] as $joinColumn) {
354 1
                    $joinColumnXml = $joinColumnsXml->addChild('join-column');
355 1
                    $joinColumnXml->addAttribute('name', $joinColumn['name']);
356 1
                    $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']);
357
358 1
                    if (isset($joinColumn['onDelete'])) {
359 1
                        $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']);
360
                    }
361
362 1
                    if (isset($joinColumn['columnDefinition'])) {
363
                        $joinColumnXml->addAttribute('column-definition', $joinColumn['columnDefinition']);
364
                    }
365
366 1
                    if (isset($joinColumn['nullable'])) {
367 1
                        $joinColumnXml->addAttribute('nullable', $joinColumn['nullable']);
368
                    }
369
                }
370
            }
371 1
            if (isset($associationMapping['orderBy'])) {
372 1
                $orderByXml = $associationMappingXml->addChild('order-by');
373
374 1
                foreach ($associationMapping['orderBy'] as $name => $direction) {
375 1
                    $orderByFieldXml = $orderByXml->addChild('order-by-field');
376 1
                    $orderByFieldXml->addAttribute('name', $name);
377 1
                    $orderByFieldXml->addAttribute('direction', $direction);
378
                }
379
            }
380
        }
381
382 3
        if (isset($metadata->lifecycleCallbacks) && count($metadata->lifecycleCallbacks)>0) {
383 1
            $lifecycleCallbacksXml = $root->addChild('lifecycle-callbacks');
384
385 1
            foreach ($metadata->lifecycleCallbacks as $name => $methods) {
386 1
                foreach ($methods as $method) {
387 1
                    $lifecycleCallbackXml = $lifecycleCallbacksXml->addChild('lifecycle-callback');
388 1
                    $lifecycleCallbackXml->addAttribute('type', $name);
389 1
                    $lifecycleCallbackXml->addAttribute('method', $method);
390
                }
391
            }
392
        }
393
394 3
        $this->processEntityListeners($metadata, $root);
395
396 3
        return $this->_asXml($xml);
397
    }
398
399
    /**
400
     * Exports (nested) option elements.
401
     *
402
     * @param SimpleXMLElement $parentXml
403
     * @param array            $options
404
     */
405 1
    private function exportTableOptions(SimpleXMLElement $parentXml, array $options): void
406
    {
407 1
        foreach ($options as $name => $option) {
408 1
            $isArray   = is_array($option);
409 1
            $optionXml = $isArray
410 1
                ? $parentXml->addChild('option')
411 1
                : $parentXml->addChild('option', (string) $option);
412
413 1
            $optionXml->addAttribute('name', (string) $name);
414
415 1
            if ($isArray) {
416 1
                $this->exportTableOptions($optionXml, $option);
417
            }
418
        }
419 1
    }
420
421
    /**
422
     * Export sequence information (if available/configured) into the current identifier XML node
423
     *
424
     * @param SimpleXMLElement  $identifierXmlNode
425
     * @param ClassMetadataInfo $metadata
426
     *
427
     * @return void
428
     */
429 2
    private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata): void
430
    {
431 2
        $sequenceDefinition = $metadata->sequenceGeneratorDefinition;
432
433 2
        if (! ($metadata->generatorType === ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE && $sequenceDefinition)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sequenceDefinition of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
434 1
            return;
435
        }
436
437 1
        $sequenceGeneratorXml = $identifierXmlNode->addChild('sequence-generator');
438
439 1
        $sequenceGeneratorXml->addAttribute('sequence-name', $sequenceDefinition['sequenceName']);
440 1
        $sequenceGeneratorXml->addAttribute('allocation-size', $sequenceDefinition['allocationSize']);
441 1
        $sequenceGeneratorXml->addAttribute('initial-value', $sequenceDefinition['initialValue']);
442 1
    }
443
444 3
    private function _asXml(SimpleXMLElement $simpleXml): string
445
    {
446 3
        $dom = new \DOMDocument('1.0', 'UTF-8');
447 3
        $dom->loadXML($simpleXml->asXML());
448 3
        $dom->formatOutput = true;
449
450 3
        return $dom->saveXML();
451
    }
452
453 3
    private function processEntityListeners(ClassMetadataInfo $metadata, SimpleXMLElement $root): void
454
    {
455 3
        if (0 === \count($metadata->entityListeners)) {
456 2
            return;
457
        }
458
459 1
        $entityListenersXml = $root->addChild('entity-listeners');
460 1
        $entityListenersXmlMap = [];
461
462 1
        $this->generateEntityListenerXml($metadata, $entityListenersXmlMap, $entityListenersXml);
463 1
    }
464
465 1
    private function generateEntityListenerXml(ClassMetadataInfo $metadata, array $entityListenersXmlMap, SimpleXMLElement $entityListenersXml): void
466
    {
467 1
        foreach ($metadata->entityListeners as $event => $entityListenerConfig) {
468 1
            foreach ($entityListenerConfig as $entityListener) {
469 1
                $entityListenerXml = $this->addClassToMapIfExists(
470 1
                    $entityListenersXmlMap,
471 1
                    $entityListener,
472 1
                    $entityListenersXml
473
                );
474
475 1
                $entityListenerCallbackXml = $entityListenerXml->addChild('lifecycle-callback');
476 1
                $entityListenerCallbackXml->addAttribute('type', $event);
477 1
                $entityListenerCallbackXml->addAttribute('method', $entityListener['method']);
478
            }
479
        }
480 1
    }
481
482 1
    private function addClassToMapIfExists(array $entityListenersXmlMap, array $entityListener, SimpleXMLElement $entityListenersXml): SimpleXMLElement
483
    {
484 1
        if (isset($entityListenersXmlMap[$entityListener['class']])) {
485
            return $entityListenersXmlMap[$entityListener['class']];
486
        }
487
488 1
        $entityListenerXml = $entityListenersXml->addChild('entity-listener');
489 1
        $entityListenerXml->addAttribute('class', $entityListener['class']);
490 1
        $entityListenersXmlMap[$entityListener['class']] = $entityListenerXml;
491
492 1
        return $entityListenerXml;
493
    }
494
}
495