8000 [PropertyAccess] stop overwriting once a reference is reached (3rd) by bananer · Pull Request #13835 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyAccess] stop overwriting once a reference is reached (3rd) #13835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
[PropertyAccess] return as soon as possible from setValue and isWritable
  • Loading branch information
bananer committed Mar 3, 2015
commit c3eedcbbe6232bd789a72b805c56f6da8b41e483
40 changes: 19 additions & 21 deletions src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
}

$propertyValues = & $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);
$overwrite = true;

// Add the root object to the list
array_unshift($propertyValues, array(
Expand All @@ -81,16 +80,16 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
$objectOrArray = & $propertyValues[$i][self::VALUE];

if ($overwrite) {
$property = $propertyPath->getElement($i);
$property = $propertyPath->getElement($i);

if ($propertyPath->isIndex($i)) {
$this->writeIndex($objectOrArray, $property, $value);
} else {
$this->writeProperty($objectOrArray, $property, $value);
}
if ($propertyPath->isIndex($i)) {
$this->writeIndex($objectOrArray, $property, $value);
} else {
$this->writeProperty($objectOrArray, $property, $value);
}

$overwrite = !$propertyValues[$i][self::IS_REF];
if ($propertyValues[$i][self::IS_REF]) {
return;
}

$value = & $objectOrArray;
Expand Down Expand Up @@ -128,7 +127,6 @@ public function isWritable($objectOrArray, $propertyPath)

try {
$propertyValues = $this->readPropertiesUntil($objectOrArray, $propertyPath, $propertyPath->getLength() - 1);
$overwrite = true;

// Add the root object to the list
array_unshift($propertyValues, array(
Expand All @@ -139,20 +137,20 @@ public function isWritable($objectOrArray, $propertyPath)
for ($i = count($propertyValues) - 1; $i >= 0; --$i) {
$objectOrArray = $propertyValues[$i][self::VALUE];

if ($overwrite) {
$property = $propertyPath->getElement($i);
$property = $propertyPath->getElement($i);

if ($propertyPath->isIndex($i)) {
if (!$objectOrArray instanceof \ArrayAccess && !is_array($objectOrArray)) {
return false;
}
} else {
if (!$this->isPropertyWritable($objectOrArray, $property)) {
return false;
}
if ($propertyPath->isIndex($i)) {
if (!$objectOrArray instanceof \ArrayAccess && !is_array($objectOrArray)) {
return false;
}
} else {
if (!$this->isPropertyWritable($objectOrArray, $property)) {
return false;
}
}

$overwrite = !$propertyValues[$i][self::IS_REF];
if ($propertyValues[$i][self::IS_REF]) {
return true;
}
}

Expand Down
0