From a0c0d7d5921e415793ee0f6b0214d8852479146b Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 18 Jun 2012 10:25:14 +0200 Subject: [PATCH 1/2] [Form] PropertyPath: Add failing testcase for reading from CustomArrayObject --- .../Form/Tests/Util/PropertyPathTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php b/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php index f231c24f45866..574818ce453d8 100644 --- a/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php +++ b/src/Symfony/Component/Form/Tests/Util/PropertyPathTest.php @@ -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 @@ -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]); + } } From f7dd77003bdce6e33556cfbc8c72651d4e43076d Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 18 Jun 2012 12:45:37 +0200 Subject: [PATCH 2/2] [Form] PropertyPath: Fix reading from custom array object. Fixes #4535 --- src/Symfony/Component/Form/Util/PropertyPath.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Util/PropertyPath.php b/src/Symfony/Component/Form/Util/PropertyPath.php index 88a94b5f76f79..ef12e723d23d7 100644 --- a/src/Symfony/Component/Form/Util/PropertyPath.php +++ b/src/Symfony/Component/Form/Util/PropertyPath.php @@ -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);