1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Add support for custom ID generator in XML

This commit is contained in:
Vitali Yakavenka 2011-11-28 21:41:54 +03:00
parent 6bcfaed640
commit 2b97f79bd3
4 changed files with 46 additions and 0 deletions

View File

@ -143,6 +143,7 @@
<xs:enumeration value="SEQUENCE"/>
<xs:enumeration value="IDENTITY"/>
<xs:enumeration value="AUTO"/>
<xs:enumeration value="CUSTOM" />
</xs:restriction>
</xs:simpleType>
@ -253,6 +254,7 @@
<xs:sequence>
<xs:element name="generator" type="orm:generator" minOccurs="0" />
<xs:element name="sequence-generator" type="orm:sequence-generator" minOccurs="0" maxOccurs="1" />
<xs:element name="custom-generator" type="orm:custom-generator" minOccurs="0" maxOccurs="1" />
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"/>
</xs:sequence>
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
@ -271,6 +273,19 @@
<xs:attribute name="initial-value" type="xs:integer" use="optional" default="1" />
<xs:anyAttribute namespace="##other"/>
</xs:complexType>
<xs:complexType name="custom-generator">
<xs:sequence>
<xs:element name="args" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="arg" type="xs:string" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="class" type="xs:NMTOKEN" use="required" />
</xs:complexType>
<xs:complexType name="inverse-join-columns">
<xs:sequence>

View File

@ -250,6 +250,16 @@ class XmlDriver extends AbstractFileDriver
'allocationSize' => (string)$seqGenerator['allocation-size'],
'initialValue' => (string)$seqGenerator['initial-value']
));
} else if (isset($idElement->{'custom-generator'})) {
$customGenerator = $idElement->{'custom-generator'};
$args = array();
foreach ($customGenerator->args->children() as $argument) {
$args[] = (string) $argument;
}
$metadata->setCustomGeneratorDefinition(array(
'class' => (string) $customGenerator['class'],
'args' => $args
));
} else if (isset($idElement->{'table-generator'})) {
throw MappingException::tableIdGeneratorNotImplemented($className);
}

View File

@ -88,6 +88,18 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$class->sequenceGeneratorDefinition
);
}
public function testEntityCustomGenerator()
{
$class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM,
$class->generatorType, "Generator Type");
$this->assertEquals(
array("class" => "stdClass", "args" => array("par1", "par2")),
$class->customGeneratorDefinition,
"Custom Generator Definition");
}
/**

View File

@ -8,5 +8,14 @@
<discriminator-mapping value="cat" class="Cat" />
<discriminator-mapping value="dog" class="Dog" />
</discriminator-map>
<id name="id" type="integer" column="id">
<generator strategy="CUSTOM"/>
<custom-generator class="stdClass">
<args>
<arg>par1</arg>
<arg>par2</arg>
</args>
</custom-generator>
</id>
</entity>
</doctrine-mapping>