Esempio n. 1
0
 /**
  * @param array $row
  * @return object
  */
 public function hydrate(array $row)
 {
     $dto = $this->getNewDtoInstance();
     foreach ($row as $column => $value) {
         if (ObjectAccess::isPropertySettable($dto, $column)) {
             ObjectAccess::setProperty($dto, $column, $value);
         }
     }
     return $dto;
 }
 /**
  * @param string $dataSourceIdentifier
  * @param NodeInterface $node
  * @return string
  * @throws NeosException
  */
 public function indexAction($dataSourceIdentifier, NodeInterface $node = null)
 {
     $dataSources = static::getDataSources($this->objectManager);
     if (!isset($dataSources[$dataSourceIdentifier])) {
         throw new NeosException(sprintf('Data source with identifier "%s" does not exist.', $dataSourceIdentifier), 1414088186);
     }
     /** @var $dataSource DataSourceInterface */
     $dataSource = new $dataSources[$dataSourceIdentifier]();
     if (ObjectAccess::isPropertySettable($dataSource, 'controllerContext')) {
         ObjectAccess::setProperty($dataSource, 'controllerContext', $this->controllerContext);
     }
     $arguments = $this->request->getArguments();
     unset($arguments['dataSourceIdentifier']);
     unset($arguments['node']);
     $values = $dataSource->getData($node, $arguments);
     $this->view->assign('value', $values);
 }
Esempio n. 3
0
 /**
  * Factory method which creates the specified transport with the given options.
  *
  * @param string $transportType Object name of the transport to create
  * @param array $transportOptions Options for the transport
  * @param array $transportArguments Constructor arguments for the transport
  * @return \TYPO3\SwiftMailer\TransportInterface The created transport instance
  * @throws Exception
  */
 public function create($transportType, array $transportOptions = array(), array $transportArguments = NULL)
 {
     if (!class_exists($transportType)) {
         throw new Exception('The specified transport backend "' . $transportType . '" does not exist.', 1269351207);
     }
     if (is_array($transportArguments)) {
         $class = new \ReflectionClass($transportType);
         $transport = $class->newInstanceArgs($transportArguments);
     } else {
         $transport = new $transportType();
     }
     foreach ($transportOptions as $optionName => $optionValue) {
         if (ObjectAccess::isPropertySettable($transport, $optionName)) {
             ObjectAccess::setProperty($transport, $optionName, $optionValue);
         }
     }
     return $transport;
 }
 /**
  *
  * @param string $objectName
  * @param array $overrideProperties
  * @param boolean $addObjectToPersistence
  * @return object
  */
 public function buildObject($objectName, $overrideProperties = array(), $addObjectToPersistence = FALSE)
 {
     if (!isset($this->fixtureDefinitions[$objectName])) {
         throw new \Exception('Object name ' . $objectName . ' not configured in fixture definitions');
     }
     $properties = \TYPO3\Flow\Utility\Arrays::arrayMergeRecursiveOverrule($this->fixtureDefinitions[$objectName], $overrideProperties);
     $className = isset($properties['__type']) ? $properties['__type'] : $this->baseType;
     unset($properties['__type']);
     $object = new $className();
     foreach ($properties as $propertyName => $propertyValue) {
         if (\TYPO3\Flow\Reflection\ObjectAccess::isPropertySettable($object, $propertyName)) {
             \TYPO3\Flow\Reflection\ObjectAccess::setProperty($object, $propertyName, $propertyValue);
         }
     }
     $this->setCustomProperties($object, $properties, $addObjectToPersistence);
     if ($addObjectToPersistence) {
         $this->addObjectToPersistence($object);
     }
     return $object;
 }
