From 1dc3396ad4b692de4d97358221f343c9976a24ec Mon Sep 17 00:00:00 2001 From: fabios Date: Thu, 17 Apr 2014 15:16:46 -0400 Subject: [PATCH] DDC-3078 - Use CacheFactory instead of cache instantiator --- lib/Doctrine/ORM/Cache/CacheConfiguration.php | 21 ---------- lib/Doctrine/ORM/Cache/CacheFactory.php | 9 ++++ lib/Doctrine/ORM/Cache/CacheInstantiator.php | 41 ------------------- .../ORM/Cache/DefaultCacheFactory.php | 8 ++++ .../ORM/Cache/DefaultCacheInstantiator.php | 41 ------------------- lib/Doctrine/ORM/EntityManager.php | 4 +- .../Tests/ORM/Cache/CacheConfigTest.php | 19 --------- .../Cache/DefaultCacheInstantiatorTest.php | 29 ------------- 8 files changed, 20 insertions(+), 152 deletions(-) delete mode 100644 lib/Doctrine/ORM/Cache/CacheInstantiator.php delete mode 100644 lib/Doctrine/ORM/Cache/DefaultCacheInstantiator.php delete mode 100644 tests/Doctrine/Tests/ORM/Cache/DefaultCacheInstantiatorTest.php diff --git a/lib/Doctrine/ORM/Cache/CacheConfiguration.php b/lib/Doctrine/ORM/Cache/CacheConfiguration.php index aee703b55..760352314 100644 --- a/lib/Doctrine/ORM/Cache/CacheConfiguration.php +++ b/lib/Doctrine/ORM/Cache/CacheConfiguration.php @@ -50,11 +50,6 @@ class CacheConfiguration */ private $queryValidator; - /** - * @var CacheInstantiator|null - */ - private $cacheInstantiator; - /** * @return \Doctrine\ORM\Cache\CacheFactory|null */ @@ -128,20 +123,4 @@ class CacheConfiguration { $this->queryValidator = $validator; } - - /** - * @param CacheInstantiator - */ - public function setCacheInstantiator(CacheInstantiator $cacheInstantiator) - { - $this->cacheInstantiator = $cacheInstantiator; - } - - /** - * @return CacheInstantiator - */ - public function getCacheInstantiator() - { - return $this->cacheInstantiator ?: $this->cacheInstantiator = new DefaultCacheInstantiator(); - } } 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/CacheInstantiator.php b/lib/Doctrine/ORM/Cache/CacheInstantiator.php deleted file mode 100644 index a88442b24..000000000 --- a/lib/Doctrine/ORM/Cache/CacheInstantiator.php +++ /dev/null @@ -1,41 +0,0 @@ -. - */ - -namespace Doctrine\ORM\Cache; - -use Doctrine\ORM\EntityManagerInterface; - -/** - * Contract for building second level cache instances. - * - * @since 2.5 - * @author Marco Pivetta - */ -interface CacheInstantiator -{ - /** - * Build timestamp cache region - * - * @param EntityManagerInterface $entityManager - * - * @return \Doctrine\ORM\Cache - */ - public function getCache(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/Cache/DefaultCacheInstantiator.php b/lib/Doctrine/ORM/Cache/DefaultCacheInstantiator.php deleted file mode 100644 index 43d7df20f..000000000 --- a/lib/Doctrine/ORM/Cache/DefaultCacheInstantiator.php +++ /dev/null @@ -1,41 +0,0 @@ -. - */ - -namespace Doctrine\ORM\Cache; - -use Doctrine\ORM\EntityManagerInterface; - -/** - * Default implementation of the {@see \Doctrine\ORM\Cache\CacheInstantiator}, responsible - * for producing an {@see \Doctrine\ORM\Cache\DefaultCache} - * - * @since 2.5 - * @author Marco Pivetta - */ -class DefaultCacheInstantiator implements CacheInstantiator -{ - /** - * {@inheritDoc} - */ - public function getCache(EntityManagerInterface $entityManager) - { - return new DefaultCache($entityManager); - } -} diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 5c8ce598b..cd433a7fa 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -166,7 +166,9 @@ use Doctrine\Common\Util\ClassUtils; ); if ($config->isSecondLevelCacheEnabled()) { - $this->cache = $config->getSecondLevelCacheConfiguration()->getCacheInstantiator()->getCache($this); + $cacheConfig = $config->getSecondLevelCacheConfiguration(); + $cacheFactory = $cacheConfig->getCacheFactory(); + $this->cache = $cacheFactory->createCache($this); } } diff --git a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php index 1c88fcf17..412d30207 100644 --- a/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php @@ -27,25 +27,6 @@ class CacheConfigTest extends DoctrineTestCase $this->config = new CacheConfiguration(); } - /** - * @covers \Doctrine\ORM\Cache\CacheConfiguration::getCacheInstantiator - */ - public function testGetDefaultCacheIstantiator() - { - $this->assertInstanceOf('Doctrine\ORM\Cache\DefaultCacheInstantiator', $this->config->getCacheInstantiator()); - } - - /** - * @covers \Doctrine\ORM\Cache\CacheConfiguration::getCacheInstantiator - */ - public function testSetGetCacheIstantiator() - { - $istantiator = $this->getMock('Doctrine\ORM\Cache\CacheInstantiator'); - - $this->config->setCacheInstantiator($istantiator); - $this->assertSame($istantiator, $this->config->getCacheInstantiator()); - } - public function testSetGetRegionLifetime() { $config = $this->config->getRegionsConfiguration(); diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheInstantiatorTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheInstantiatorTest.php deleted file mode 100644 index 49c8573bc..000000000 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheInstantiatorTest.php +++ /dev/null @@ -1,29 +0,0 @@ -getMock('Doctrine\ORM\EntityManagerInterface'); - $config = $this->getMock('Doctrine\ORM\Configuration'); - $cacheConfig = $this->getMock('Doctrine\ORM\Cache\CacheConfiguration'); - - $entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($config)); - $config - ->expects($this->any()) - ->method('getSecondLevelCacheConfiguration') - ->will($this->returnValue($cacheConfig)); - - $instantiator = new DefaultCacheInstantiator(); - - $this->assertInstanceOf('Doctrine\ORM\Cache\DefaultCache', $instantiator->getCache($entityManager)); - } -}