1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Add support for GenerateValue(strategy='CUSTOM') in AnnotationDriver

This commit is contained in:
Vitali Yakavenka 2011-11-26 11:32:44 +01:00
parent 955497e3d5
commit 48b6356e53
4 changed files with 46 additions and 1 deletions

View File

@ -1828,6 +1828,14 @@ class ClassMetadataInfo implements ClassMetadata
{ {
$this->idGenerator = $generator; $this->idGenerator = $generator;
} }
/**
* Sets definition
* @param array $definition
*/
public function setCustomGeneratorDefinition(array $definition) {
$this->customGeneratorDefinition = $definition;
}
/** /**
* Sets the definition of the sequence ID generator for this class. * Sets the definition of the sequence ID generator for this class.

View File

@ -319,6 +319,11 @@ class AnnotationDriver implements Driver
)); ));
} else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) { } else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
throw MappingException::tableIdGeneratorNotImplemented($className); throw MappingException::tableIdGeneratorNotImplemented($className);
} else if ($customGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\CustomIdGenerator')) {
$metadata->setCustomGeneratorDefinition(array(
'class' => $customGeneratorAnnot->class,
'args' => $customGeneratorAnnot->args
));
} }
} else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) { } else if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\OneToOne')) {
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) { if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {

View File

@ -39,6 +39,7 @@ require_once __DIR__.'/../UniqueConstraint.php';
require_once __DIR__.'/../Index.php'; require_once __DIR__.'/../Index.php';
require_once __DIR__.'/../JoinTable.php'; require_once __DIR__.'/../JoinTable.php';
require_once __DIR__.'/../SequenceGenerator.php'; require_once __DIR__.'/../SequenceGenerator.php';
require_once __DIR__.'/../CustomIdGenerator.php';
require_once __DIR__.'/../ChangeTrackingPolicy.php'; require_once __DIR__.'/../ChangeTrackingPolicy.php';
require_once __DIR__.'/../OrderBy.php'; require_once __DIR__.'/../OrderBy.php';
require_once __DIR__.'/../NamedQueries.php'; require_once __DIR__.'/../NamedQueries.php';
@ -51,4 +52,4 @@ require_once __DIR__.'/../PostUpdate.php';
require_once __DIR__.'/../PreRemove.php'; require_once __DIR__.'/../PreRemove.php';
require_once __DIR__.'/../PostRemove.php'; require_once __DIR__.'/../PostRemove.php';
require_once __DIR__.'/../PostLoad.php'; require_once __DIR__.'/../PostLoad.php';
require_once __DIR__.'/../PreFlush.php'; require_once __DIR__.'/../PreFlush.php';

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Events; use Doctrine\ORM\Events;
use Doctrine\Common\Annotations\AnnotationRegistry;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
@ -21,6 +22,21 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
$annotationDriver->loadMetadataForClass('stdClass', $cm); $annotationDriver->loadMetadataForClass('stdClass', $cm);
} }
public function testLoadMetadataForClassSetsCustomIdGenerator()
{
$cm = new ClassMetadata("Doctrine\Tests\ORM\Mapping\CustomIdGeneratorClass");
$driver = $this->_loadDriver();
$expected = array("class" => "\stdClass",
"args" => array("par1", "par2"));
$driver->loadMetadataForClass(
"Docrtine\Tests\ORM\Mapping\CustomIdGeneratorClass", $cm);
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM, $cm->generatorType);
$this->assertEquals($expected, $cm->customGeneratorDefinition);
}
/** /**
* @group DDC-268 * @group DDC-268
@ -99,6 +115,8 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
protected function _loadDriver() protected function _loadDriver()
{ {
AnnotationRegistry::registerFile(__DIR__ .
'/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
return $this->createAnnotationDriver(); return $this->createAnnotationDriver();
} }
@ -215,6 +233,19 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
} }
} }
/**
* @Entity
*/
class CustomIdGeneratorClass
{
/**
* @Id @Column
* @GeneratedValue(strategy="CUSTOM")
* @CustomIdGenerator(class="\stdClass", args={"par1", "par2"})
*/
public $id;
}
/** /**
* @Entity * @Entity
*/ */