[~BUGFIX] Extbase (Property): The property mapper now doesn't map properties if the...
authorJochen Rau <j.rau@web.de>
Tue, 2 Mar 2010 19:50:00 +0000 (19:50 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 2 Mar 2010 19:50:00 +0000 (19:50 +0000)
typo3/sysext/extbase/Classes/MVC/Controller/Argument.php
typo3/sysext/extbase/Classes/Property/Mapper.php

index bf5c5f7..d295a79 100644 (file)
@@ -364,11 +364,7 @@ class Tx_Extbase_MVC_Controller_Argument {
                }
 
                if (!($transformedValue instanceof $this->dataType)) {
-                       if (is_object($transformedValue)) {
-                               throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('The value must be of type "' . $this->dataType . '", but was of type "' . get_class($transformedValue) . '".', 1251730701);
-                       } else {
-                               throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('The value must be of type "' . $this->dataType . '", but was of type "' . gettype($transformedValue) . '".', 1251730702);
-                       }
+                       throw new Tx_Extbase_MVC_Exception_InvalidArgumentValueException('The value must be of type "' . $this->dataType . '", but was of type "' . (is_object($transformedValue) ? get_class($transformedValue) : gettype($transformedValue)) . '".', 1251730701);
                }
                return $transformedValue;
        }
index 1379a00..2a01257 100644 (file)
@@ -216,6 +216,9 @@ class Tx_Extbase_Property_Mapper {
                                                }
                                        } elseif ($propertyMetaData['type'] === 'DateTime' || strpos($propertyMetaData['type'], '_') !== FALSE) {
                                                $propertyValue = $this->transformToObject($propertyValue, $propertyMetaData['type'], $propertyName);
+                                               if ($propertyValue === NULL) {
+                                                       continue;
+                                               }
                                        }
                                } elseif ($targetClassSchema !== NULL) {
                                        $this->mappingResults->addError(new Tx_Extbase_Error_Error("Property '$propertyName' does not exist in target class schema." , 1251813614), $propertyName);
@@ -239,7 +242,7 @@ class Tx_Extbase_Property_Mapper {
         * @param mixed $propertyValue The value to transform, string or array
         * @param string $targetType The type to transform to
         * @param string $propertyName In case of an error we add this to the error message
-        * @return object
+        * @return object The object, when no transformation was possible this may return NULL as well
         */
        protected function transformToObject($propertyValue, $targetType, $propertyName) {
                if ($targetType === 'DateTime' || in_array('DateTime', class_parents($targetType)) ) {
@@ -270,12 +273,16 @@ class Tx_Extbase_Property_Mapper {
                                                $newObject = clone $existingObject;
                                                if ($this->map(array_keys($propertyValue), $propertyValue, $newObject)) {
                                                        $propertyValue = $newObject;
+                                               } else {
+                                                       $propertyValue = NULL;
                                                }
                                        }
                                } else {
                                        $newObject = new $targetType;
                                        if ($this->map(array_keys($propertyValue), $propertyValue, $newObject)) {
                                                $propertyValue = $newObject;
+                                       } else {
+                                               $propertyValue = NULL;
                                        }
                                }
                        } else {