1
0
mirror of synced 2025-03-09 22:36:14 +03:00

Merge pull request #1012 from FabioBatSilva/DDC-3078-slc-cache-interface-ctor-removal

Ddc 3078 slc cache interface ctor removal
This commit is contained in:
Guilherme Blanco 2014-04-17 15:34:36 -04:00
commit 6af3236ba6
7 changed files with 25 additions and 61 deletions

View File

@ -54,13 +54,6 @@ interface Cache
*/
const MODE_REFRESH = 4;
/**
* Construct
*
* @param \Doctrine\ORM\EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em);
/**
* @param string $className The entity class.
*

View File

@ -20,7 +20,6 @@
namespace Doctrine\ORM\Cache;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\Cache\Logging\CacheLogger;
/**
@ -51,11 +50,6 @@ class CacheConfiguration
*/
private $queryValidator;
/**
* @var string
*/
private $cacheClassName = 'Doctrine\ORM\Cache\DefaultCache';
/**
* @return \Doctrine\ORM\Cache\CacheFactory|null
*/
@ -129,28 +123,4 @@ class CacheConfiguration
{
$this->queryValidator = $validator;
}
/**
* @param string $className
*
* @throws \Doctrine\ORM\ORMException If is not a \Doctrine\ORM\Cache
*/
public function setCacheClassName($className)
{
$reflectionClass = new \ReflectionClass($className);
if ( ! $reflectionClass->implementsInterface('Doctrine\ORM\Cache')) {
throw ORMException::invalidSecondLevelCache($className);
}
$this->cacheClassName = $className;
}
/**
* @return string A \Doctrine\ORM\Cache class name
*/
public function getCacheClassName()
{
return $this->cacheClassName;
}
}

View File

@ -101,4 +101,13 @@ interface CacheFactory
* @return \Doctrine\ORM\Cache\TimestampRegion The timestamp region.
*/
public function getTimestampRegion();
/**
* Build \Doctrine\ORM\Cache
*
* @param EntityManagerInterface $entityManager
*
* @return \Doctrine\ORM\Cache
*/
public function createCache(EntityManagerInterface $entityManager);
}

View File

@ -230,4 +230,12 @@ class DefaultCacheFactory implements CacheFactory
return $this->timestampRegion;
}
/**
* {@inheritdoc}
*/
public function createCache(EntityManagerInterface $em)
{
return new DefaultCache($em);
}
}

View File

@ -166,8 +166,9 @@ use Doctrine\Common\Util\ClassUtils;
);
if ($config->isSecondLevelCacheEnabled()) {
$cacheClass = $config->getSecondLevelCacheConfiguration()->getCacheClassName();
$this->cache = new $cacheClass($this);
$cacheConfig = $config->getSecondLevelCacheConfiguration();
$cacheFactory = $cacheConfig->getCacheFactory();
$this->cache = $cacheFactory->createCache($this);
}
}

View File

@ -262,16 +262,6 @@ class ORMException extends Exception
return new self("Invalid repository class '".$className."'. It must be a Doctrine\Common\Persistence\ObjectRepository.");
}
/**
* @param string $className
*
* @return ORMException
*/
public static function invalidSecondLevelCache($className)
{
return new self(sprintf('Invalid cache class "%s". It must be a Doctrine\ORM\Cache.', $className));
}
/**
* @param string $className
* @param string $fieldName

View File

@ -7,6 +7,8 @@ use Doctrine\ORM\Cache\CacheConfiguration;
/**
* @group DDC-2183
*
* @covers \Doctrine\ORM\Cache\CacheConfiguration
*/
class CacheConfigTest extends DoctrineTestCase
{
@ -15,6 +17,9 @@ class CacheConfigTest extends DoctrineTestCase
*/
private $config;
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
@ -22,18 +27,6 @@ class CacheConfigTest extends DoctrineTestCase
$this->config = new CacheConfiguration();
}
public function testSetGetCacheClassName()
{
$mockClass = get_class($this->getMock('Doctrine\ORM\Cache'));
$this->assertEquals('Doctrine\ORM\Cache\DefaultCache', $this->config->getCacheClassName());
$this->config->setCacheClassName($mockClass);
$this->assertEquals($mockClass, $this->config->getCacheClassName());
$this->setExpectedException('Doctrine\ORM\ORMException');
$this->config->setCacheClassName(__CLASS__);
}
public function testSetGetRegionLifetime()
{
$config = $this->config->getRegionsConfiguration();