[Serializer] fixed fix encoding of cache keys with anonymous classes
This commit is contained in:
parent
77418e712e
commit
3a4675359d
@ -44,8 +44,7 @@ class CacheClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
public function getMetadataFor($value)
|
public function getMetadataFor($value)
|
||||||
{
|
{
|
||||||
$class = $this->getClass($value);
|
$class = $this->getClass($value);
|
||||||
// Key cannot contain backslashes according to PSR-6
|
$key = rawurlencode(strtr($class, '\\', '_'));
|
||||||
$key = strtr($class, '\\', '_');
|
|
||||||
|
|
||||||
$item = $this->cacheItemPool->getItem($key);
|
$item = $this->cacheItemPool->getItem($key);
|
||||||
if ($item->isHit()) {
|
if ($item->isHit()) {
|
||||||
|
@ -63,4 +63,20 @@ class CacheMetadataFactoryTest extends TestCase
|
|||||||
|
|
||||||
$factory->getMetadataFor('Not\Exist');
|
$factory->getMetadataFor('Not\Exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAnonymousClass()
|
||||||
|
{
|
||||||
|
$anonymousObject = new class() {
|
||||||
|
};
|
||||||
|
|
||||||
|
$metadata = new ClassMetadata(\get_class($anonymousObject));
|
||||||
|
$decorated = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock();
|
||||||
|
$decorated
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getMetadataFor')
|
||||||
|
->willReturn($metadata);
|
||||||
|
|
||||||
|
$factory = new CacheClassMetadataFactory($decorated, new ArrayAdapter());
|
||||||
|
$this->assertEquals($metadata, $factory->getMetadataFor($anonymousObject));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user