Пример #1
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
  * @author Robert Lemke <*****@*****.**>
  * @author Karsten Dambekalns <*****@*****.**>
  * @author Bastian Waidelich <*****@*****.**>
  * @author Sebastian Kurfürst <*****@*****.**>
  */
 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_string($value) && preg_match(self::PATTERN_MATCH_UUID, $value) === 1) {
             $this->origin = self::ORIGIN_PERSISTENCE;
             $transformedValue = $this->persistenceManager->getObjectByIdentifier($value);
         } elseif (is_array($value)) {
             if (array_keys($value) === array('__identity')) {
                 // If there is only an __identity array _and nothing else_, then the property mapper will not clone the object.
                 $this->origin = self::ORIGIN_PERSISTENCE;
             } else {
                 $this->origin = self::ORIGIN_PERSISTENCE_AND_MODIFIED;
             }
             $transformedValue = $this->propertyMapper->map(array_keys($value), $value, $this->dataType);
         }
     } else {
         if (!is_array($value)) {
             throw new \F3\FLOW3\MVC\Exception\InvalidArgumentValueException('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 \F3\FLOW3\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;
 }
 /**
  * Maps arguments delivered by the request object to the local controller arguments.
  *
  * @return void
  * @author Robert Lemke <*****@*****.**>
  */
 protected function mapRequestArgumentsToControllerArguments()
 {
     $optionalArgumentNames = array();
     $allArgumentNames = $this->arguments->getArgumentNames();
     foreach ($allArgumentNames as $argumentName) {
         if ($this->arguments[$argumentName]->isRequired() === FALSE) {
             $optionalArgumentNames[] = $argumentName;
         }
     }
     $validator = $this->objectManager->getObject('F3\\FLOW3\\MVC\\Controller\\ArgumentsValidator');
     $this->propertyMapper->mapAndValidate($allArgumentNames, $this->request->getArguments(), $this->arguments, $optionalArgumentNames, $validator);
     $this->argumentsMappingResults = $this->propertyMapper->getMappingResults();
 }