class PropertyMapper (View source)

The Property Mapper transforms simple types (arrays, strings, integers, floats, booleans) to objects or other simple types.

It is used most prominently to map incoming HTTP arguments to objects.

Properties

protected ObjectManagerInterface $objectManager
protected VariableFrontend $cache
protected array $typeConverters

A multi-dimensional array which stores the Type Converters available in the system.

protected Result $messages

A list of property mapping messages (errors, warnings) which have occured on last mapping.

Methods

void
initializeObject()

Lifecycle method, called after all dependencies have been injected.

static array
getTypeConverterImplementationClassNames(ObjectManagerInterface $objectManager)

Returns all class names implementing the TypeConverterInterface.

mixed
convert(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration = null)

Map $source to $targetType, and return the result.

getMessages()

Get the messages of the last Property Mapping

mixed
doMapping(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration, array $currentPropertyPath)

Internal function which actually does the property mapping.

findTypeConverter(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration)

Determine the type converter to be used. If no converter has been found, an exception is raised.

mixed
findFirstEligibleTypeConverterInObjectHierarchy(string $source, string $sourceType, string $targetType)

Tries to find a suitable type converter for the given source and target type.

mixed
findEligibleConverterWithHighestPriority(mixed $converters, mixed $source, string $targetType)

No description

array
getConvertersForInterfaces(array $convertersForSource, array $interfaceNames)

No description

array
determineSourceTypes(mixed $source)

Determine the type of the source data, or throw an exception if source was an unsupported format.

array
prepareTypeConverterMap()

Collects all TypeConverter implementations in a multi-dimensional array with source and target types.

array
getTypeConverters()

Returns a multi-dimensional array with the Type Converters available in the system.

buildPropertyMappingConfiguration(string $type = PropertyMappingConfiguration::class)

Builds the default property mapping configuration.

Details

void initializeObject()

Lifecycle method, called after all dependencies have been injected.

Here, the typeConverter array gets initialized.

Return Value

void

static array getTypeConverterImplementationClassNames(ObjectManagerInterface $objectManager)

Returns all class names implementing the TypeConverterInterface.

Parameters

ObjectManagerInterface $objectManager

Return Value

array

Array of type converter implementations

mixed convert(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration = null)

Map $source to $targetType, and return the result.

If $source is an object and already is of type $targetType, we do return the unmodified object.

Parameters

mixed $source

the source data to map. MUST be a simple type, NO object allowed!

string $targetType

The type of the target; can be either a class name or a simple type.

PropertyMappingConfigurationInterface $configuration

Configuration for the property mapping. If NULL, the PropertyMappingConfigurationBuilder will create a default configuration.

Return Value

mixed

an instance of $targetType

Exceptions

Exception
Exception

Result getMessages()

Get the messages of the last Property Mapping

Return Value

Result

protected mixed doMapping(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration, array $currentPropertyPath)

Internal function which actually does the property mapping.

Parameters

mixed $source

the source data to map. MUST be a simple type, NO object allowed!

string $targetType

The type of the target; can be either a class name or a simple type.

PropertyMappingConfigurationInterface $configuration

Configuration for the property mapping.

array $currentPropertyPath

The property path currently being mapped; used for knowing the context in case an exception is thrown.

Return Value

mixed

an instance of $targetType

Exceptions

TypeConverterException
InvalidPropertyMappingConfigurationException

protected TypeConverterInterface findTypeConverter(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration)

Determine the type converter to be used. If no converter has been found, an exception is raised.

Parameters

mixed $source
string $targetType
PropertyMappingConfigurationInterface $configuration

Return Value

TypeConverterInterface

Type Converter which should be used to convert between $source and $targetType.

Exceptions

TypeConverterException
InvalidTargetException

protected mixed findFirstEligibleTypeConverterInObjectHierarchy(string $source, string $sourceType, string $targetType)

Tries to find a suitable type converter for the given source and target type.

Parameters

string $source

The actual source value

string $sourceType

Type of the source to convert from

string $targetType

Name of the target type to find a type converter for

Return Value

mixed

Either the matching object converter or NULL

Exceptions

InvalidTargetException

protected mixed findEligibleConverterWithHighestPriority(mixed $converters, mixed $source, string $targetType)

No description

Parameters

mixed $converters
mixed $source
string $targetType

Return Value

mixed

Either the matching object converter or NULL

protected array getConvertersForInterfaces(array $convertersForSource, array $interfaceNames)

No description

Parameters

array $convertersForSource
array $interfaceNames

Return Value

array

Exceptions

DuplicateTypeConverterException

protected array determineSourceTypes(mixed $source)

Determine the type of the source data, or throw an exception if source was an unsupported format.

Parameters

mixed $source

Return Value

array

Possible source types (single value for simple typed source, multiple values for object source)

Exceptions

InvalidSourceException

protected array prepareTypeConverterMap()

Collects all TypeConverter implementations in a multi-dimensional array with source and target types.

Return Value

array

Exceptions

DuplicateTypeConverterException

See also

getTypeConverters

array getTypeConverters()

Returns a multi-dimensional array with the Type Converters available in the system.

It has the following structure:

  1. Dimension: Source Type
  2. Dimension: Target Type
  3. Dimension: Priority Value: Type Converter instance

Return Value

array

PropertyMappingConfiguration buildPropertyMappingConfiguration(string $type = PropertyMappingConfiguration::class)

Builds the default property mapping configuration.

Parameters

string $type

the implementation class name of the PropertyMappingConfiguration to instantiate; must be a subclass of Neos\Flow\Property\PropertyMappingConfiguration

Return Value

PropertyMappingConfiguration