Esempio n. 5
0
 /**
  * @param array $serializedMessage
  * @return Message
  */
 public function unserialize($serializedMessage)
 {
     if (is_array($serializedMessage) === FALSE) {
         throw new \InvalidArgumentException('The ArraySerializer can only unserialize arrays.', 1427369045);
     }
     if (array_key_exists('messageType', $serializedMessage) === FALSE || array_key_exists('payload', $serializedMessage) === FALSE || is_array($serializedMessage['payload']) === FALSE) {
         throw new \InvalidArgumentException('The serialized message is corrupted.', 1427369459);
     }
     $messageType = str_replace('.', '\\', $serializedMessage['messageType']);
     if (class_exists($messageType) === FALSE) {
         throw new \InvalidArgumentException('Unserialization for message of type "' . $messageType . '" failed. No such class.', 1427369534);
     }
     $message = new $messageType();
     foreach ($serializedMessage['payload'] as $propertyName => $propertyValue) {
         if (ObjectAccess::isPropertySettable($message, $propertyName)) {
             ObjectAccess::setProperty($message, $propertyName, $propertyValue);
         }
     }
     return $message;
 }
 /**
  * Convert an object from $source to an entity or a value object.
  *
  * @param mixed $source
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return object|TargetNotFoundError the converted entity/value object or an instance of TargetNotFoundError if the object could not be resolved
  * @throws \InvalidArgumentException|InvalidTargetException
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = NULL)
 {
     if (is_array($source)) {
         if ($this->reflectionService->isClassAnnotatedWith($targetType, 'TYPO3\\Flow\\Annotations\\ValueObject')) {
             // Unset identity for value objects to use constructor mapping, since the identity is determined from
             // property values after construction
             unset($source['__identity']);
         }
         $object = $this->handleArrayData($source, $targetType, $convertedChildProperties, $configuration);
         if ($object instanceof TargetNotFoundError) {
             return $object;
         }
     } elseif (is_string($source)) {
         if ($source === '') {
             return NULL;
         }
         $object = $this->fetchObjectFromPersistence($source, $targetType);
         if ($object === NULL) {
             return new TargetNotFoundError(sprintf('Object of type "%s" with identity "%s" not found.', $targetType, $source), 1412283033);
         }
     } else {
         throw new \InvalidArgumentException('Only strings and arrays are accepted.', 1305630314);
     }
     $objectConstructorArguments = $this->getConstructorArgumentsForClass(get_class($object));
     foreach ($convertedChildProperties as $propertyName => $propertyValue) {
         // We need to check for "immutable" constructor arguments that have no setter and remove them.
         if (isset($objectConstructorArguments[$propertyName]) && !ObjectAccess::isPropertySettable($object, $propertyName)) {
             $currentPropertyValue = ObjectAccess::getProperty($object, $propertyName);
             if ($currentPropertyValue === $propertyValue) {
                 continue;
             } else {
                 $exceptionMessage = sprintf('Property "%s" having a value of type "%s" could not be set in target object of type "%s". The property has no setter and is not equal to the value in the object, in that case it would have been skipped.', $propertyName, is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue), $targetType);
                 throw new InvalidTargetException($exceptionMessage, 1421498771);
             }
         }
         $result = ObjectAccess::setProperty($object, $propertyName, $propertyValue);
         if ($result === FALSE) {
             $exceptionMessage = sprintf('Property "%s" having a value of type "%s" could not be set in target object of type "%s". Make sure that the property is accessible properly, for example via an appropriate setter method.', $propertyName, is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue), $targetType);
             throw new InvalidTargetException($exceptionMessage, 1297935345);
         }
     }
     return $object;
 }
 /**
  * Sets the specified property.
  * If the node has a content object attached, the property will be set there
  * if it is settable.
  *
  * @param string $propertyName Name of the property
  * @param mixed $value Value of the property
  * @return void
  */
 public function setProperty($propertyName, $value)
 {
     if (!is_object($this->contentObjectProxy)) {
         switch ($this->getNodeType()->getPropertyType($propertyName)) {
             case 'references':
                 $nodeIdentifiers = array();
                 if (is_array($value)) {
                     foreach ($value as $nodeIdentifier) {
                         if ($nodeIdentifier instanceof NodeInterface || $nodeIdentifier instanceof AbstractNodeData) {
                             $nodeIdentifiers[] = $nodeIdentifier->getIdentifier();
                         } elseif (preg_match(UuidValidator::PATTERN_MATCH_UUID, $nodeIdentifier) !== 0) {
                             $nodeIdentifiers[] = $nodeIdentifier;
                         }
                     }
                 }
                 $value = $nodeIdentifiers;
                 break;
             case 'reference':
                 $nodeIdentifier = NULL;
                 if ($value instanceof NodeInterface || $value instanceof AbstractNodeData) {
                     $nodeIdentifier = $value->getIdentifier();
                 } elseif (preg_match(UuidValidator::PATTERN_MATCH_UUID, $value) !== 0) {
                     $nodeIdentifier = $value;
                 }
                 $value = $nodeIdentifier;
                 break;
         }
         if (isset($this->properties[$propertyName]) && $this->properties[$propertyName] === $value) {
             return;
         }
         $this->properties[$propertyName] = $value;
         $this->update();
     } elseif (ObjectAccess::isPropertySettable($this->contentObjectProxy->getObject(), $propertyName)) {
         $contentObject = $this->contentObjectProxy->getObject();
         ObjectAccess::setProperty($contentObject, $propertyName, $value);
         $this->updateContentObject($contentObject);
     }
 }
 /**
  * @test
  */
 public function isPropertySettableWorksOnStdClass()
 {
     $stdClassObject = new \stdClass();
     $stdClassObject->property = 'foo';
     $this->assertTrue(ObjectAccess::isPropertySettable($stdClassObject, 'property'));
     $this->assertFalse(ObjectAccess::isPropertySettable($stdClassObject, 'undefinedProperty'));
 }