Add support for GenerateValue(strategy='CUSTOM') in AnnotationDriver
This commit is contained in:
parent
955497e3d5
commit
48b6356e53
@ -1829,6 +1829,14 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
$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.
|
||||
*
|
||||
|
@ -319,6 +319,11 @@ class AnnotationDriver implements Driver
|
||||
));
|
||||
} else if ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\TableGenerator')) {
|
||||
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')) {
|
||||
if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Id')) {
|
||||
|
@ -39,6 +39,7 @@ require_once __DIR__.'/../UniqueConstraint.php';
|
||||
require_once __DIR__.'/../Index.php';
|
||||
require_once __DIR__.'/../JoinTable.php';
|
||||
require_once __DIR__.'/../SequenceGenerator.php';
|
||||
require_once __DIR__.'/../CustomIdGenerator.php';
|
||||
require_once __DIR__.'/../ChangeTrackingPolicy.php';
|
||||
require_once __DIR__.'/../OrderBy.php';
|
||||
require_once __DIR__.'/../NamedQueries.php';
|
||||
|
@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
@ -22,6 +23,21 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
||||
$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
|
||||
*/
|
||||
@ -99,6 +115,8 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
||||
|
||||
protected function _loadDriver()
|
||||
{
|
||||
AnnotationRegistry::registerFile(__DIR__ .
|
||||
'/../../../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
|
||||
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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user