Failed Conditions
Push — master ( 9005c5...76e215 )
by Marco
64:47
created

XmlExporter::addClassToMapIfExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
crap 6
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 3
     */
42
    public function exportClassMetadata(ClassMetadataInfo $metadata)
43 3
    {
44
        $xml = new SimpleXmlElement('<?xml version="1.0" encoding="utf-8"?><doctrine-mapping ' .
45
            'xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" ' .
46 3
            'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' .
47
            'xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" />');
48 3
49
        if ($metadata->isMappedSuperclass) {
50
            $root = $xml->addChild('mapped-superclass');
51 3
        } else {
52
            $root = $xml->addChild('entity');
53
        }
54 3
55
        if ($metadata->customRepositoryClassName) {
56
            $root->addAttribute('repository-class', $metadata->customRepositoryClassName);
57
        }
58 3
59
        $root->addAttribute('name', $metadata->name);
60 3
61 1
        if (isset($metadata->table['name'])) {
62
            $root->addAttribute('table', $metadata->table['name']);
63
        }
64 3
65
        if (isset($metadata->table['schema'])) {
66
            $root->addAttribute('schema', $metadata->table['schema']);
67
        }
68 3
69
        if ($metadata->inheritanceType && $metadata->inheritanceType !== ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
70
            $root->addAttribute('inheritance-type', $this->_getInheritanceTypeString($metadata->inheritanceType));
71
        }
72 3
73 1
        if (isset($metadata->table['options'])) {
74
            $optionsXml = $root->addChild('options');
75 1
76
            $this->exportTableOptions($optionsXml, $metadata->table['options']);
77
        }
78 3
79
        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 3
89
        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 3
99
        $trackingPolicy = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy);
100 3
101
        if ( $trackingPolicy != 'DEFERRED_IMPLICIT') {
102
            $root->addChild('change-tracking-policy', $trackingPolicy);
103
        }
104 3
105
        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 3
118
        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 3
128
        $fields = $metadata->fieldMappings;
129 3
130 3
        $id = [];
131 3
        foreach ($fields as $name => $field) {
132 2
            if (isset($field['id']) && $field['id']) {
133 3
                $id[$name] = $field;
134
                unset($fields[$name]);
135
            }
136
        }
137 3
138 1
        foreach ($metadata->associationMappings as $name => $assoc) {
139
            if (isset($assoc['id']) && $assoc['id']) {
140 1
                $id[$name] = [
141
                    'fieldName' => $name,
142
                    'associationKey' => true
143
                ];
144
            }
145
        }
146 3
147 2 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
            $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType;
149
        }
150 3
151 2
        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
                $idXml->addAttribute('name', $field['fieldName']);
155 2
156 2
                if (isset($field['type'])) {
157
                    $idXml->addAttribute('type', $field['type']);
158
                }
159 2
160 2
                if (isset($field['columnName'])) {
161
                    $idXml->addAttribute('column', $field['columnName']);
162
                }
163 2
164
                if (isset($field['length'])) {
165
                    $idXml->addAttribute('length', $field['length']);
166
                }
167 2
168
                if (isset($field['associationKey']) && $field['associationKey']) {
169
                    $idXml->addAttribute('association-key', 'true');
170
                }
171 2
172 2
                if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
173 2
                    $generatorXml = $idXml->addChild('generator');
174
                    $generatorXml->addAttribute('strategy', $idGeneratorType);
175 2
176
                    $this->exportSequenceInformation($idXml, $metadata);
177
                }
178
            }
179
        }
180 3
181 2
        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
                $fieldXml->addAttribute('type', $field['type']);
186 2
187 2
                if (isset($field['columnName'])) {
188
                    $fieldXml->addAttribute('column', $field['columnName']);
189
                }
190 2
191 1
                if (isset($field['length'])) {
192
                    $fieldXml->addAttribute('length', $field['length']);
193
                }
