From fb3a06b9e7b0e34c2de172f0e03b8c685bc12a6e Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Wed, 13 Nov 2013 00:03:21 +0100 Subject: [PATCH] adds support for XML/Yaml drivers --- docs/en/tutorials/embeddables.rst | 12 ++++++------ lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 13 +++++++++++++ lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php | 12 ++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/docs/en/tutorials/embeddables.rst b/docs/en/tutorials/embeddables.rst index 3db2b47b0..5ec207fa6 100644 --- a/docs/en/tutorials/embeddables.rst +++ b/docs/en/tutorials/embeddables.rst @@ -43,14 +43,14 @@ instead of simply adding the respective columns to the ``User`` class. - + - - - - + + + + @@ -64,7 +64,7 @@ instead of simply adding the respective columns to the ``User`` class. Address: type: embeddable - columns: + fields: street: { type: string } postalCode: { type: string } city: { type: string } diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 6e024d041..3b8bf7e99 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -69,6 +69,8 @@ class XmlDriver extends FileDriver isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null ); $metadata->isMappedSuperclass = true; + } else if ($xmlRoot->getName() == 'embeddable') { + $metadata->isEmbeddedClass = true; } else { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); } @@ -241,6 +243,17 @@ class XmlDriver extends FileDriver } } + if (isset($xmlRoot->embedded)) { + foreach ($xmlRoot->embedded as $embeddedMapping) { + $mapping = array( + 'fieldName' => (string) $embeddedMapping['name'], + 'class' => (string) $embeddedMapping['class'], + 'columnPrefix' => isset($embeddedMapping['class']) ? (string) $embeddedMapping['class'] : null, + ); + $metadata->mapEmbedded($mapping); + } + } + foreach ($mappings as $mapping) { if (isset($mapping['version'])) { $metadata->setVersionMapping($mapping); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 1e7aa3356..9a1347649 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -66,6 +66,8 @@ class YamlDriver extends FileDriver isset($element['repositoryClass']) ? $element['repositoryClass'] : null ); $metadata->isMappedSuperclass = true; + } else if ($element['type'] == 'embeddable') { + $metadata->isEmbeddedClass = true; } else { throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); } @@ -311,6 +313,16 @@ class YamlDriver extends FileDriver } } + if (isset($element['embedded'])) { + foreach ($element['embedded'] as $name => $embeddedMapping) { + $mapping = array( + 'fieldName' => $name, + 'class' => $embeddedMapping['class'], + 'columnPrefix' => isset($embeddedMapping['columnPrefix']) ? $embeddedMapping['columnPrefix'] : null, + ); + $metadata->mapEmbedded($mapping); + } + } // Evaluate oneToOne relationships if (isset($element['oneToOne'])) {