浏览代码

[Form] Improved internal structore of PropertyPathMapper

Bernhard Schussek 14 年之前
父节点
当前提交
9b6722222f
共有 1 个文件被更改,包括 11 次插入15 次删除
  1. 11 15
      src/Symfony/Component/Form/DataMapper/PropertyPathMapper.php

+ 11 - 15
src/Symfony/Component/Form/DataMapper/PropertyPathMapper.php

@@ -85,27 +85,23 @@ class PropertyPathMapper implements DataMapperInterface
         $iterator = new \RecursiveIteratorIterator($iterator);
 
         foreach ($iterator as $form) {
-            $isReference = false;
-
-            // If the data is identical to the value in $data, we are
-            // dealing with a reference
-            if ($form->getAttribute('property_path') !== null) {
-                $isReference = $form->getData() === $form->getAttribute('property_path')->getValue($data);
-            }
-
-            // Don't write into $data if $data is an object,
-            // $isReference is true (see above) and the option "by_reference" is
-            // true as well
-            if (!is_object($data) || !$isReference || !$form->getAttribute('by_reference')) {
-                $this->mapFormToData($form, $data);
-            }
+            $this->mapFormToData($form, $data);
         }
     }
 
     public function mapFormToData(FormInterface $form, &$data)
     {
         if ($form->getAttribute('property_path') !== null) {
-            $form->getAttribute('property_path')->setValue($data, $form->getData());
+            $propertyPath = $form->getAttribute('property_path');
+
+            // If the data is identical to the value in $data, we are
+            // dealing with a reference
+            $isReference = $form->getData() === $propertyPath->getValue($data);
+            $byReference = $form->getAttribute('by_reference');
+
+            if (!(is_object($data) && $isReference && $byReference)) {
+                $propertyPath->setValue($data, $form->getData());
+            }
         }
     }
 }