/**
  * Actually convert from $source to $targetType, taking into account the fully
  * built $convertedChildProperties and $configuration.
  *
  * The return value can be one of three types:
  * - an arbitrary object, or a simple type (which has been created while mapping).
  *   This is the normal case.
  * - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur.
  * - An instance of \TYPO3\Flow\Error\Error -- This will be a user-visible error message later on.
  * Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened.
  *
  * @param mixed $source
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return mixed|\TYPO3\Flow\Error\Error the target type, or an error object if a user-error occurred
  * @throws \TYPO3\Flow\Property\Exception\TypeConverterException thrown in case a developer error occurred
  * @api
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null)
 {
     $properties = ObjectAccess::getGettableProperties($source);
     if ($source instanceof \Doctrine\ORM\Proxy\Proxy) {
         $className = get_parent_class($source);
     } else {
         $className = get_class($source);
     }
     $properties = array_merge($properties, $convertedChildProperties);
     if ($source instanceof \TYPO3\Flow\Persistence\Aspect\PersistenceMagicInterface) {
         $properties['__identity'] = $this->persistenceManager->getIdentifierByObject($source);
     }
     $properties['__type'] = $className;
     return $properties;
 }
 /**
  * Convert an object from \TYPO3\Media\Domain\Model\ImageInterface to a json representation
  *
  * @param ImageInterface $source
  * @param string $targetType must be 'string'
  * @param array $convertedChildProperties
  * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration
  * @return string|\TYPO3\Flow\Validation\Error The converted Image, a Validation Error or NULL
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL)
 {
     $data = array('__identity' => $this->persistenceManager->getIdentifierByObject($source), '__type' => TypeHandling::getTypeForValue($source));
     if ($source instanceof \TYPO3\Media\Domain\Model\ImageVariant) {
         $data['originalAsset'] = ['__identity' => $this->persistenceManager->getIdentifierByObject($source->getOriginalAsset())];
         $adjustments = array();
         foreach ($source->getAdjustments() as $adjustment) {
             $index = TypeHandling::getTypeForValue($adjustment);
             $adjustments[$index] = array();
             foreach (\TYPO3\Flow\Reflection\ObjectAccess::getGettableProperties($adjustment) as $propertyName => $propertyValue) {
                 $adjustments[$index][$propertyName] = $propertyValue;
             }
         }
         $data['adjustments'] = $adjustments;
     }
     return $data;
 }
 /**
  * Returns all properties of this node.
  *
  * If the node has a content object attached, the properties will be fetched
  * there.
  *
  * @param boolean $returnNodesAsIdentifiers If enabled, references to nodes are returned as node identifiers instead of NodeData objects
  * @param \TYPO3\TYPO3CR\Domain\Service\Context $context An optional Context if $returnNodesAsIdentifiers === TRUE
  * @return array Property values, indexed by their name
  */
 public function getProperties($returnNodesAsIdentifiers = FALSE, \TYPO3\TYPO3CR\Domain\Service\Context $context = NULL)
 {
     if (is_object($this->contentObjectProxy)) {
         return ObjectAccess::getGettableProperties($this->contentObjectProxy->getObject());
     }
     $properties = array();
     foreach (array_keys($this->properties) as $propertyName) {
         $properties[$propertyName] = $this->getProperty($propertyName, $returnNodesAsIdentifiers, $context);
     }
     return $properties;
 }
 /**
  * Returns all properties of this node.
  *
  * If the node has a content object attached, the properties will be fetched
  * there.
  *
  * @return array Property values, indexed by their name
  */
 public function getProperties()
 {
     if (is_object($this->contentObjectProxy)) {
         return ObjectAccess::getGettableProperties($this->contentObjectProxy->getObject());
     }
     $properties = array();
     foreach (array_keys($this->properties) as $propertyName) {
         $properties[$propertyName] = $this->getProperty($propertyName);
     }
     return $properties;
 }
 /**
  * @test
  */
 public function getGettablePropertiesReturnsPropertiesOfStdClass()
 {
     $stdClassObject = new \stdClass();
     $stdClassObject->property = 'string1';
     $stdClassObject->property2 = NULL;
     $stdClassObject->publicProperty2 = 42;
     $expectedProperties = array('property' => 'string1', 'property2' => NULL, 'publicProperty2' => 42);
     $actualProperties = ObjectAccess::getGettableProperties($stdClassObject);
     $this->assertEquals($expectedProperties, $actualProperties, 'expectedProperties did not return the right values for the properties.');
 }
 /**
  * @test
  */
 public function getGettablePropertiesHandlesDoctrineProxy()
 {
     $proxyObject = new \TYPO3\Flow\Tests\Reflection\Fixture\Model\EntityWithDoctrineProxy();
     $expectedProperties = array();
     $actualProperties = ObjectAccess::getGettableProperties($proxyObject);
     $this->assertEquals($expectedProperties, $actualProperties, 'expectedProperties did not return the right values for the properties.');
 }
Esempio n. 7
0
 /**
  * @param Message $message
  * @return array
  */
 public function serialize(Message $message)
 {
     $messageType = new ObjectName($message);
     $data = ObjectAccess::getGettableProperties($message);
     return ['messageType' => $messageType->getName(), 'payload' => $data];
 }
 /**
  * Apply the given adjustment to the image variant.
  * If an adjustment of the given type already exists, the existing one will be overridden by the new one.
  *
  * @param ImageAdjustmentInterface $adjustment
  * @return void
  */
 protected function applyAdjustment(ImageAdjustmentInterface $adjustment)
 {
     $existingAdjustmentFound = false;
     $newAdjustmentClassName = TypeHandling::getTypeForValue($adjustment);
     foreach ($this->adjustments as $existingAdjustment) {
         if (TypeHandling::getTypeForValue($existingAdjustment) === $newAdjustmentClassName) {
             foreach (ObjectAccess::getGettableProperties($adjustment) as $propertyName => $propertyValue) {
                 ObjectAccess::setProperty($existingAdjustment, $propertyName, $propertyValue);
             }
             $existingAdjustmentFound = true;
         }
     }
     if (!$existingAdjustmentFound) {
         $this->adjustments->add($adjustment);
         $adjustment->setImageVariant($this);
         $this->adjustments = $this->adjustments->matching(new \Doctrine\Common\Collections\Criteria(null, array('position' => 'ASC')));
     }
     $this->lastModified = new \DateTime();
 }
Esempio n. 9
0
 /**
  * @param Message $message
  * @return array
  */
 public function serialize(Message $message)
 {
     $type = str_replace('\\', '.', get_class($message));
     $data = ObjectAccess::getGettableProperties($message);
     return ['messageType' => $type, 'payload' => $data];
 }