/** * 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 \Neos\Error\Messages\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|Error the target type, or an error object if a user-error occurred * @throws TypeConverterException thrown in case a developer error occurred * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = [], 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 PersistenceMagicInterface) { $properties['__identity'] = $this->persistenceManager->getIdentifierByObject($source); } $properties['__type'] = $className; return $properties; }
/** * Convert an object from \Neos\Media\Domain\Model\ImageInterface to a json representation * * @param ImageInterface $source * @param string $targetType must be 'string' * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return string|Error The converted Image, a Validation Error or NULL */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null) { $data = array('__identity' => $this->persistenceManager->getIdentifierByObject($source), '__type' => TypeHandling::getTypeForValue($source)); if ($source instanceof ImageVariant) { $data['originalAsset'] = ['__identity' => $this->persistenceManager->getIdentifierByObject($source->getOriginalAsset())]; $adjustments = array(); foreach ($source->getAdjustments() as $adjustment) { $index = TypeHandling::getTypeForValue($adjustment); $adjustments[$index] = array(); foreach (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. * * @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 getGettablePropertiesHandlesDoctrineProxy() { $proxyObject = new EntityWithDoctrineProxy(); $expectedProperties = array(); $actualProperties = ObjectAccess::getGettableProperties($proxyObject); $this->assertEquals($expectedProperties, $actualProperties, 'expectedProperties did not return the right values for the properties.'); }
/** * 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 Criteria(null, array('position' => 'ASC'))); } $this->lastModified = new \DateTime(); }