/**
  * @test
  * @author Robert Lemke <*****@*****.**>
  */
 public function isPropertyGettableTellsIfAPropertyCanBeRetrieved()
 {
     $this->assertTrue(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject, 'publicProperty'));
     $this->assertTrue(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject, 'property'));
     $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject, 'privateProperty'));
     $this->assertFalse(\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($this->dummyObject, 'writeOnlyMagicProperty'));
 }
 /**
  * Checks if the specified property of the given object is valid.
  *
  * If at least one error occurred, the result is FALSE.
  *
  * @param object $object The object containing the property to validate
  * @param string $propertyName Name of the property to validate
  * @return boolean TRUE if the property value is valid, FALSE if an error occured
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function isPropertyValid($object, $propertyName)
 {
     if (!is_object($object)) {
         throw new \InvalidArgumentException('Object expected, ' . gettype($object) . ' given.', 1241099149);
     }
     if (!isset($this->propertyValidators[$propertyName])) {
         return TRUE;
     }
     $result = TRUE;
     foreach ($this->propertyValidators[$propertyName] as $validator) {
         if (\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($object, $propertyName)) {
             $propertyValue = \F3\FLOW3\Reflection\ObjectAccess::getProperty($object, $propertyName);
         } else {
             $propertyReflection = new \F3\FLOW3\Reflection\PropertyReflection(get_class($object), $propertyName);
             $propertyReflection->setAccessible(TRUE);
             $propertyValue = $propertyReflection->getValue($object);
         }
         if ($validator->isValid($propertyValue) === FALSE) {
             $this->addErrorsForProperty($validator->getErrors(), $propertyName);
             $result = FALSE;
         }
     }
     return $result;
 }
 /**
  * Maps the given properties to the target object WITHOUT VALIDATING THE RESULT.
  * If the properties could be set, this method returns TRUE, otherwise FALSE.
  * Returning TRUE does not mean that the target object is valid and secure!
  *
  * Only use this method if you're sure that you don't need validation!
  *
  * @param array $propertyNames Names of the properties to map.
  * @param mixed $source Source containing the properties to map to the target object. Must either be an array, ArrayObject or any other object.
  * @param object $target The target object
  * @param array $optionalPropertyNames Names of optional properties. If a property is specified here and it doesn't exist in the source, no error is issued.
  * @return boolean TRUE if the properties could be mapped, otherwise FALSE
  * @see mapAndValidate()
  * @author Robert Lemke <*****@*****.**>
  * @api
  */
 public function map(array $propertyNames, $source, &$target, $optionalPropertyNames = array())
 {
     if (!is_object($source) && !is_array($source)) {
         throw new \F3\FLOW3\Property\Exception\InvalidSourceException('The source object must be a valid object or array, ' . gettype($target) . ' given.', 1187807099);
     }
     if (is_string($target) && strpos($target, '\\') !== FALSE) {
         return $this->transformToObject($source, $target, '--none--');
     }
     $this->mappingResults = $this->objectManager->getObject('F3\\FLOW3\\Property\\MappingResults');
     if (!is_object($target) && !is_array($target)) {
         throw new \F3\FLOW3\Property\Exception\InvalidTargetException('The target must be a valid object, class name or array, ' . gettype($target) . ' given.', 1187807099);
     }
     if (is_object($target)) {
         $targetClassSchema = $this->reflectionService->getClassSchema($target);
     } else {
         $targetClassSchema = NULL;
     }
     foreach ($propertyNames as $propertyName) {
         $propertyValue = NULL;
         if (is_array($source) || $source instanceof \ArrayAccess) {
             if (isset($source[$propertyName])) {
                 $propertyValue = $source[$propertyName];
             }
         } elseif (\F3\FLOW3\Reflection\ObjectAccess::isPropertyGettable($source, $propertyName)) {
             $propertyValue = \F3\FLOW3\Reflection\ObjectAccess::getProperty($source, $propertyName);
         }
         if ($propertyValue === NULL && !in_array($propertyName, $optionalPropertyNames)) {
             $this->mappingResults->addError($this->objectManager->getObject('F3\\FLOW3\\Error\\Error', "Required property '{$propertyName}' does not exist in source.", 1236785359), $propertyName);
         } else {
             if (method_exists($target, \F3\FLOW3\Reflection\ObjectAccess::buildSetterMethodName($propertyName)) && is_callable(array($target, \F3\FLOW3\Reflection\ObjectAccess::buildSetterMethodName($propertyName)))) {
                 $targetClassName = $target instanceof \F3\FLOW3\AOP\ProxyInterface ? $target->FLOW3_AOP_Proxy_getProxyTargetClassName() : get_class($target);
                 $methodParameters = $this->reflectionService->getMethodParameters($targetClassName, \F3\FLOW3\Reflection\ObjectAccess::buildSetterMethodName($propertyName));
                 $methodParameter = current($methodParameters);
                 $targetPropertyType = \F3\FLOW3\Utility\TypeHandling::parseType($methodParameter['type']);
             } elseif ($targetClassSchema !== NULL && $targetClassSchema->hasProperty($propertyName)) {
                 $targetPropertyType = $targetClassSchema->getProperty($propertyName);
             } elseif ($targetClassSchema !== NULL) {
                 $this->mappingResults->addError($this->objectManager->getObject('F3\\FLOW3\\Error\\Error', "Property '{$propertyName}' does not exist in target class schema.", 1251813614), $propertyName);
                 continue;
             }
             if (isset($targetPropertyType)) {
                 if (in_array($targetPropertyType['type'], array('array', 'ArrayObject', 'SplObjectStorage')) && strpos($targetPropertyType['elementType'], '\\') !== FALSE) {
                     $objects = array();
                     foreach ($propertyValue as $value) {
                         $objects[] = $this->transformToObject($value, $targetPropertyType['elementType'], $propertyName);
                     }
                     if ($targetPropertyType['type'] === 'ArrayObject') {
                         $propertyValue = new \ArrayObject($objects);
                     } elseif ($targetPropertyType['type'] === 'SplObjectStorage') {
                         $propertyValue = new \SplObjectStorage();
                         foreach ($objects as $object) {
                             $propertyValue->attach($object);
                         }
                     } else {
                         $propertyValue = $objects;
                     }
                 } elseif (strpos($targetPropertyType['type'], '\\') !== FALSE) {
                     $propertyValue = $this->transformToObject($propertyValue, $targetPropertyType['type'], $propertyName);
                 }
             }
             if (is_array($target)) {
                 $target[$propertyName] = $propertyValue;
             } elseif (\F3\FLOW3\Reflection\ObjectAccess::setProperty($target, $propertyName, $propertyValue) === FALSE) {
                 $this->mappingResults->addError($this->objectManager->getObject('F3\\FLOW3\\Error\\Error', "Property '{$propertyName}' could not be set.", 1236783102), $propertyName);
             }
         }
     }
     return !$this->mappingResults->hasErrors();
 }