Skip to content

Commit

Permalink
Merge pull request #1012 from FabioBatSilva/DDC-3078-slc-cache-interf…
Browse files Browse the repository at this point in the history
…ace-ctor-removal

Ddc 3078 slc cache interface ctor removal
  • Loading branch information
guilhermeblanco committed Apr 17, 2014
2 parents 318f503 + 1dc3396 commit 6af3236
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 61 deletions.
7 changes: 0 additions & 7 deletions lib/Doctrine/ORM/Cache.php
Expand Up @@ -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.
*
Expand Down
30 changes: 0 additions & 30 deletions lib/Doctrine/ORM/Cache/CacheConfiguration.php
Expand Up @@ -20,7 +20,6 @@

namespace Doctrine\ORM\Cache;

use Doctrine\ORM\ORMException;
use Doctrine\ORM\Cache\Logging\CacheLogger;

/**
Expand Down Expand Up @@ -51,11 +50,6 @@ class CacheConfiguration
*/
private $queryValidator;

/**
* @var string
*/
private $cacheClassName = 'Doctrine\ORM\Cache\DefaultCache';

/**
* @return \Doctrine\ORM\Cache\CacheFactory|null
*/
Expand Down Expand Up @@ -129,28 +123,4 @@ public function setQueryValidator(QueryCacheValidator $validator)
{
$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;
}
}
9 changes: 9 additions & 0 deletions lib/Doctrine/ORM/Cache/CacheFactory.php
Expand Up @@ -101,4 +101,13 @@ public function getRegion(array $cache);
* @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);
}
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Expand Up @@ -230,4 +230,12 @@ public function getTimestampRegion()

return $this->timestampRegion;
}

/**
* {@inheritdoc}
*/
public function createCache(EntityManagerInterface $em)
{
return new DefaultCache($em);
}
}
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/EntityManager.php
Expand Up @@ -166,8 +166,9 @@ protected function __construct(Connection $conn, Configuration $config, EventMan
);

if ($config->isSecondLevelCacheEnabled()) {
$cacheClass = $config->getSecondLevelCacheConfiguration()->getCacheClassName();
$this->cache = new $cacheClass($this);
$cacheConfig = $config->getSecondLevelCacheConfiguration();
$cacheFactory = $cacheConfig->getCacheFactory();
$this->cache = $cacheFactory->createCache($this);
}
}

Expand Down
10 changes: 0 additions & 10 deletions lib/Doctrine/ORM/ORMException.php
Expand Up @@ -262,16 +262,6 @@ public static function invalidEntityRepository($className)
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
Expand Down
17 changes: 5 additions & 12 deletions tests/Doctrine/Tests/ORM/Cache/CacheConfigTest.php
Expand Up @@ -7,6 +7,8 @@

/**
* @group DDC-2183
*
* @covers \Doctrine\ORM\Cache\CacheConfiguration
*/
class CacheConfigTest extends DoctrineTestCase
{
Expand All @@ -15,25 +17,16 @@ class CacheConfigTest extends DoctrineTestCase
*/
private $config;

/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();

$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();
Expand Down

0 comments on commit 6af3236

Please sign in to comment.