Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
 /**
  * Maps arguments delivered by the request object to the local controller arguments.
  *
  * @return void
  */
 protected function mapRequestArgumentsToControllerArguments()
 {
     $optionalPropertyNames = array();
     $allPropertyNames = $this->arguments->getArgumentNames();
     foreach ($allPropertyNames as $propertyName) {
         if ($this->arguments[$propertyName]->isRequired() === FALSE) {
             $optionalPropertyNames[] = $propertyName;
         }
     }
     $validator = t3lib_div::makeInstance('Tx_Extbase_MVC_Controller_ArgumentsValidator');
     $this->propertyMapper->mapAndValidate($allPropertyNames, $this->request->getArguments(), $this->arguments, $optionalPropertyNames, $validator);
     $this->argumentsMappingResults = $this->propertyMapper->getMappingResults();
 }