Neos\Flow\Property\TypeConverter\MediaTypeConverter::convertFrom PHP Метод

convertFrom() публичный Метод

Convert the given $source to $targetType depending on the MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE property mapping configuration
public convertFrom ( string $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : array
$source string the raw request body
$targetType string must be "array"
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
Результат array
    public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
    {
        $mediaType = null;
        if ($configuration !== null) {
            $mediaType = $configuration->getConfigurationValue(MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE);
        }
        if ($mediaType === null) {
            $mediaType = MediaTypeConverterInterface::DEFAULT_MEDIA_TYPE;
        }
        return $this->convertMediaType($source, $mediaType);
    }

Usage Example

 /**
  * @test
  * @dataProvider contentTypesBodiesAndExpectedUnifiedArguments
  */
 public function convertTests($mediaType, $requestBody, array $expectedResult)
 {
     $this->mockPropertyMappingConfiguration->expects($this->atLeastOnce())->method('getConfigurationValue')->with(MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE)->will($this->returnValue($mediaType));
     $actualResult = $this->mediaTypeConverter->convertFrom($requestBody, 'array', [], $this->mockPropertyMappingConfiguration);
     $this->assertSame($expectedResult, $actualResult);
 }