ObjectConverter
class ObjectConverter extends AbstractTypeConverter (View source)
This converter transforms arrays to simple objects (POPO) by setting properties.
This converter will only be used on target types that are not entities or value objects (for those the PersistentObjectConverter is used).
The target type can be overridden in the source by setting the __type key to the desired value.
The converter will return an instance of the target type with all properties given in the source array set to the respective values. For the mechanics used to set the values see ObjectAccess::setProperty().
Constants
CONFIGURATION_TARGET_TYPE |
|
CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED |
|
Properties
protected array | $sourceTypes | ||
protected string | $targetType | ||
protected int | $priority | ||
protected ObjectManagerInterface | $objectManager | ||
protected ReflectionService | $reflectionService | ||
protected array | $constructorReflectionFirstLevelCache | As it is very likely that the constructor arguments are needed twice we should cache them for the request. |
Methods
Returns the list of source types the TypeConverter can handle.
Return the target type this TypeConverter converts to.
Determines the target type based on the source's (optional) __type key.
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
Only convert non-persistent types
Convert all properties in the source array
The type of a property is determined by the reflection service.
Convert an object from $source to an object.
Builds a new instance of $objectType with the given $possibleConstructorArgumentValues.
Get the constructor argument reflection for the given object type.
Details
string[]
getSupportedSourceTypes()
Returns the list of source types the TypeConverter can handle.
Must be PHP simple types, classes or object is not allowed.
string
getSupportedTargetType()
Return the target type this TypeConverter converts to.
Can be a simple type or a class name.
string
getTargetTypeForSource(mixed $source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null)
Determines the target type based on the source's (optional) __type key.
int
getPriority()
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
bool
canConvertFrom(mixed $source, string $targetType)
Only convert non-persistent types
array
getSourceChildPropertiesToBeConverted(mixed $source)
Convert all properties in the source array
string
getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)
The type of a property is determined by the reflection service.
mixed|null|Error
convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
Convert an object from $source to an object.
protected object
buildObject(array $possibleConstructorArgumentValues, string $objectType)
Builds a new instance of $objectType with the given $possibleConstructorArgumentValues.
If constructor argument values are missing from the given array the method looks for a default value in the constructor signature.
Furthermore, the constructor arguments are removed from $possibleConstructorArgumentValues
protected array[]
getConstructorArgumentsForClass(string $className)
Get the constructor argument reflection for the given object type.