194 2
195
                if (isset($field['precision'])) {
196
                    $fieldXml->addAttribute('precision', $field['precision']);
197
                }
198 2
199
                if (isset($field['scale'])) {
200
                    $fieldXml->addAttribute('scale', $field['scale']);
201
                }
202 2
203 1
                if (isset($field['unique']) && $field['unique']) {
204
                    $fieldXml->addAttribute('unique', $field['unique'] ? 'true' : 'false');
205
                }
206 2
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
                        $optionXml->addAttribute('name', $key);
212
                    }
213
                }
214 2
215
                if (isset($field['version'])) {
216
                    $fieldXml->addAttribute('version', $field['version']);
217
                }
218 2
219 1
                if (isset($field['columnDefinition'])) {
220
                    $fieldXml->addAttribute('column-definition', $field['columnDefinition']);
221
                }
222 2
223 2
                if (isset($field['nullable'])) {
224
                    $fieldXml->addAttribute('nullable', $field['nullable'] ? 'true' : 'false');
225
                }
226
            }
227
        }
228
229 3
        $orderMap = [
230
            ClassMetadataInfo::ONE_TO_ONE,
231
            ClassMetadataInfo::ONE_TO_MANY,
232
            ClassMetadataInfo::MANY_TO_ONE,
233
            ClassMetadataInfo::MANY_TO_MANY,
234
        ];
235 3
236 1
        uasort($metadata->associationMappings, function($m1, $m2) use (&$orderMap){
237 1
            $a1 = array_search($m1['type'], $orderMap);
238
            $a2 = array_search($m2['type'], $orderMap);
239 1
240 3
            return strcmp($a1, $a2);
241
        });
242 3
243 1
        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
                $associationMappingXml = $root->addChild('many-to-many');
253
            }
254 1
255 1
            $associationMappingXml->addAttribute('field', $associationMapping['fieldName']);
256
            $associationMappingXml->addAttribute('target-entity', $associationMapping['targetEntity']);
257 1
258 1
            if (isset($associationMapping['mappedBy'])) {
259
                $associationMappingXml->addAttribute('mapped-by', $associationMapping['mappedBy']);
260
            }
261 1
262 1
            if (isset($associationMapping['inversedBy'])) {
263
                $associationMappingXml->addAttribute('inversed-by', $associationMapping['inversedBy']);
264
            }
265 1
266
            if (isset($associationMapping['indexBy'])) {
267
                $associationMappingXml->addAttribute('index-by', $associationMapping['indexBy']);
268
            }
269 1
270 1
            if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval'] !== false) {
271
                $associationMappingXml->addAttribute('orphan-removal', 'true');
272
            }
273 1
274 1
            if (isset($associationMapping['fetch'])) {
275
                $associationMappingXml->addAttribute('fetch', $this->_getFetchModeString($associationMapping['fetch']));
276
            }
277 1
278 1
            $cascade = [];
279 1
            if ($associationMapping['isCascadeRemove']) {
280
                $cascade[] = 'cascade-remove';
281
            }
282 1
283 1
            if ($associationMapping['isCascadePersist']) {
284
                $cascade[] = 'cascade-persist';
285
            }
286 1
287 1
            if ($associationMapping['isCascadeRefresh']) {
288
                $cascade[] = 'cascade-refresh';
289
            }
290 1
291 1
            if ($associationMapping['isCascadeMerge']) {
292
                $cascade[] = 'cascade-merge';
293
            }
294 1
295 1
            if ($associationMapping['isCascadeDetach']) {
296
                $cascade[] = 'cascade-detach';
297
            }
298 1
299 1
            if (count($cascade) === 5) {
300
                $cascade  = ['cascade-all'];
301
            }
302 1
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
                $cascadeXml = $associationMappingXml->addChild('cascade');
305 1
306 1
                foreach ($cascade as $type) {
307
                    $cascadeXml->addChild($type);
308
                }
