Permalink
Browse files

Add support for custom ID generator in XML

  • Loading branch information...
1 parent 6bcfaed commit 2b97f79bd3e67e1357be8e286a4f70be7c310135 @velovint velovint committed Nov 28, 2011
View
@@ -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>
@@ -250,6 +250,16 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
'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);
}
@@ -88,6 +88,18 @@ public function testEntitySequence($class)
$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");
+ }
/**
@@ -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>

0 comments on commit 2b97f79

Please sign in to comment.