From 85a16f9f28b33111139443d0047175dfb245506d Mon Sep 17 00:00:00 2001 From: Menno Holtkamp Date: Sun, 5 Jan 2014 15:34:59 +0100 Subject: [PATCH] Ensure elements preceed When converting annotations based metadata to XML, the position of the elements resulted in XSD validation errors caused by the definitions of the association ComplexTypes: - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L463 - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L482 - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L495 - https://github.com/doctrine/doctrine2/blob/master/doctrine-mapping.xsd#L517 Since changing the XSD might result in validation problems in existing mappings, changing the XmlExporter seems a better approach. Note that the '' element is not yet generated by the XmlExporter, but according to the XML Schema, it should precede the '' element. --- .../ORM/Tools/Export/Driver/XmlExporter.php | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php index 1a8fde184..c7b13c725 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/XmlExporter.php @@ -260,6 +260,39 @@ class XmlExporter extends AbstractExporter if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval'] !== false) { $associationMappingXml->addAttribute('orphan-removal', 'true'); } + + $cascade = array(); + if ($associationMapping['isCascadeRemove']) { + $cascade[] = 'cascade-remove'; + } + + if ($associationMapping['isCascadePersist']) { + $cascade[] = 'cascade-persist'; + } + + if ($associationMapping['isCascadeRefresh']) { + $cascade[] = 'cascade-refresh'; + } + + if ($associationMapping['isCascadeMerge']) { + $cascade[] = 'cascade-merge'; + } + + if ($associationMapping['isCascadeDetach']) { + $cascade[] = 'cascade-detach'; + } + + if (count($cascade) === 5) { + $cascade = array('cascade-all'); + } + + if ($cascade) { + $cascadeXml = $associationMappingXml->addChild('cascade'); + + foreach ($cascade as $type) { + $cascadeXml->addChild($type); + } + } if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) { $joinTableXml = $associationMappingXml->addChild('join-table'); @@ -330,39 +363,6 @@ class XmlExporter extends AbstractExporter $orderByFieldXml->addAttribute('direction', $direction); } } - $cascade = array(); - - if ($associationMapping['isCascadeRemove']) { - $cascade[] = 'cascade-remove'; - } - - if ($associationMapping['isCascadePersist']) { - $cascade[] = 'cascade-persist'; - } - - if ($associationMapping['isCascadeRefresh']) { - $cascade[] = 'cascade-refresh'; - } - - if ($associationMapping['isCascadeMerge']) { - $cascade[] = 'cascade-merge'; - } - - if ($associationMapping['isCascadeDetach']) { - $cascade[] = 'cascade-detach'; - } - - if (count($cascade) === 5) { - $cascade = array('cascade-all'); - } - - if ($cascade) { - $cascadeXml = $associationMappingXml->addChild('cascade'); - - foreach ($cascade as $type) { - $cascadeXml->addChild($type); - } - } } if (isset($metadata->lifecycleCallbacks) && count($metadata->lifecycleCallbacks)>0) {