309
            }
310 1
311 1
            if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) {
312 1
                $joinTableXml = $associationMappingXml->addChild('join-table');
313 1
                $joinTableXml->addAttribute('name', $associationMapping['joinTable']['name']);
314
                $joinColumnsXml = $joinTableXml->addChild('join-columns');
315 1
316 1
                foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) {
317 1
                    $joinColumnXml = $joinColumnsXml->addChild('join-column');
318 1
                    $joinColumnXml->addAttribute('name', $joinColumn['name']);
319
                    $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']);
320 1
321 1
                    if (isset($joinColumn['onDelete'])) {
322
                        $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']);
323
                    }
324
                }
325 1
326
                $inverseJoinColumnsXml = $joinTableXml->addChild('inverse-join-columns');
327 1
328 1
                foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $inverseJoinColumn) {
329 1
                    $inverseJoinColumnXml = $inverseJoinColumnsXml->addChild('join-column');
330 1
                    $inverseJoinColumnXml->addAttribute('name', $inverseJoinColumn['name']);
331
                    $inverseJoinColumnXml->addAttribute('referenced-column-name', $inverseJoinColumn['referencedColumnName']);
332 1
333
                    if (isset($inverseJoinColumn['onDelete'])) {
334
                        $inverseJoinColumnXml->addAttribute('on-delete', $inverseJoinColumn['onDelete']);
335
                    }
336 1
337 1
                    if (isset($inverseJoinColumn['columnDefinition'])) {
338
                        $inverseJoinColumnXml->addAttribute('column-definition', $inverseJoinColumn['columnDefinition']);
339
                    }
340 1
341
                    if (isset($inverseJoinColumn['nullable'])) {
342
                        $inverseJoinColumnXml->addAttribute('nullable', $inverseJoinColumn['nullable']);
343
                    }
344 1
345 1
                    if (isset($inverseJoinColumn['orderBy'])) {
346
                        $inverseJoinColumnXml->addAttribute('order-by', $inverseJoinColumn['orderBy']);
347
                    }
348
                }
349 1
            }
350 1
            if (isset($associationMapping['joinColumns'])) {
351
                $joinColumnsXml = $associationMappingXml->addChild('join-columns');
352 1
353 1
                foreach ($associationMapping['joinColumns'] as $joinColumn) {
354 1
                    $joinColumnXml = $joinColumnsXml->addChild('join-column');
355 1
                    $joinColumnXml->addAttribute('name', $joinColumn['name']);
356
                    $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']);
357 1
358 1
                    if (isset($joinColumn['onDelete'])) {
359
                        $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']);
360
                    }
361 1
362
                    if (isset($joinColumn['columnDefinition'])) {
363
                        $joinColumnXml->addAttribute('column-definition', $joinColumn['columnDefinition']);
364
                    }
365 1
366 1
                    if (isset($joinColumn['nullable'])) {
367
                        $joinColumnXml->addAttribute('nullable', $joinColumn['nullable']);
368
                    }
369
                }
370 1
            }
371 1
            if (isset($associationMapping['orderBy'])) {
372
                $orderByXml = $associationMappingXml->addChild('order-by');
373 1
374 1
                foreach ($associationMapping['orderBy'] as $name => $direction) {
375 1
                    $orderByFieldXml = $orderByXml->addChild('order-by-field');
376 1
                    $orderByFieldXml->addAttribute('name', $name);
377
                    $orderByFieldXml->addAttribute('direction', $direction);
378
                }
379
            }
380
        }
381 3
382 1
        if (isset($metadata->lifecycleCallbacks) && count($metadata->lifecycleCallbacks)>0) {
383
            $lifecycleCallbacksXml = $root->addChild('lifecycle-callbacks');
384 1
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
                    $lifecycleCallbackXml->addAttribute('method', $method);
390
                }
391
            }
392
        }
