public convertFrom ( array $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : |
||
$source | array | The upload info (expected keys: error, name, tmp_name) |
$targetType | string | |
$convertedChildProperties | array | |
$configuration | Neos\Flow\Property\PropertyMappingConfigurationInterface | |
return | if the input format is not supported or could not be converted for other reasons |
public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
{
if (empty($source)) {
return null;
}
if (is_string($source)) {
$source = ['hash' => $source];
}
// $source is ALWAYS an array at this point
if (isset($source['error']) || isset($source['originallySubmittedResource'])) {
return $this->handleFileUploads($source, $configuration);
} elseif (isset($source['hash']) || isset($source['data'])) {
return $this->handleHashAndData($source, $configuration);
}
return null;
}
/** * @test */ public function convertFromReturnsAnErrorIfTheUploadedFileCantBeImported() { $this->inject($this->resourceTypeConverter, 'systemLogger', $this->createMock(SystemLoggerInterface::class)); $source = ['tmp_name' => 'SomeFilename', 'error' => \UPLOAD_ERR_OK]; $this->mockResourceManager->expects($this->once())->method('importUploadedResource')->with($source)->will($this->throwException(new Exception())); $actualResult = $this->resourceTypeConverter->convertFrom($source, PersistentResource::class); $this->assertInstanceOf(FlowError\Error::class, $actualResult); }