[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);
|
$propertyValues = & $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);
|
||||||
$overwrite = true;
|
|
||||||
|
|
||||||
// Add the root object to the list
|
// Add the root object to the list
|
||||||
array_unshift($propertyValues, array(
|
array_unshift($propertyValues, array(
|
||||||
@ -81,18 +80,19 @@ class PropertyAccessor implements PropertyAccessorInterface
|
|||||||
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
|
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
|
||||||
$objectOrArray = & $propertyValues[$i][self::VALUE];
|
$objectOrArray = & $propertyValues[$i][self::VALUE];
|
||||||
|
|
||||||
if ($overwrite) {
|
$property = $propertyPath->getElement($i);
|
||||||
$property = $propertyPath->getElement($i);
|
|
||||||
|
|
||||||
if ($propertyPath->isIndex($i)) {
|
if ($propertyPath->isIndex($i)) {
|
||||||
$this->writeIndex($objectOrArray, $property, $value);
|
$this->writeIndex($objectOrArray, $property, $value);
|
||||||
} else {
|
} else {
|
||||||
$this->writeProperty($objectOrArray, $property, $value);
|
$this->writeProperty($objectOrArray, $property, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($propertyValues[$i][self::IS_REF]) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = & $objectOrArray;
|
$value = & $objectOrArray;
|
||||||
$overwrite = !$propertyValues[$i][self::IS_REF];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,6 @@ class PropertyAccessor implements PropertyAccessorInterface
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$propertyValues = $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);
|
$propertyValues = $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);
|
||||||
$overwrite = true;
|
|
||||||
|
|
||||||
// Add the root object to the list
|
// Add the root object to the list
|
||||||
array_unshift($propertyValues, array(
|
array_unshift($propertyValues, array(
|
||||||
@ -138,21 +137,21 @@ class PropertyAccessor implements PropertyAccessorInterface
|
|||||||
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
|
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
|
||||||
$objectOrArray = $propertyValues[$i][self::VALUE];
|
$objectOrArray = $propertyValues[$i][self::VALUE];
|
||||||
|
|
||||||
if ($overwrite) {
|
$property = $propertyPath->getElement($i);
|
||||||
$property = $propertyPath->getElement($i);
|
|
||||||
|
|
||||||
if ($propertyPath->isIndex($i)) {
|
if ($propertyPath->isIndex($i)) {
|
||||||
if (!$objectOrArray instanceof \ArrayAccess && !is_array($objectOrArray)) {
|
if (!$objectOrArray instanceof \ArrayAccess && !is_array($objectOrArray)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!$this->isPropertyWritable($objectOrArray, $property)) {
|
if (!$this->isPropertyWritable($objectOrArray, $property)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$overwrite = !$propertyValues[$i][self::IS_REF];
|
if ($propertyValues[$i][self::IS_REF]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -25,6 +25,7 @@ class TestClass
|
|||||||
private $publicAccessorWithMoreRequiredParameters;
|
private $publicAccessorWithMoreRequiredParameters;
|
||||||
private $publicIsAccessor;
|
private $publicIsAccessor;
|
||||||
private $publicHasAccessor;
|
private $publicHasAccessor;
|
||||||
|
private $publicGetter;
|
||||||
|
|
||||||
public function __construct($value)
|
public function __construct($value)
|
||||||
{
|
{
|
||||||
@ -37,6 +38,7 @@ class TestClass
|
|||||||
$this->publicAccessorWithMoreRequiredParameters = $value;
|
$this->publicAccessorWithMoreRequiredParameters = $value;
|
||||||
$this->publicIsAccessor = $value;
|
$this->publicIsAccessor = $value;
|
||||||
$this->publicHasAccessor = $value;
|
$this->publicHasAccessor = $value;
|
||||||
|
$this->publicGetter = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPublicAccessor($value)
|
public function setPublicAccessor($value)
|
||||||
@ -166,4 +168,9 @@ class TestClass
|
|||||||
{
|
{
|
||||||
return 'foobar';
|
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(array('index' => array('%!@$§.' => 'Bernhard')), '[index][%!@$§.]', 'Bernhard'),
|
||||||
array((object) array('%!@$§' => 'Bernhard'), '%!@$§', 'Bernhard'),
|
array((object) array('%!@$§' => 'Bernhard'), '%!@$§', 'Bernhard'),
|
||||||
array((object) array('property' => (object) array('%!@$§' => 'Bernhard')), 'property.%!@$§', '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