/** * @param $data * @param Tx_PtExtlist_Domain_Configuration_Columns_ObjectMapper_ObjectMapperConfig $configuration * @return object */ public function convert($data, $configuration) { if ($configuration->getMapping()) { $this->applyKeyMapping($configuration->getMapping(), $data); } $mappedObject = $this->mapper->map(array(), $data, $configuration->getClass()); if ($mappedObject === NULL) { throw new Exception('The data could mot be mapped to the object of class' . $configuration->getClass() . '. Reason: ' . implode(', ', $this->mapper->getMappingResults()->getErrors())); } return $mappedObject; }
/** * Checks if the value is a UUID or an array but should be an object, i.e. * the argument's data type class schema is set. If that is the case, this * method tries to look up the corresponding object instead. * * Additionally, it maps arrays to objects in case it is a normal object. * * @param mixed $value The value of an argument * @return mixed */ protected function transformValue($value) { if ($value === NULL) { return NULL; } if (!class_exists($this->dataType)) { return $value; } $transformedValue = NULL; if ($this->dataTypeClassSchema !== NULL) { // The target object is an Entity or ValueObject. if (is_numeric($value)) { $this->origin = self::ORIGIN_PERSISTENCE; $transformedValue = $this->findObjectByUid($value); } elseif (is_array($value)) { $this->origin = self::ORIGIN_PERSISTENCE_AND_MODIFIED; $transformedValue = $this->propertyMapper->map(array_keys($value), $value, $this->dataType); } } else { if (!is_array($value)) { throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('The value was a simple type, so we could not map it to an object. Maybe the @entity or @valueobject annotations are missing?', 1251730701); } $this->origin = self::ORIGIN_NEWLY_CREATED; $transformedValue = $this->propertyMapper->map(array_keys($value), $value, $this->dataType); } if (!$transformedValue instanceof $this->dataType) { throw new Tx_Extbase_MVC_Exception_InvalidArgumentValue('The value must be of type "' . $this->dataType . '", but was of type "' . (is_object($transformedValue) ? get_class($transformedValue) : gettype($transformedValue)) . '".', 1251730701); } return $transformedValue; }