class ResourceTypeConverter extends AbstractTypeConverter (View source)

A type converter for converting strings, array and uploaded files to PersistentResource objects.

Has two major working modes:

  1. File Uploads by PHP

    In this case, the input array is expected to be a fresh file upload following the native PHP handling. The temporary upload file is then imported through the resource manager.

    To enable the handling of files that have already been uploaded earlier, the special field ['originallySubmittedResource'] is checked. If set, it is used to fetch a file that has already been uploaded even if no file has been actually uploaded in the current request.

  2. Strings / arbitrary Arrays

    If the source

    • is an array and contains the key '__identity'

    the converter will find an existing resource with the given identity or continue and assign the given identity if CONFIGURATION_IDENTITY_CREATION_ALLOWED is set.

    • is a string looking like a SHA1 (40 characters [0-9a-f]) or
    • is an array and contains the key 'hash' with a value looking like a SHA1 (40 characters [0-9a-f])

    the converter will look up an existing PersistentResource with that hash and return it if found. If that fails, the converter will try to import a file named like that hash from the configured CONFIGURATION_RESOURCE_LOAD_PATH.

    If no hash is given in an array source but the key 'data' is set, the content of that key is assumed a binary string and a PersistentResource representing this content is created and returned.

    The imported PersistentResource will be given a 'filename' if set in the source array in both cases (import from file or data).

Constants

CONFIGURATION_RESOURCE_LOAD_PATH

CONFIGURATION_IDENTITY_CREATION_ALLOWED

CONFIGURATION_COLLECTION_NAME

Sets the default resource collection name (see Settings: Neos.Flow.resource.collections) to use for this resource, will fallback to ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME

Properties

protected string[] $sourceTypes
protected string $targetType
protected int $priority
protected ResourceManager $resourceManager
protected ResourceRepository $resourceRepository
protected PersistenceManagerInterface $persistenceManager
protected LoggerInterface $logger
protected array $convertedResources

Methods

string[]
getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

string
getSupportedTargetType()

Return the target type this TypeConverter converts to.

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.

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

mixed|null|Error
convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)

Converts the given string or array to a PersistentResource object.

handleFileUploads(array $source, PropertyMappingConfigurationInterface $configuration = null)

No description

handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = null)

No description

handleUploadedFile(UploadedFileInterface $source, PropertyMappingConfigurationInterface $configuration = null)

No description

string
getCollectionName(array|UploadedFileInterface $source, PropertyMappingConfigurationInterface $configuration = null)

Get the collection name this resource will be stored in. Default will be ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME The propertyMappingConfiguration CONFIGURATION_COLLECTION_NAME will directly override the default. Then if CONFIGURATION_ALLOW_COLLECTION_OVERRIDE is true and __collectionName is in the $source this will finally be the value.

Details

string[] getSupportedSourceTypes()

Returns the list of source types the TypeConverter can handle.

Must be PHP simple types, classes or object is not allowed.

Return Value

string[]

string getSupportedTargetType()

Return the target type this TypeConverter converts to.

Can be a simple type or a class name.

Return Value

string

string getTargetTypeForSource(mixed $source, string $originalTargetType, PropertyMappingConfigurationInterface $configuration = null)

Returns the $originalTargetType unchanged in this implementation.

Parameters

mixed $source

the source data

string $originalTargetType

the type we originally want to convert to

PropertyMappingConfigurationInterface $configuration

Return Value

string

int getPriority()

Return the priority of this TypeConverter. TypeConverters with a high priority are chosen before low priority.

Return Value

int

bool canConvertFrom(mixed $source, string $targetType)

This implementation always returns true for this method.

Parameters

mixed $source

the source data

string $targetType

the type to convert to.

Return Value

bool

true if this TypeConverter can convert from $source to $targetType, false otherwise.

array getSourceChildPropertiesToBeConverted(mixed $source)

Returns an empty list of sub property names

Parameters

mixed $source

Return Value

array

string|null getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration)

This method is never called, as getSourceChildPropertiesToBeConverted() returns an empty array.

Parameters

string $targetType
string $propertyName
PropertyMappingConfigurationInterface $configuration

Return Value

string|null

the type of $propertyName in $targetType

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

mixed|null|Error convertFrom(mixed $source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)

Converts the given string or array to a PersistentResource object.

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.

Parameters

mixed $source
string $targetType
array $convertedChildProperties
PropertyMappingConfigurationInterface $configuration

Return Value

mixed|null|Error

the target type, or an error object if a user-error occurred

Exceptions

Exception
InvalidResourceDataException
InvalidPropertyMappingConfigurationException

protected PersistentResource|null|Error handleFileUploads(array $source, PropertyMappingConfigurationInterface $configuration = null)

No description

Parameters

array $source
PropertyMappingConfigurationInterface $configuration

Return Value

PersistentResource|null|Error

protected PersistentResource|Error handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = null)

protected PersistentResource|null|Error handleUploadedFile(UploadedFileInterface $source, PropertyMappingConfigurationInterface $configuration = null)

No description

Parameters

UploadedFileInterface $source
PropertyMappingConfigurationInterface $configuration

Return Value

PersistentResource|null|Error

protected string getCollectionName(array|UploadedFileInterface $source, PropertyMappingConfigurationInterface $configuration = null)

Get the collection name this resource will be stored in. Default will be ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME The propertyMappingConfiguration CONFIGURATION_COLLECTION_NAME will directly override the default. Then if CONFIGURATION_ALLOW_COLLECTION_OVERRIDE is true and __collectionName is in the $source this will finally be the value.

Parameters

array|UploadedFileInterface $source
PropertyMappingConfigurationInterface $configuration

Return Value

string

Exceptions

InvalidPropertyMappingConfigurationException