Merge branch '4.1'
* 4.1: [PropertyAccess] make cache keys encoding bijective
This commit is contained in:
commit
721304eed4
|
@ -412,14 +412,14 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||||
*/
|
*/
|
||||||
private function getReadAccessInfo($class, $property)
|
private function getReadAccessInfo($class, $property)
|
||||||
{
|
{
|
||||||
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
|
$key = str_replace('\\', '.', $class).'..'.$property;
|
||||||
|
|
||||||
if (isset($this->readPropertyCache[$key])) {
|
if (isset($this->readPropertyCache[$key])) {
|
||||||
return $this->readPropertyCache[$key];
|
return $this->readPropertyCache[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cacheItemPool) {
|
if ($this->cacheItemPool) {
|
||||||
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_READ.str_replace('\\', '.', $key));
|
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_READ.rawurlencode($key));
|
||||||
if ($item->isHit()) {
|
if ($item->isHit()) {
|
||||||
return $this->readPropertyCache[$key] = $item->get();
|
return $this->readPropertyCache[$key] = $item->get();
|
||||||
}
|
}
|
||||||
|
@ -587,14 +587,14 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||||
*/
|
*/
|
||||||
private function getWriteAccessInfo(string $class, string $property, $value): array
|
private function getWriteAccessInfo(string $class, string $property, $value): array
|
||||||
{
|
{
|
||||||
$key = false !== strpbrk($key = $class.'..'.$property, '{}()/@:') ? rawurlencode($key) : $key;
|
$key = str_replace('\\', '.', $class).'..'.$property;
|
||||||
|
|
||||||
if (isset($this->writePropertyCache[$key])) {
|
if (isset($this->writePropertyCache[$key])) {
|
||||||
return $this->writePropertyCache[$key];
|
return $this->writePropertyCache[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cacheItemPool) {
|
if ($this->cacheItemPool) {
|
||||||
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_WRITE.str_replace('\\', '.', $key));
|
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_WRITE.rawurlencode($key));
|
||||||
if ($item->isHit()) {
|
if ($item->isHit()) {
|
||||||
return $this->writePropertyCache[$key] = $item->get();
|
return $this->writePropertyCache[$key] = $item->get();
|
||||||
}
|
}
|
||||||
|
@ -753,8 +753,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cacheItemPool) {
|
if ($this->cacheItemPool) {
|
||||||
$key = false !== strpbrk($propertyPath, '{}()/@:') ? rawurlencode($propertyPath) : $propertyPath;
|
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_PROPERTY_PATH.rawurlencode($propertyPath));
|
||||||
$item = $this->cacheItemPool->getItem(self::CACHE_PREFIX_PROPERTY_PATH.str_replace('\\', '.', $key));
|
|
||||||
if ($item->isHit()) {
|
if ($item->isHit()) {
|
||||||
return $this->propertyPathCache[$propertyPath] = $item->get();
|
return $this->propertyPathCache[$propertyPath] = $item->get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -586,9 +586,13 @@ class PropertyAccessorTest extends TestCase
|
||||||
{
|
{
|
||||||
$obj = new \stdClass();
|
$obj = new \stdClass();
|
||||||
$obj->{'@foo'} = 'bar';
|
$obj->{'@foo'} = 'bar';
|
||||||
|
$obj->{'a/b'} = '1';
|
||||||
|
$obj->{'a%2Fb'} = '2';
|
||||||
|
|
||||||
$propertyAccessor = new PropertyAccessor(false, false, new ArrayAdapter());
|
$propertyAccessor = new PropertyAccessor(false, false, new ArrayAdapter());
|
||||||
$this->assertSame('bar', $propertyAccessor->getValue($obj, '@foo'));
|
$this->assertSame('bar', $propertyAccessor->getValue($obj, '@foo'));
|
||||||
|
$this->assertSame('1', $propertyAccessor->getValue($obj, 'a/b'));
|
||||||
|
$this->assertSame('2', $propertyAccessor->getValue($obj, 'a%2Fb'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in New Issue