Neos\Flow\ResourceManagement\ResourceTypeConverter::convertFrom PHP Метод

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

If the input format is an array, this method assumes the resource to be a fresh file upload and imports the temporary upload file through the ResourceManager. Note that $source['error'] will also be present if a file was successfully uploaded. In that case its value will be \UPLOAD_ERR_OK.
public convertFrom ( array $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : PersistentResource | Neos\Error\Messages\Error
$source array The upload info (expected keys: error, name, tmp_name)
$targetType string
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
Результат PersistentResource | Neos\Error\Messages\Error 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;
    }

Usage Example

 /**
  * @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);
 }