public convertFrom ( mixed $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : mixed | Neos\Error\Messages\Error | ||
$source | mixed | |
$targetType | string | |
$convertedChildProperties | array | |
$configuration | Neos\Flow\Property\PropertyMappingConfigurationInterface | |
return | mixed | Neos\Error\Messages\Error | the target type, or an error object if a user-error occurred |
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;
}
/** * @test * @dataProvider objectToArrayDataProvider */ public function canConvertFromObjectToArray($source, $expectedResult) { if (is_array($source)) { $source = json_decode(json_encode($source), false); } $convertedChildProperties = array_map(function ($value) { return $this->converter->convertFrom($value, 'array', [], null); }, $this->converter->getSourceChildPropertiesToBeConverted($source)); $this->assertEquals($expectedResult, $this->converter->convertFrom($source, 'array', $convertedChildProperties, null)); }