diff --git a/lib/Doctrine/ORM/Cache.php b/lib/Doctrine/ORM/Cache.php index fec65f1f3..3da7c05ef 100644 --- a/lib/Doctrine/ORM/Cache.php +++ b/lib/Doctrine/ORM/Cache.php @@ -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. * diff --git a/lib/Doctrine/ORM/Cache/CacheConfiguration.php b/lib/Doctrine/ORM/Cache/CacheConfiguration.php index 4a583c14c..760352314 100644 --- a/lib/Doctrine/ORM/Cache/CacheConfiguration.php +++ b/lib/Doctrine/ORM/Cache/CacheConfiguration.php @@ -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; - } } diff --git a/lib/Doctrine/ORM/Cache/CacheFactory.php b/lib/Doctrine/ORM/Cache/CacheFactory.php index b1ce7f8e3..793392199 100644 --- a/lib/Doctrine/ORM/Cache/CacheFactory.php +++ b/lib/Doctrine/ORM/Cache/CacheFactory.php @@ -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); } diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index 9ae425df3..207c34a61 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -230,4 +230,12 @@ class DefaultCacheFactory implements CacheFactory return $this->timestampRegion; } + + /** + * {@inheritdoc} + */ + public function createCache(EntityManagerInterface $em) + { + return new DefaultCache($em); + } } diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 0c1b16b5c..cd433a7fa 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -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); } } diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index 40c0cb3be..799fd1b8d 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -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 diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php index fff090330..412d30207 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php @@ -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();