[PropertyAccess] stop overwriting once a reference is reached (3rd)
This commit is contained in:
parent
38a5ebdb05
commit
d733a887df
@ -70,7 +70,6 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
}
|
||||
|
||||
$propertyValues = & $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);
|
||||
$overwrite = true;
|
||||
|
||||
// Add the root object to the list
|
||||
array_unshift($propertyValues, array(
|
||||
@ -81,7 +80,6 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
|
||||
$objectOrArray = & $propertyValues[$i][self::VALUE];
|
||||
|
||||
if ($overwrite) {
|
||||
$property = $propertyPath->getElement($i);
|
||||
|
||||
if ($propertyPath->isIndex($i)) {
|
||||
@ -89,10 +87,12 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
} else {
|
||||
$this->writeProperty($objectOrArray, $property, $value);
|
||||
}
|
||||
|
||||
if ($propertyValues[$i][self::IS_REF]) {
|
||||
return;
|
||||
}
|
||||
|
||||
$value = & $objectOrArray;
|
||||
$overwrite = !$propertyValues[$i][self::IS_REF];
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +127,6 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
|
||||
try {
|
||||
$propertyValues = $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);
|
||||
$overwrite = true;
|
||||
|
||||
// Add the root object to the list
|
||||
array_unshift($propertyValues, array(
|
||||
@ -138,7 +137,6 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
|
||||
$objectOrArray = $propertyValues[$i][self::VALUE];
|
||||
|
||||
if ($overwrite) {
|
||||
$property = $propertyPath->getElement($i);
|
||||
|
||||
if ($propertyPath->isIndex($i)) {
|
||||
@ -150,9 +148,10 @@ class PropertyAccessor implements PropertyAccessorInterface
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$overwrite = !$propertyValues[$i][self::IS_REF];
|
||||
if ($propertyValues[$i][self::IS_REF]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -25,6 +25,7 @@ class TestClass
|
||||
private $publicAccessorWithMoreRequiredParameters;
|
||||
private $publicIsAccessor;
|
||||
private $publicHasAccessor;
|
||||
private $publicGetter;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
@ -37,6 +38,7 @@ class TestClass
|
||||
$this->publicAccessorWithMoreRequiredParameters = $value;
|
||||
$this->publicIsAccessor = $value;
|
||||
$this->publicHasAccessor = $value;
|
||||
$this->publicGetter = $value;
|
||||
}
|
||||
|
||||
public function setPublicAccessor($value)
|
||||
@ -166,4 +168,9 @@ class TestClass
|
||||
{
|
||||
return 'foobar';
|
||||
}
|
||||
|
||||
public function getPublicGetter()
|
||||
{
|
||||
return $this->publicGetter;
|
||||
}
|
||||
}
|
||||
|
@ -419,6 +419,14 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase
|
||||
array(array('index' => array('%!@$§.' => 'Bernhard')), '[index][%!@$§.]', 'Bernhard'),
|
||||
array((object) array('%!@$§' => 'Bernhard'), '%!@$§', 'Bernhard'),
|
||||
array((object) array('property' => (object) array('%!@$§' => 'Bernhard')), 'property.%!@$§', 'Bernhard'),
|
||||
|
||||
// nested objects and arrays
|
||||
array(array('foo' => new TestClass('bar')), '[foo].publicGetSetter', 'bar'),
|
||||
array(new TestClass(array('foo' => 'bar')), 'publicGetSetter[foo]', 'bar'),
|
||||
array(new TestClass(new TestClass('bar')), 'publicGetter.publicGetSetter', 'bar'),
|
||||
array(new TestClass(array('foo' => new TestClass('bar'))), 'publicGetter[foo].publicGetSetter', 'bar'),
|
||||
array(new TestClass(new TestClass(new TestClass('bar'))), 'publicGetter.publicGetter.publicGetSetter', 'bar'),
|
||||
array(new TestClass(array('foo' => array('baz' => new TestClass('bar')))), 'publicGetter[foo][baz].publicGetSetter', 'bar'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user