diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 2044932d6..98ef3fd6e 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -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 diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index ee7db54ac..afb89f083 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -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); diff --git a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php index e6a674b38..6e5b36a45 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php @@ -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 diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 20631d63c..b676ca8da 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -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); diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index a47d56fa1..a2c5402b6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -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); diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index d5aac63f9..e5fa6d220 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -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 +{ + } \ No newline at end of file