StringConverter
class StringConverter extends AbstractTypeConverter (View source)
Converter which transforms simple types to a string.
- If the source is a DateTime instance, it will be formatted as string. The format can be set via CONFIGURATION_DATE_FORMAT.
- If the source is an array, it will be converted to a CSV string or JSON, depending on CONFIGURATION_ARRAY_FORMAT.
For array to CSV string, the delimiter can be set via CONFIGURATION_CSV_DELIMITER.
Constants
CONFIGURATION_DATE_FORMAT |
|
DEFAULT_DATE_FORMAT |
The default date format is "YYYY-MM-DDT##:##:##+##:##", for example "2005-08-15T15:52:01+00:00"
according to the W3C standard http://www.w3.org/TR/NOTE-datetime.html |
CONFIGURATION_ARRAY_FORMAT |
|
DEFAULT_ARRAY_FORMAT |
|
ARRAY_FORMAT_CSV |
|
ARRAY_FORMAT_JSON |
|
CONFIGURATION_CSV_DELIMITER |
|
DEFAULT_CSV_DELIMITER |
|
Properties
protected string[] | $sourceTypes | ||
protected string | $targetType | ||
protected int | $priority |
Methods
Returns the list of source types the TypeConverter can handle.
Return the target type this TypeConverter converts to.
Returns the $originalTargetType unchanged in this implementation.
Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.
This implementation always returns true for this method.
Returns an empty list of sub property names
This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.
Actually convert from $source to $targetType, taking into account the fully built $convertedChildProperties and $configuration.
Determines the date format to use for the conversion.
Determines the delimiter to use for the conversion from array to CSV format.
Determines the format to use for the conversion from array to string.
Details
string[]
getSupportedSourceTypes()
Returns the list of source types the TypeConverter can handle.
Must be PHP simple types, classes or object is not allowed.
string
getSupportedTargetType()
Return the target type this TypeConverter converts to.
Can be a simple type or a class name.
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)
Actually convert from $source to $targetType, taking into account the fully built $convertedChildProperties and $configuration.
protected string
getDateFormat(PropertyMappingConfigurationInterface $configuration = null)
Determines the date format to use for the conversion.
If no format is specified in the mapping configuration DEFAULT_DATE_FORMAT is used.
protected string
getCsvDelimiter(PropertyMappingConfigurationInterface $configuration = null)
Determines the delimiter to use for the conversion from array to CSV format.
If no delimiter is specified in the mapping configuration DEFAULT_CSV_DELIMITER is used.
protected string
getArrayFormat(PropertyMappingConfigurationInterface $configuration = null)
Determines the format to use for the conversion from array to string.
If no format is specified in the mapping configuration DEFAULT_ARRAY_FORMAT is used.