Merge branch 'hotfix/#1112-single-repository-for-aliased-entity'
Close #1112
This commit is contained in:
commit
c20b3a7cf2
@ -32,7 +32,7 @@ class DefaultRepositoryFactory implements RepositoryFactory
|
|||||||
/**
|
/**
|
||||||
* The list of EntityRepository instances.
|
* The list of EntityRepository instances.
|
||||||
*
|
*
|
||||||
* @var array<\Doctrine\Common\Persistence\ObjectRepository>
|
* @var \Doctrine\Common\Persistence\ObjectRepository[]
|
||||||
*/
|
*/
|
||||||
private $repositoryList = array();
|
private $repositoryList = array();
|
||||||
|
|
||||||
@ -41,17 +41,13 @@ class DefaultRepositoryFactory implements RepositoryFactory
|
|||||||
*/
|
*/
|
||||||
public function getRepository(EntityManagerInterface $entityManager, $entityName)
|
public function getRepository(EntityManagerInterface $entityManager, $entityName)
|
||||||
{
|
{
|
||||||
$entityName = ltrim($entityName, '\\');
|
$className = $entityManager->getClassMetadata($entityName)->getName();
|
||||||
|
|
||||||
if (isset($this->repositoryList[$entityName])) {
|
if (isset($this->repositoryList[$className])) {
|
||||||
return $this->repositoryList[$entityName];
|
return $this->repositoryList[$className];
|
||||||
}
|
}
|
||||||
|
|
||||||
$repository = $this->createRepository($entityManager, $entityName);
|
return $this->repositoryList[$className] = $this->createRepository($entityManager, $entityName);
|
||||||
|
|
||||||
$this->repositoryList[$entityName] = $repository;
|
|
||||||
|
|
||||||
return $repository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,13 +60,10 @@ class DefaultRepositoryFactory implements RepositoryFactory
|
|||||||
*/
|
*/
|
||||||
protected function createRepository(EntityManagerInterface $entityManager, $entityName)
|
protected function createRepository(EntityManagerInterface $entityManager, $entityName)
|
||||||
{
|
{
|
||||||
|
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */
|
||||||
$metadata = $entityManager->getClassMetadata($entityName);
|
$metadata = $entityManager->getClassMetadata($entityName);
|
||||||
$repositoryClassName = $metadata->customRepositoryClassName;
|
$repositoryClassName = $metadata->customRepositoryClassName
|
||||||
|
?: $entityManager->getConfiguration()->getDefaultRepositoryClassName();
|
||||||
if ($repositoryClassName === null) {
|
|
||||||
$configuration = $entityManager->getConfiguration();
|
|
||||||
$repositoryClassName = $configuration->getDefaultRepositoryClassName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new $repositoryClassName($entityManager, $metadata);
|
return new $repositoryClassName($entityManager, $metadata);
|
||||||
}
|
}
|
||||||
|
@ -611,6 +611,33 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository");
|
$this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-3257
|
||||||
|
*/
|
||||||
|
public function testSingleRepositoryInstanceForDifferentEntityAliases()
|
||||||
|
{
|
||||||
|
$config = $this->_em->getConfiguration();
|
||||||
|
|
||||||
|
$config->addEntityNamespace('Aliased', 'Doctrine\Tests\Models\CMS');
|
||||||
|
$config->addEntityNamespace('AliasedAgain', 'Doctrine\Tests\Models\CMS');
|
||||||
|
|
||||||
|
$repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
|
||||||
|
|
||||||
|
$this->assertSame($repository, $this->_em->getRepository('Aliased:CmsUser'));
|
||||||
|
$this->assertSame($repository, $this->_em->getRepository('AliasedAgain:CmsUser'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-3257
|
||||||
|
*/
|
||||||
|
public function testCanRetrieveRepositoryFromClassNameWithLeadingBackslash()
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
$this->_em->getRepository('\\Doctrine\\Tests\\Models\\CMS\\CmsUser'),
|
||||||
|
$this->_em->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DDC-1376
|
* @group DDC-1376
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user