class ScalarTypeToObjectConverter extends AbstractTypeConverter (View source)

A type converter which converts a scalar type (string, boolean, float or integer) to an object by instantiating the object and passing the string as the constructor argument.

This converter will only be used if the target class has a constructor with exactly one argument whose type must be the given type.

Properties

protected string[] $sourceTypes
protected string $targetType
protected int $priority
protected ReflectionService $reflectionService

Methods

string[]
getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

string
getSupportedTargetType()

Return the target type this TypeConverter converts to.

string
getTargetTypeForSource(mixed $source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null)

Returns the $originalTargetType unchanged in this implementation.

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 if the given target class has a constructor with one argument being of type given type

array
getSourceChildPropertiesToBeConverted(mixed $source)

Returns an empty list of sub property names

string|null
getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)

This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.

mixed|Error
convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)

Convert the given simple type to an object

Details

string[] getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

Must be PHP simple types, classes or object is not allowed.

Return Value

string[]

string getSupportedTargetType()

Return the target type this TypeConverter converts to.

Can be a simple type or a class name.

Return Value

string

string getTargetTypeForSource(mixed $source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null)

Returns the $originalTargetType unchanged in this implementation.

Parameters

mixed $source

the source data

string $originalTargetType

the type we originally want to convert to

PropertyMappingConfigurationInterface $configuration

Return Value

string

int getPriority()

Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.

Return Value

int

bool canConvertFrom(mixed $source, string $targetType)

Only convert if the given target class has a constructor with one argument being of type given type

Parameters

mixed $source

the source data

string $targetType

the type to convert to.

Return Value

bool

true if this TypeConverter can convert from $source to $targetType, false otherwise.

array getSourceChildPropertiesToBeConverted(mixed $source)

Returns an empty list of sub property names

Parameters

mixed $source

Return Value

array

string|null getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)

This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.

Parameters

string $targetType
string $propertyName
PropertyMappingConfigurationInterface $configuration

Return Value

string|null

the type of $propertyName in $targetType

mixed|Error convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)

Convert the given simple type to an object

Parameters

mixed $source
string $targetType
array $convertedChildProperties
PropertyMappingConfigurationInterface $configuration

Return Value

mixed|Error

the target type, or an error object if a user-error occurred