starts work with mapped superclass repository
This commit is contained in:
parent
6ec2ae249b
commit
82f7d6cad2
@ -274,6 +274,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
$class->setDiscriminatorMap($parent->discriminatorMap);
|
$class->setDiscriminatorMap($parent->discriminatorMap);
|
||||||
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
|
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
|
||||||
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
|
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
|
||||||
|
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke driver
|
// Invoke driver
|
||||||
|
@ -147,12 +147,16 @@ class AnnotationDriver implements Driver
|
|||||||
// Evaluate Entity annotation
|
// Evaluate Entity annotation
|
||||||
if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
|
if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
|
||||||
$entityAnnot = $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) {
|
if ($entityAnnot->readOnly) {
|
||||||
$metadata->markReadOnly();
|
$metadata->markReadOnly();
|
||||||
}
|
}
|
||||||
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
|
} else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) {
|
||||||
|
$mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'];
|
||||||
|
$metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
|
||||||
$metadata->isMappedSuperclass = true;
|
$metadata->isMappedSuperclass = true;
|
||||||
} else {
|
} else {
|
||||||
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
||||||
|
@ -36,7 +36,9 @@ final class Entity extends Annotation {
|
|||||||
* @Annotation
|
* @Annotation
|
||||||
* @Target("CLASS")
|
* @Target("CLASS")
|
||||||
*/
|
*/
|
||||||
final class MappedSuperclass extends Annotation {}
|
final class MappedSuperclass extends Annotation {
|
||||||
|
public $repositoryClass;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Annotation
|
* @Annotation
|
||||||
|
@ -52,13 +52,16 @@ class XmlDriver extends AbstractFileDriver
|
|||||||
$xmlRoot = $this->getElement($className);
|
$xmlRoot = $this->getElement($className);
|
||||||
|
|
||||||
if ($xmlRoot->getName() == 'entity') {
|
if ($xmlRoot->getName() == 'entity') {
|
||||||
$metadata->setCustomRepositoryClass(
|
if (isset($xmlRoot['repository-class'])) {
|
||||||
isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null
|
$metadata->setCustomRepositoryClass((string)$xmlRoot['repository-class']);
|
||||||
);
|
}
|
||||||
if (isset($xmlRoot['read-only']) && $xmlRoot['read-only'] == "true") {
|
if (isset($xmlRoot['read-only']) && $xmlRoot['read-only'] == "true") {
|
||||||
$metadata->markReadOnly();
|
$metadata->markReadOnly();
|
||||||
}
|
}
|
||||||
} else if ($xmlRoot->getName() == 'mapped-superclass') {
|
} else if ($xmlRoot->getName() == 'mapped-superclass') {
|
||||||
|
$metadata->setCustomRepositoryClass(
|
||||||
|
isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null
|
||||||
|
);
|
||||||
$metadata->isMappedSuperclass = true;
|
$metadata->isMappedSuperclass = true;
|
||||||
} else {
|
} else {
|
||||||
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
||||||
|
@ -46,13 +46,16 @@ class YamlDriver extends AbstractFileDriver
|
|||||||
$element = $this->getElement($className);
|
$element = $this->getElement($className);
|
||||||
|
|
||||||
if ($element['type'] == 'entity') {
|
if ($element['type'] == 'entity') {
|
||||||
$metadata->setCustomRepositoryClass(
|
if (isset($element['repositoryClass'])) {
|
||||||
isset($element['repositoryClass']) ? $element['repositoryClass'] : null
|
$metadata->setCustomRepositoryClass($element['repositoryClass']);
|
||||||
);
|
}
|
||||||
if (isset($element['readOnly']) && $element['readOnly'] == true) {
|
if (isset($element['readOnly']) && $element['readOnly'] == true) {
|
||||||
$metadata->markReadOnly();
|
$metadata->markReadOnly();
|
||||||
}
|
}
|
||||||
} else if ($element['type'] == 'mappedSuperclass') {
|
} else if ($element['type'] == 'mappedSuperclass') {
|
||||||
|
$metadata->setCustomRepositoryClass(
|
||||||
|
isset($element['repositoryClass']) ? $element['repositoryClass'] : null
|
||||||
|
);
|
||||||
$metadata->isMappedSuperclass = true;
|
$metadata->isMappedSuperclass = true;
|
||||||
} else {
|
} else {
|
||||||
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
|
||||||
|
@ -52,6 +52,30 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
$this->assertTrue(isset($class->associationMappings['mappedRelated1']));
|
$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
|
* @group DDC-388
|
||||||
@ -277,4 +301,30 @@ abstract class MediumSuperclassBase extends SuperclassBase
|
|||||||
class MediumSuperclassEntity extends MediumSuperclassBase
|
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
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user