Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Serializer\Mapping\Factory;

use Doctrine\Common\Cache\Cache;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
Expand All @@ -30,28 +29,17 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
*/
private $loader;

/**
* @var Cache
*/
private $cache;

/**
* @var array
*/
private $loadedClasses;

/**
* @param LoaderInterface $loader
* @param Cache|null $cache
*/
public function __construct(LoaderInterface $loader, Cache $cache = null)
public function __construct(LoaderInterface $loader)
{
$this->loader = $loader;
$this->cache = $cache;

if (null !== $cache) {
@trigger_error(sprintf('Passing a Doctrine Cache instance as 2nd parameter of the "%s" constructor is deprecated since version 3.1. This parameter will be removed in Symfony 4.0. Use the "%s" class instead.', __CLASS__, CacheClassMetadataFactory::class), E_USER_DEPRECATED);
}
}

/**
Expand All @@ -65,10 +53,6 @@ public function getMetadataFor($value)
return $this->loadedClasses[$class];
}

if ($this->cache && ($this->loadedClasses[$class] = $this->cache->fetch($class))) {
return $this->loadedClasses[$class];
}

$classMetadata = new ClassMetadata($class);
$this->loader->loadClassMetadata($classMetadata);

Expand All @@ -84,10 +68,6 @@ public function getMetadataFor($value)
$classMetadata->merge($this->getMetadataFor($interface->name));
}

if ($this->cache) {
$this->cache->save($class, $classMetadata);
}

return $this->loadedClasses[$class] = $classMetadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,4 @@ public function testHasMetadataFor()
$this->assertTrue($factory->hasMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummyInterface'));
$this->assertFalse($factory->hasMetadataFor('Dunglas\Entity'));
}

/**
* @group legacy
*/
public function testCacheExists()
{
$cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
$cache
->expects($this->once())
->method('fetch')
->will($this->returnValue('foo'))
;

$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
$this->assertEquals('foo', $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy'));
}

/**
* @group legacy
*/
public function testCacheNotExists()
{
$cache = $this->getMockBuilder('Doctrine\Common\Cache\Cache')->getMock();
$cache->method('fetch')->will($this->returnValue(false));
$cache->method('save');

$factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()), $cache);
$metadata = $factory->getMetadataFor('Symfony\Component\Serializer\Tests\Fixtures\GroupDummy');

$this->assertEquals(TestClassMetadataFactory::createClassMetadata(true, true), $metadata);
}
}