CRUDlex\FileHandler¶
-
class
FileHandler
¶ Handles the files.
-
property
filesystem
¶ protected FilesystemInterface
Brings the abstract access to the filesystem.
-
property
entityDefinition
¶ protected EntityDefinition
Holds the entity definition.
-
getPath
($entityName, Entity $entity, $field)¶ Constructs a file system path for the given parameters for storing the file of the file field.
Parameters: - $entityName (string) – the entity name
- $entity (Entity) – the entity
- $field (string) – the file field in the entity
Returns: string the constructed path for storing the file of the file field
-
performOnFiles
(Entity $entity, $entityName, $function)¶ Executes a function for each file field of this entity.
Parameters: - $entity (Entity) – the just created entity
- $entityName (string) – the name of the entity as this class here is not aware of it
- $function (Closure) – the function to perform, takes $entity, $entityName and $field as parameter
-
shouldWriteFile
(AbstractData $data, Request $request, Entity $entity, $entityName, $action)¶ Writes the uploaded files.
Parameters: - $data (AbstractData) – the AbstractData instance who should receive the events
- $request (Request) – the HTTP request containing the file data
- $entity (Entity) – the just manipulated entity
- $entityName (string) – the name of the entity as this class here is not aware of it
- $action (string) – the name of the performed action
Returns: boolean true if all before events passed
-
__construct
(FilesystemInterface $filesystem, EntityDefinition $entityDefinition)¶ FileHandler constructor.
Parameters: - $filesystem (FilesystemInterface) – the filesystem to use
- $entityDefinition (EntityDefinition) – the entity definition to use
-
renderFile
(Entity $entity, $entityName, $field)¶ Renders (outputs) a file of an entity. This includes setting headers like the file size, mimetype and name, too.
Parameters: - $entity (Entity) – the entity to render the file from
- $entityName (string) – the name of the entity as this class here is not aware of it
- $field (string) – the field of the entity containing the file to be rendered
Returns: StreamedResponse the HTTP streamed response
-
deleteFiles
(AbstractData $data, Entity $entity, $entityName)¶ Deletes all files of an existing entity.
Parameters: - $data (AbstractData) – the AbstractData instance who should receive the events
- $entity (Entity) – the entity to delete the files from
- $entityName (string) – the name of the entity as this class here is not aware of it
Returns: boolean true on successful deletion
-
deleteFile
(AbstractData $data, Entity $entity, $entityName, $field)¶ Deletes a specific file from an existing entity.
Parameters: - $data (AbstractData) – the AbstractData instance who should receive the events
- $entity (Entity) – the entity to delete the file from
- $entityName (string) – the name of the entity as this class here is not aware of it
- $field (string) – the field of the entity containing the file to be deleted
Returns: bool true on successful deletion true on successful deletion
-
createFiles
(AbstractData $data, Request $request, Entity $entity, $entityName)¶ Creates the uploaded files of a newly created entity.
Parameters: - $data (AbstractData) – the AbstractData instance who should receive the events
- $request (Request) – the HTTP request containing the file data
- $entity (Entity) – the just created entity
- $entityName (string) – the name of the entity as this class here is not aware of it
Returns: boolean true if all before events passed
-
updateFiles
(AbstractData $data, Request $request, Entity $entity, $entityName)¶ Updates the uploaded files of an updated entity.
Parameters: - $data (AbstractData) – the AbstractData instance who should receive the events
- $request (Request) – the HTTP request containing the file data
- $entity (Entity) – the updated entity
- $entityName (string) – the name of the entity as this class here is not aware of it
Returns: boolean true on successful update
-
property