Change repository type for EntityRepository
This commit is contained in:
parent
43ccd9ead6
commit
3707b34cbb
@ -522,13 +522,13 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
||||
*
|
||||
* @since 2.2
|
||||
* @param string $className
|
||||
* @throws ORMException If not implements Doctrine\Common\Persistence\ObjectRepository
|
||||
* @throws ORMException If not is a Doctrine\ORM\EntityRepository
|
||||
*/
|
||||
public function setDefaultRepositoryClassName($className)
|
||||
{
|
||||
$class = new \ReflectionClass($className);
|
||||
if (!$class->implementsInterface('Doctrine\Common\Persistence\ObjectRepository')) {
|
||||
throw ORMException::invalidObjectRepository($className);
|
||||
if ($className != "Doctrine\ORM\EntityRepository" &&
|
||||
!is_subclass_of($className, 'Doctrine\ORM\EntityRepository')){
|
||||
throw ORMException::invalidEntityRepository($className);
|
||||
}
|
||||
$this->_attributes['defaultRepositoryClassName'] = $className;
|
||||
}
|
||||
|
@ -131,8 +131,9 @@ class ORMException extends Exception
|
||||
);
|
||||
}
|
||||
|
||||
public static function invalidObjectRepository($className) {
|
||||
public static function invalidEntityRepository($className)
|
||||
{
|
||||
return new self("Invalid repository class '".$className."'. ".
|
||||
"it must implement Doctrine\Common\Persistence\ObjectRepository.");
|
||||
"it must be a Doctrine\ORM\EntityRepository.");
|
||||
}
|
||||
}
|
||||
|
@ -22,55 +22,8 @@ namespace Doctrine\Tests\Models\DDC753;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class DDC753DefaultRepository implements \Doctrine\Common\Persistence\ObjectRepository
|
||||
class DDC753DefaultRepository extends EntityRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Doctrine\ORM\EntityRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @param EntityManager $em
|
||||
* @param ClassMetadata $classMetadata
|
||||
*/
|
||||
public function __construct($em, $class)
|
||||
{
|
||||
$this->repository = new EntityRepository($em, $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findAll()
|
||||
{
|
||||
return $this->repository->findAll;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
{
|
||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findOneBy(array $criteria)
|
||||
{
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -463,7 +463,7 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
/**
|
||||
* @group DDC-753
|
||||
* @expectedException Doctrine\ORM\ORMException
|
||||
* @expectedExceptionMessage Invalid repository class 'Doctrine\Tests\Models\DDC753\DDC753InvalidRepository'. it must implement Doctrine\Common\Persistence\ObjectRepository.
|
||||
* @expectedExceptionMessage Invalid repository class 'Doctrine\Tests\Models\DDC753\DDC753InvalidRepository'. it must be a Doctrine\ORM\EntityRepository.
|
||||
*/
|
||||
public function testSetDefaultRepositoryInvalidClassError()
|
||||
{
|
||||
@ -471,20 +471,5 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_em->getConfiguration()->setDefaultRepositoryClassName("Doctrine\Tests\Models\DDC753\DDC753InvalidRepository");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group DDC-753
|
||||
* @todo check it is necessary throws exception when a repository is not a Doctrine\Common\Persistence\ObjectRepository
|
||||
* ClassMetadataInfo#setCustomRepositoryClass
|
||||
*/
|
||||
public function testEntityWithInvalidRepositoryError()
|
||||
{
|
||||
$this->assertEquals($this->_em->getConfiguration()->getDefaultRepositoryClassName(), "Doctrine\ORM\EntityRepository");
|
||||
$repos = $this->_em->getRepository('Doctrine\Tests\Models\DDC753\DDC753EntityWithInvalidRepository');
|
||||
|
||||
$this->assertInstanceOf("\stdClass", $repos);
|
||||
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user