1
0
mirror of synced 2025-01-18 06:21:40 +03:00

adds support for XML/Yaml drivers

This commit is contained in:
Johannes M. Schmitt 2013-11-13 00:03:21 +01:00
parent 9ad376c006
commit fb3a06b9e7
3 changed files with 31 additions and 6 deletions

View File

@ -43,14 +43,14 @@ instead of simply adding the respective columns to the ``User`` class.
<doctrine-mapping> <doctrine-mapping>
<entity name="User"> <entity name="User">
<embedded class="Address" /> <embedded name="address" class="Address" />
</entity> </entity>
<embeddable name="Address"> <embeddable name="Address">
<column name="street" type="string" /> <field name="street" type="string" />
<column name="postalCode" type="string" /> <field name="postalCode" type="string" />
<column name="city" type="string" /> <field name="city" type="string" />
<column name="country" type="string" /> <field name="country" type="string" />
</embeddable> </embeddable>
</doctrine-mapping> </doctrine-mapping>
@ -64,7 +64,7 @@ instead of simply adding the respective columns to the ``User`` class.
Address: Address:
type: embeddable type: embeddable
columns: fields:
street: { type: string } street: { type: string }
postalCode: { type: string } postalCode: { type: string }
city: { type: string } city: { type: string }

View File

@ -69,6 +69,8 @@ class XmlDriver extends FileDriver
isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null
); );
$metadata->isMappedSuperclass = true; $metadata->isMappedSuperclass = true;
} else if ($xmlRoot->getName() == 'embeddable') {
$metadata->isEmbeddedClass = true;
} else { } else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); 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) { foreach ($mappings as $mapping) {
if (isset($mapping['version'])) { if (isset($mapping['version'])) {
$metadata->setVersionMapping($mapping); $metadata->setVersionMapping($mapping);

View File

@ -66,6 +66,8 @@ class YamlDriver extends FileDriver
isset($element['repositoryClass']) ? $element['repositoryClass'] : null isset($element['repositoryClass']) ? $element['repositoryClass'] : null
); );
$metadata->isMappedSuperclass = true; $metadata->isMappedSuperclass = true;
} else if ($element['type'] == 'embeddable') {
$metadata->isEmbeddedClass = true;
} else { } else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className); 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 // Evaluate oneToOne relationships
if (isset($element['oneToOne'])) { if (isset($element['oneToOne'])) {