interface TypeConverterInterface (View source)

Interface for type converters, which can convert from a simple type to an object or another simple type.

All Type Converters should have NO INTERNAL STATE, such that they can be used as singletons and multiple times in succession (as this improves performance dramatically).

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 type for a given source, depending on e.g. the __type setting or other properties.

int
getPriority()

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

bool
canConvertFrom(mixed $source, string $targetType)

Here, the TypeConverter can do some additional runtime checks to see whether it can handle the given source data and the given target type.

array
getSourceChildPropertiesToBeConverted(mixed $source)

Return a list of sub-properties inside the source object.

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

Return the type of a given sub-property inside the $targetType

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

Actually convert from $source to $targetType, taking into account the fully built $convertedChildProperties and $configuration.

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 type for a given source, depending on e.g. the __type setting or other properties.

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)

Here, the TypeConverter can do some additional runtime checks to see whether it can handle the given source data and the given target 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)

Return a list of sub-properties inside the source object.

The "key" is the sub-property name, and the "value" is the value of the sub-property.

Parameters

mixed $source

Return Value

array

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

Return the type of a given sub-property inside the $targetType

Parameters

string $targetType
string $propertyName
PropertyMappingConfigurationInterface $configuration

Return Value

string|null

the type of $propertyName in $targetType

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

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.

Parameters

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

Return Value

mixed|null|Error

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

Exceptions

TypeConverterException