1
0
mirror of synced 2024-12-13 14:56:01 +03:00

starts work with mapped superclass repository

This commit is contained in:
Fabio B. Silva 2011-09-07 17:27:05 -03:00
parent 6ec2ae249b
commit 82f7d6cad2
6 changed files with 71 additions and 8 deletions

View File

@ -274,6 +274,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
$class->setDiscriminatorMap($parent->discriminatorMap);
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
}
// Invoke driver

View File

@ -147,12 +147,16 @@ class AnnotationDriver implements Driver
// Evaluate Entity annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
$entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity'];
$metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
if($entityAnnot->repositoryClass !== null) {
$metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
}
if ($entityAnnot->readOnly) {
$metadata->markReadOnly();
}
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
$mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'];
$metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
$metadata->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);

View File

@ -36,7 +36,9 @@ final class Entity extends Annotation {
* @Annotation
* @Target("CLASS")
*/
final class MappedSuperclass extends Annotation {}
final class MappedSuperclass extends Annotation {
public $repositoryClass;
}
/**
* @Annotation

View File

@ -52,13 +52,16 @@ class XmlDriver extends AbstractFileDriver
$xmlRoot = $this->getElement($className);
if ($xmlRoot->getName() == 'entity') {
$metadata->setCustomRepositoryClass(
isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null
);
if (isset($xmlRoot['repository-class'])) {
$metadata->setCustomRepositoryClass((string)$xmlRoot['repository-class']);
}
if (isset($xmlRoot['read-only']) && $xmlRoot['read-only'] == "true") {
$metadata->markReadOnly();
}
} else if ($xmlRoot->getName() == 'mapped-superclass') {
$metadata->setCustomRepositoryClass(
isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null
);
$metadata->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);

View File

@ -46,13 +46,16 @@ class YamlDriver extends AbstractFileDriver
$element = $this->getElement($className);
if ($element['type'] == 'entity') {
$metadata->setCustomRepositoryClass(
isset($element['repositoryClass']) ? $element['repositoryClass'] : null
);
if (isset($element['repositoryClass'])) {
$metadata->setCustomRepositoryClass($element['repositoryClass']);
}
if (isset($element['readOnly']) && $element['readOnly'] == true) {
$metadata->markReadOnly();
}
} else if ($element['type'] == 'mappedSuperclass') {
$metadata->setCustomRepositoryClass(
isset($element['repositoryClass']) ? $element['repositoryClass'] : null
);
$metadata->isMappedSuperclass = true;
} else {
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);

View File

@ -52,6 +52,30 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
$this->assertTrue(isset($class->associationMappings['mappedRelated1']));
}
public function testGetMetadataForSubclassWithMappedSuperclassWhithRepository()
{
$class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithoutRepository');
$this->assertTrue(empty($class->subClasses));
$this->assertTrue(empty($class->parentClasses));
$this->assertTrue(isset($class->fieldMappings['id']));
$this->assertTrue(isset($class->fieldMappings['name']));
$this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SuperRepository");
$class = $this->_factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\SubclassWithRepository');
$this->assertTrue(empty($class->subClasses));
$this->assertTrue(empty($class->parentClasses));
$this->assertTrue(isset($class->fieldMappings['id']));
$this->assertTrue(isset($class->fieldMappings['name']));
$this->assertEquals($class->customRepositoryClassName, "App\Reposotories\SubRepository");
}
/**
* @group DDC-388
@ -277,4 +301,30 @@ abstract class MediumSuperclassBase extends SuperclassBase
class MediumSuperclassEntity extends MediumSuperclassBase
{
}
/**
* @MappedSuperclass(repositoryClass = "App\Reposotories\SuperRepository")
*/
abstract class SuperclassBaseWithRepository
{
/** @Id @Column(type="integer") */
public $id;
/** @Column(type="string") */
public $name;
}
/**
* @Entity
*/
class SubclassWithoutRepository extends SuperclassBaseWithRepository
{
}
/**
* @Entity(repositoryClass = "App\Reposotories\SubRepository")
*/
class SubclassWithRepository extends SuperclassBaseWithRepository
{
}