MediaTypeConverter
class MediaTypeConverter extends AbstractTypeConverter implements MediaTypeConverterInterface (View source)
Converter which transforms strings to arrays using the configured strategy.
This TypeConverter is used by default to decode the content of a HTTP request and it currently supports json and xml based media types as well as urlencoded content.
Properties
protected string | $sourceTypes | ||
protected string | $targetType | ||
protected int | $priority | This converter is not used automatically |
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.
Convert the given $source to $targetType depending on the MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE property mapping configuration
Converts the given request body according to the specified media type Override this method in your custom TypeConverter to support additional media types
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|null
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 the given $source to $targetType depending on the MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE property mapping configuration
protected array|string|int
convertMediaType(string $requestBody, string $mediaType)
Converts the given request body according to the specified media type Override this method in your custom TypeConverter to support additional media types