From 2b97f79bd3e67e1357be8e286a4f70be7c310135 Mon Sep 17 00:00:00 2001 From: Vitali Yakavenka Date: Mon, 28 Nov 2011 21:41:54 +0300 Subject: [PATCH] Add support for custom ID generator in XML --- doctrine-mapping.xsd | 15 +++++++++++++++ lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 10 ++++++++++ .../ORM/Mapping/AbstractMappingDriverTest.php | 12 ++++++++++++ .../xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml | 9 +++++++++ 4 files changed, 46 insertions(+) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index e8e21f193..7c9cd2bfe 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -143,6 +143,7 @@ + @@ -253,6 +254,7 @@ + @@ -271,6 +273,19 @@ + + + + + + + + + + + + + diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 6f655d0db..af783cf4e 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -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); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 7c2887301..407276e5b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -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"); + } /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml index 6c2a2356f..4f7e6d26f 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.Animal.dcm.xml @@ -8,5 +8,14 @@ + + + + + par1 + par2 + + + \ No newline at end of file