class FileImporter (View source)

A class to be used to import files into the application file manager.

Properties

protected Application $app

The container instance to be used to build dependencies.

private ProcessorManager $processorManager
private Application $applicationFileService
private Incoming $incoming

Methods

__construct(Application $app, ProcessorManager $processorManager, Application $applicationFileService, Incoming $incoming)

Initialize the instance.

getProcessorManager()

Get the processor list manager.

importLocalFile(string $localFilename, string $concreteFilename = '', ImportOptions $options = null)

Import a local file into the application file manager.

importFromIncoming(string $incomingFilename, string $concreteFilename = '', ImportOptions $options = null)

Import a file from the incoming directory into the application file manager.

importUploadedFile(UploadedFile $uploadedFile = null, string $concreteFilename = '', ImportOptions $options = null)

Import a file received via a POST request into the application file manager.

string
generatePrefix()

Generate a file prefix.

import(ImportingFile $importingFile, ImportOptions $options)

Import a file into the application file manager.

applyValidators(ImportingFile $importingFile, ImportOptions $options)

Apply the validators to the file being imported.

applyPreProcessors(ImportingFile $importingFile, ImportOptions $options)

Apply the pre-processors to the file being imported.

save(ImportingFile $importingFile, ImportOptions $options)

Actually import a file into the application file manager.

applyPostProcessors(ImportingFile $importingFile, ImportOptions $options, Version $fileVersion)

Apply the post-processors to the imported file.

string
resolveIncomingFilename(string $incomingFilename, bool $copiedLocally, VolatileDirectory $volatileDirectory = null)

Get the local path of an incoming file (if the incoming file system is not local, we'll create a copy of it in a volatile directory).

Details

__construct(Application $app, ProcessorManager $processorManager, Application $applicationFileService, Incoming $incoming)

Initialize the instance.

Parameters

Application $app
ProcessorManager $processorManager
Application $applicationFileService
Incoming $incoming

ProcessorManager getProcessorManager()

Get the processor list manager.

Return Value

ProcessorManager

Version importLocalFile(string $localFilename, string $concreteFilename = '', ImportOptions $options = null)

Import a local file into the application file manager.

Parameters

string $localFilename

The path to the file

string $concreteFilename

A custom name to give to the file (if empty we'll derive it from $localFilename)

ImportOptions $options

the options to be used to import the file

Return Value

Version

Exceptions

ImportException

Version importFromIncoming(string $incomingFilename, string $concreteFilename = '', ImportOptions $options = null)

Import a file from the incoming directory into the application file manager.

Parameters

string $incomingFilename

The path to the file

string $concreteFilename

A custom name to give to the file (if empty we'll derive it from $incomingFilename)

ImportOptions $options

the options to be used to import the file

Return Value

Version

Exceptions

ImportException

Version importUploadedFile(UploadedFile $uploadedFile = null, string $concreteFilename = '', ImportOptions $options = null)

Import a file received via a POST request into the application file manager.

Parameters

UploadedFile $uploadedFile

The uploaded file

string $concreteFilename

A custom name to give to the file (if empty we'll derive it from $uploadedFile)

ImportOptions $options

the options to be used to import the file

Return Value

Version

Exceptions

ImportException

Examples

<pre><code>
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$request = $app->make(\Concrete\Core\Http\Request::class);
$importer = $app->make(\Concrete\Core\File\Import\FileImporter::class);
try {
    $fv = $importer->importUploadedFile($request->files->get('field_name'));
} catch (\Concrete\Core\File\Import\ImportException $x) {
    // Manage the import exception
}
</code></pre>

string generatePrefix()

Generate a file prefix.

Return Value

string

protected Version import(ImportingFile $importingFile, ImportOptions $options)

Import a file into the application file manager.

Parameters

ImportingFile $importingFile

the file being imported

ImportOptions $options

the options to be used to import the file

Return Value

Version

Exceptions

ImportException

protected applyValidators(ImportingFile $importingFile, ImportOptions $options)

Apply the validators to the file being imported.

Parameters

ImportingFile $importingFile
ImportOptions $options

Exceptions

ImportException

protected applyPreProcessors(ImportingFile $importingFile, ImportOptions $options)

Apply the pre-processors to the file being imported.

Parameters

ImportingFile $importingFile
ImportOptions $options

protected Version save(ImportingFile $importingFile, ImportOptions $options)

Actually import a file into the application file manager.

Parameters

ImportingFile $importingFile

the file being imported

ImportOptions $options

the options to be used to import the file

Return Value

Version

Exceptions

ImportException

protected applyPostProcessors(ImportingFile $importingFile, ImportOptions $options, Version $fileVersion)

Apply the post-processors to the imported file.

Parameters

ImportingFile $importingFile
ImportOptions $options
Version $fileVersion

Exceptions

ImportException

protected string resolveIncomingFilename(string $incomingFilename, bool $copiedLocally, VolatileDirectory $volatileDirectory = null)

Get the local path of an incoming file (if the incoming file system is not local, we'll create a copy of it in a volatile directory).

Parameters

string $incomingFilename

The file name in the incoming file system

bool $copiedLocally

this output parameter will be set to true if we had to copy the file locally

VolatileDirectory $volatileDirectory

this output parameter will be set to a VolatileDirectory instance if we had to copy the file locally

Return Value

string

Exceptions

ImportException