393 3
394
        $this->processEntityListeners($metadata, $root);
395
396
        return $this->_asXml($xml);
397
    }
398
399
    /**
400
     * Exports (nested) option elements.
401
     *
402 1
     * @param SimpleXMLElement $parentXml
403
     * @param array            $options
404 1
     */
405 1
    private function exportTableOptions(SimpleXMLElement $parentXml, array $options) : void
406 1
    {
407 1
        foreach ($options as $name => $option) {
408 1
            $isArray   = is_array($option);
409
            $optionXml = $isArray
410 1
                ? $parentXml->addChild('option')
411
                : $parentXml->addChild('option', (string) $option);
412 1
413 1
            $optionXml->addAttribute('name', (string) $name);
414
415
            if ($isArray) {
416 1
                $this->exportTableOptions($optionXml, $option);
417
            }
418
        }
419
    }
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 2
     *
427
     * @return void
428 2
     */
429
    private function exportSequenceInformation(SimpleXMLElement $identifierXmlNode, ClassMetadataInfo $metadata) : void
430 2
    {
431 1
        $sequenceDefinition = $metadata->sequenceGeneratorDefinition;
432
433
        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 1
437 1
        $sequenceGeneratorXml = $identifierXmlNode->addChild('sequence-generator');
438 1
439 1
        $sequenceGeneratorXml->addAttribute('sequence-name', $sequenceDefinition['sequenceName']);
440
        $sequenceGeneratorXml->addAttribute('allocation-size', $sequenceDefinition['allocationSize']);
441
        $sequenceGeneratorXml->addAttribute('initial-value', $sequenceDefinition['initialValue']);
442
    }
443
444
    private function _asXml(SimpleXMLElement $simpleXml) : string
445
    {
446 3
        $dom = new \DOMDocument('1.0', 'UTF-8');
447
        $dom->loadXML($simpleXml->asXML());
448 3
        $dom->formatOutput = true;
449 3
450 3
        return $dom->saveXML();
451
    }
452 3
453
    private function processEntityListeners(ClassMetadataInfo $metadata, SimpleXMLElement $root): void
454
    {
455
        if (0 === \count($metadata->entityListeners)) {
456
            return;
457
        }
458
459
        $entityListenersXml = $root->addChild('entity-listeners');
460
        $entityListenersXmlMap = [];
461
462
        $this->generateEntityListenerXml($metadata, $entityListenersXmlMap, $entityListenersXml);
463
    }
464
465
    private function generateEntityListenerXml(ClassMetadataInfo $metadata, array $entityListenersXmlMap, SimpleXMLElement $entityListenersXml): void
466
    {
467
        foreach ($metadata->entityListeners as $event => $entityListenerConfig) {
468
            foreach ($entityListenerConfig as $entityListener) {
469
                $entityListenerXml = $this->addClassToMapIfExists(
470
                    $entityListenersXmlMap,
471
                    $entityListener,
472
                    $entityListenersXml
473
                );
474
475
                $entityListenerCallbackXml = $entityListenerXml->addChild('lifecycle-callback');
476
                $entityListenerCallbackXml->addAttribute('type', $event);
477
                $entityListenerCallbackXml->addAttribute('method', $entityListener['method']);
478
            }
479
        }
480
    }
481
482
    private function addClassToMapIfExists(array $entityListenersXmlMap, array $entityListener, SimpleXMLElement $entityListenersXml): SimpleXMLElement
483
    {
484
        if (isset($entityListenersXmlMap[$entityListener['class']])) {
485
            return $entityListenersXmlMap[$entityListener['class']];
486
        }
487
488
        $entityListenerXml = $entityListenersXml->addChild('entity-listener');
489
        $entityListenerXml->addAttribute('class', $entityListener['class']);
490
        $entityListenersXmlMap[$entityListener['class']] = $entityListenerXml;
491
492
        return $entityListenerXml;
493
    }
494
}
495