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->setLifecycleCallbacks($parent->lifecycleCallbacks);
|
||||
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
|
||||
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
|
||||
}
|
||||
|
||||
// Invoke driver
|
||||
|
@ -147,12 +147,16 @@ class AnnotationDriver implements Driver
|
||||
// Evaluate Entity annotation
|
||||
if (isset($classAnnotations['Doctrine\ORM\Mapping\Entity'])) {
|
||||
$entityAnnot = $classAnnotations['Doctrine\ORM\Mapping\Entity'];
|
||||
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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -53,6 +53,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
|
||||
*/
|
||||
@ -278,3 +302,29 @@ 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…
Reference in New Issue
Block a user