1
0
mirror of synced 2025-03-03 19:33:22 +03:00

DefaultRepositoryFactory: single repository for aliased entities

This commit is contained in:
Giorgio Premi 2014-08-18 12:02:51 +02:00
parent 5ff67c92ee
commit a665cb0229
2 changed files with 23 additions and 4 deletions

View File

@ -43,13 +43,15 @@ class DefaultRepositoryFactory implements RepositoryFactory
{ {
$entityName = ltrim($entityName, '\\'); $entityName = ltrim($entityName, '\\');
if (isset($this->repositoryList[$entityName])) { $class = $entityManager->getClassMetadata($entityName)->getName();
return $this->repositoryList[$entityName];
if (isset($this->repositoryList[$class])) {
return $this->repositoryList[$class];
} }
$repository = $this->createRepository($entityManager, $entityName); $repository = $this->createRepository($entityManager, $entityName);
$this->repositoryList[$entityName] = $repository; $this->repositoryList[$class] = $repository;
return $repository; return $repository;
} }

View File

@ -611,6 +611,23 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository"); $this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository");
} }
public function testSingleRepositoryInstanceForAnEntity()
{
$config = $this->_em->getConfiguration();
$config->addEntityNamespace('Aliased', 'Doctrine\Tests\Models\CMS');
$config->addEntityNamespace('AliasedAgain', 'Doctrine\Tests\Models\CMS');
$this->assertSame(
$this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'),
$this->_em->getRepository('Aliased:CmsUser')
);
$this->assertSame(
$this->_em->getRepository('Aliased:CmsUser'),
$this->_em->getRepository('AliasedAgain:CmsUser')
);
}
/** /**
* @group DDC-1376 * @group DDC-1376
* *