8000 [Form] PropertyPath readValue fails for custom array objects by asm89 · Pull Request #4606 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] PropertyPath readValue fails for custom array objects #4606

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\Form\Tests\Fixtures\Author;
use Symfony\Component\Form\Tests\Fixtures\CustomArrayObject;
use Symfony\Component\Form\Tests\Fixtures\Magician;

class PropertyPathTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -580,4 +581,21 @@ public function testIsIndexDoesNotAcceptNegativeIndices()

$propertyPath->isIndex(-1);
}

public function testGetValueReadsFromCustomArrayCollection()
{
$collection = new CustomArrayObject(array('foo', 'bar'));

$path = new PropertyPath('[1]');
$this->assertEquals('bar', $path->getValue($collection));
}

public function testSetValueUpdatesCustomArrayCollection()
{
$collection = new CustomArrayObject(array('foo', 'bar'));

$path = new PropertyPath('[1]');
$path->setValue($collection, 'meh');
$this->assertEquals('meh', $collection[1]);
}
}
6 changes: 5 additions & 1 deletion src/Symfony/Component/Form/Util/PropertyPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ protected function &readProperty(&$objectOrArray, $property, $isIndex)
}

if (isset($objectOrArray[$property])) {
$result =& $objectOrArray[$property];
if (is_array($objectOrArray)) {
$result =& $objectOrArray[$property];
} else {
$result = $objectOrArray[$property];
}
}
} elseif (is_object($objectOrArray)) {
$camelProp = $this->camelize($property);
Expand Down
0