class ArrayConverter extends AbstractTypeConverter (View source)

Converter which transforms various types to arrays.

  • If the source is an array, it is returned unchanged.
  • If the source is a string, is is converted depending on CONFIGURATION_STRING_FORMAT, which can be STRING_FORMAT_CSV or STRING_FORMAT_JSON. For CSV the delimiter can be set via CONFIGURATION_STRING_DELIMITER.
  • If the source is a PersistentResource object, it is converted to an array. The actual resource content is either embedded as base64-encoded data or saved to a file, depending on CONFIGURATION_RESOURCE_EXPORT_TYPE. For RESOURCE_EXPORT_TYPE_FILE the setting CONFIGURATION_RESOURCE_SAVE_PATH must be set as well.

Constants

CONFIGURATION_STRING_DELIMITER

DEFAULT_STRING_DELIMITER

CONFIGURATION_STRING_FORMAT

DEFAULT_STRING_FORMAT

STRING_FORMAT_CSV

STRING_FORMAT_JSON

CONFIGURATION_RESOURCE_EXPORT_TYPE

DEFAULT_RESOURCE_EXPORT_TYPE

RESOURCE_EXPORT_TYPE_BASE64

RESOURCE_EXPORT_TYPE_FILE

CONFIGURATION_RESOURCE_SAVE_PATH

Properties

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

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)

This implementation always returns true for this method.

array
getSourceChildPropertiesToBeConverted(mixed $source)

Returns an empty list of sub property names

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

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

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

Convert from $source to $targetType, a noop if the source is an array.

string
getStringDelimiter(PropertyMappingConfigurationInterface $configuration = null)

No description

string
getStringFormat(PropertyMappingConfigurationInterface $configuration = null)

No description

string
getResourceExportType(PropertyMappingConfigurationInterface $configuration = null)

No description

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)

This implementation always returns true for this method.

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 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

the type of $propertyName in $targetType

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

Convert from $source to $targetType, a noop if the source is an array.

If it is a string it will be converted according to the configured string format.

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

InvalidPropertyMappingConfigurationException
InvalidSourceException
TypeConverterException

protected string getStringDelimiter(PropertyMappingConfigurationInterface $configuration = null)

No description

Parameters

PropertyMappingConfigurationInterface $configuration

Return Value

string

Exceptions

InvalidPropertyMappingConfigurationException

protected string getStringFormat(PropertyMappingConfigurationInterface $configuration = null)

No description

Parameters

PropertyMappingConfigurationInterface $configuration

Return Value

string

Exceptions

InvalidPropertyMappingConfigurationException

protected string getResourceExportType(PropertyMappingConfigurationInterface $configuration = null)

No description

Parameters

PropertyMappingConfigurationInterface $configuration

Return Value

string

Exceptions

InvalidPropertyMappingConfigurationException