PropertyMapper implements SingletonInterface
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.
Table of Contents
Interfaces
- SingletonInterface
- "empty" interface for singletons (marker interface pattern)
Properties
- $configurationBuilder : PropertyMappingConfigurationBuilder
- $container : ContainerInterface
- $messages : Result
- A list of property mapping messages (errors, warnings) which have occurred on last mapping.
- $typeConverters : array<string|int, mixed>
- A multi-dimensional array which stores the Type Converters available in the system.
Methods
- __construct() : mixed
- convert() : mixed
- Map $source to $targetType, and return the result
- getMessages() : Result
- Get the messages of the last Property Mapping.
- initializeObject() : mixed
- Lifecycle method, called after all dependencies have been injected.
- parseCompositeType() : string
- Parse a composite type like \Foo\Collection<\Bar\Entity> into \Foo\Collection
- resetMessages() : void
- Resets the messages of the last Property Mapping.
- determineSourceType() : string
- Determine the type of the source data, or throw an exception if source was an unsupported format.
- doMapping() : mixed
- Internal function which actually does the property mapping.
- findEligibleConverterWithHighestPriority() : mixed
- findFirstEligibleTypeConverterInObjectHierarchy() : mixed
- Tries to find a suitable type converter for the given source and target type.
- findTypeConverter() : TypeConverterInterface
- Determine the type converter to be used. If no converter has been found, an exception is raised.
- getConvertersForInterfaces() : array<string|int, mixed>
Properties
$configurationBuilder
protected
PropertyMappingConfigurationBuilder
$configurationBuilder
$container
protected
ContainerInterface
$container
$messages
A list of property mapping messages (errors, warnings) which have occurred on last mapping.
protected
Result
$messages
$typeConverters
A multi-dimensional array which stores the Type Converters available in the system.
protected
array<string|int, mixed>
$typeConverters
= []
It has the following structure:
- Dimension: Source Type
- Dimension: Target Type
- Dimension: Priority Value: Type Converter instance
Methods
__construct()
public
__construct(ContainerInterface $container, PropertyMappingConfigurationBuilder $configurationBuilder) : mixed
Parameters
- $container : ContainerInterface
- $configurationBuilder : PropertyMappingConfigurationBuilder
convert()
Map $source to $targetType, and return the result
public
convert(mixed $source, string $targetType[, PropertyMappingConfigurationInterface $configuration = null ]) : mixed
Parameters
- $source : mixed
-
the source data to map. MUST be a simple type, NO object allowed!
- $targetType : string
-
The type of the target; can be either a class name or a simple type.
- $configuration : PropertyMappingConfigurationInterface = null
-
Configuration for the property mapping. If NULL, the PropertyMappingConfigurationBuilder will create a default configuration.
Tags
Return values
mixed —an instance of $targetType
getMessages()
Get the messages of the last Property Mapping.
public
getMessages() : Result
Return values
ResultinitializeObject()
Lifecycle method, called after all dependencies have been injected.
public
initializeObject() : mixed
Here, the typeConverter array gets initialized.
only to be used within Extbase, not part of TYPO3 Core API.
Tags
parseCompositeType()
Parse a composite type like \Foo\Collection<\Bar\Entity> into \Foo\Collection
public
parseCompositeType(string $compositeType) : string
Parameters
- $compositeType : string
only to be used within Extbase, not part of TYPO3 Core API.
Return values
stringresetMessages()
Resets the messages of the last Property Mapping.
public
resetMessages() : void
determineSourceType()
Determine the type of the source data, or throw an exception if source was an unsupported format.
protected
determineSourceType(mixed $source) : string
Parameters
- $source : mixed
Tags
Return values
string —the type of $source
doMapping()
Internal function which actually does the property mapping.
protected
doMapping(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration, array<string|int, mixed> &$currentPropertyPath) : mixed
Parameters
- $source : mixed
-
the source data to map. MUST be a simple type, NO object allowed!
- $targetType : string
-
The type of the target; can be either a class name or a simple type.
- $configuration : PropertyMappingConfigurationInterface
-
Configuration for the property mapping.
- $currentPropertyPath : array<string|int, mixed>
-
The property path currently being mapped; used for knowing the context in case an exception is thrown.
Tags
Return values
mixed —an instance of $targetType
findEligibleConverterWithHighestPriority()
protected
findEligibleConverterWithHighestPriority(mixed $converters, mixed $source, string $targetType) : mixed
Parameters
- $converters : mixed
- $source : mixed
- $targetType : string
Return values
mixed —Either the matching object converter or NULL
findFirstEligibleTypeConverterInObjectHierarchy()
Tries to find a suitable type converter for the given source and target type.
protected
findFirstEligibleTypeConverterInObjectHierarchy(string $source, string $sourceType, string $targetClass) : mixed
Parameters
- $source : string
-
The actual source value
- $sourceType : string
-
Type of the source to convert from
- $targetClass : string
-
Name of the target class to find a type converter for
Tags
Return values
mixed —Either the matching object converter or NULL
findTypeConverter()
Determine the type converter to be used. If no converter has been found, an exception is raised.
protected
findTypeConverter(mixed $source, string $targetType, PropertyMappingConfigurationInterface $configuration) : TypeConverterInterface
Parameters
- $source : mixed
- $targetType : string
- $configuration : PropertyMappingConfigurationInterface
Tags
Return values
TypeConverterInterface —Type Converter which should be used to convert between $source and $targetType.
getConvertersForInterfaces()
protected
getConvertersForInterfaces(array<string|int, mixed> $convertersForSource, array<string|int, mixed> $interfaceNames) : array<string|int, mixed>
Parameters
- $convertersForSource : array<string|int, mixed>
- $interfaceNames : array<string|int, mixed>