ResourceTypeConverter
class ResourceTypeConverter extends AbstractTypeConverter (View source)
A type converter for converting strings, array and uploaded files to PersistentResource objects.
Has two major working modes:
-
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.
-
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
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.
Injects the (system) logger based on PSR-3.
Converts the given string or array to a PersistentResource object.
No description
No description
No description
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.
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.
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.
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.
protected PersistentResource|null|Error
handleFileUploads(array $source, PropertyMappingConfigurationInterface $configuration = null)
No description
protected PersistentResource|Error
handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = null)
No description
protected PersistentResource|null|Error
handleUploadedFile(UploadedFileInterface $source, PropertyMappingConfigurationInterface $configuration = null)
No description
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.