ResourceFactory

readonly class \TYPO3\CMS\Core\Resource\ResourceFactory

Factory class for FAL objects

Attributes

#[Autoconfigure]
$public: true

Table of Contents

Properties

$runtimeCache  : FrontendInterface
$storageRepository  : StorageRepository

Methods

__construct()  : mixed
createCollectionObject()  : CollectionInterface<string|int, File>
Creates a collection object.
createFileObject()  : File
Creates a file object from an array of file data. Requires a database row to be fetched.
createFileReferenceObject()  : FileReference
Creates a file usage object from an array of fileReference data from sys_file_reference table.
getCollectionObject()  : CollectionInterface
Creates an instance of the collection from given UID. The $recordData can be supplied to increase performance.
getFileObject()  : File
Creates an instance of the file given UID. The $fileData can be supplied to increase performance.
getFileObjectFromCombinedIdentifier()  : File|ProcessedFile|null
Gets a file object from an identifier [storage]:[fileId]
getFileReferenceObject()  : FileReference
Creates an instance of a FileReference object. The $fileReferenceData can be supplied to increase performance.
getFolderObjectFromCombinedIdentifier()  : Folder
Gets a folder object from an identifier [storage]:[fileId]
getObjectFromCombinedIdentifier()  : FileInterface|Folder
Gets a file or folder object.
resolveFileObject()  : FileInterface|ProcessableFileInterface
Resolves a loosely typed file source - as it is typically supplied by a template or by user input - to a File or FileReference.
retrieveFileOrFolderObject()  : ProcessedFile|File|Folder|null
Bulk function, can be used for anything to get a file or folder
collectionCacheGet()  : CollectionInterface<string|int, File>|null
collectionCacheIdentifier()  : string
collectionCacheSet()  : void
fileCacheGet()  : File|null
fileCacheIdentifier()  : string
fileCacheSet()  : void
fileReferenceCacheGet()  : FileReference|null
fileReferenceCacheIdentifier()  : string
fileReferenceCacheSet()  : void
getFileReferenceData()  : array|false|null
Gets data for the given uid of the file reference record.

Properties

Methods

createCollectionObject()

Creates a collection object.

public createCollectionObject(array $collectionData) : CollectionInterface<string|int, File>

Parameters

$collectionData : array

The database row of the sys_file_collection record.

Return values

CollectionInterface<string|int, File>

createFileObject()

Creates a file object from an array of file data. Requires a database row to be fetched.

public createFileObject(array $fileData[, ResourceStorage|null $storage = null ]) : File

Parameters

$fileData : array
$storage : ResourceStorage|null = null

Tags

throws
FileDoesNotExistException

if the storage of the file is not configured

Return values

File

createFileReferenceObject()

Creates a file usage object from an array of fileReference data from sys_file_reference table.

public createFileReferenceObject(array $fileReferenceData) : FileReference

Requires a database row to be already fetched and present.

Parameters

$fileReferenceData : array

Return values

FileReference

getCollectionObject()

Creates an instance of the collection from given UID. The $recordData can be supplied to increase performance.

public getCollectionObject(int $uid[, array $recordData = [] ]) : CollectionInterface

Parameters

$uid : int

The uid of the collection to instantiate.

$recordData : array = []

The record row from database.

Tags

throws
InvalidArgumentException

Return values

CollectionInterface

getFileObject()

Creates an instance of the file given UID. The $fileData can be supplied to increase performance.

public getFileObject(int|string $uid[, array $fileData = [] ]) : File

Parameters

$uid : int|string

The uid of the file to instantiate. (string is used for the time being as compat-mode)

$fileData : array = []

The record row from database.

Return values

File

getFileObjectFromCombinedIdentifier()

Gets a file object from an identifier [storage]:[fileId]

public getFileObjectFromCombinedIdentifier(string $identifier) : File|ProcessedFile|null

Parameters

$identifier : string

Tags

throws
InvalidArgumentException
throws
FileDoesNotExistException

if the file is not part of any file storage

Return values

File|ProcessedFile|null

getFileReferenceObject()

Creates an instance of a FileReference object. The $fileReferenceData can be supplied to increase performance.

public getFileReferenceObject(int|string $uid[, array $fileReferenceData = [] ][, bool $raw = false ]) : FileReference

Parameters

$uid : int|string

The uid of the file usage (sys_file_reference) to instantiate. string is kept for backwards-compat

$fileReferenceData : array = []

The record row from database.

$raw : bool = false

Whether to get raw results without performing overlays

Tags

throws
ResourceDoesNotExistException

Return values

FileReference

getFolderObjectFromCombinedIdentifier()

Gets a folder object from an identifier [storage]:[fileId]

public getFolderObjectFromCombinedIdentifier(string|int $identifier) : Folder

Parameters

$identifier : string|int

Return values

Folder

resolveFileObject()

Resolves a loosely typed file source - as it is typically supplied by a template or by user input - to a File or FileReference.

public resolveFileObject(string|int|object|null $source[, bool $treatIdAsReference = false ]) : FileInterface|ProcessableFileInterface

In contrast to retrieveFileOrFolderObject() this never returns a folder, and it throws instead of returning null if the source cannot be resolved.

$source may be

  • a File or FileReference, which is passed through unchanged
  • a domain object exposing the resource via getOriginalResource(), e.g. an Extbase FileReference
  • a sys_file UID, or a sys_file_reference UID if $treatIdAsReference is set
  • a combined identifier, an "EXT:" path or a legacy storage-0 path
  • a "t3://file" URN

Parameters

$source : string|int|object|null
$treatIdAsReference : bool = false

Tags

throws
UnexpectedValueException

if the source cannot be resolved to a File or FileReference

Return values

FileInterface|ProcessableFileInterface

retrieveFileOrFolderObject()

Bulk function, can be used for anything to get a file or folder

public retrieveFileOrFolderObject(string|int $input) : ProcessedFile|File|Folder|null
  1. It's a UID
  2. It's a combined identifier
  3. It's just a path/filename within a configured file storage

$input could be

  • "2:myfolder/myfile.jpg" (combined identifier)
  • "23" (file UID)
  • "fileadmin/myfile.png" (a path resolved to its storage)
  • "file:23"

Parameters

$input : string|int

Return values

ProcessedFile|File|Folder|null

collectionCacheIdentifier()

protected collectionCacheIdentifier(int $uid) : string

Parameters

$uid : int

Return values

string

fileCacheGet()

protected fileCacheGet(int $uid) : File|null

Parameters

$uid : int

Return values

File|null

fileCacheIdentifier()

protected fileCacheIdentifier(int $uid) : string

Parameters

$uid : int

Return values

string

fileReferenceCacheIdentifier()

protected fileReferenceCacheIdentifier(int $uid) : string

Parameters

$uid : int

Return values

string

getFileReferenceData()

Gets data for the given uid of the file reference record.

protected getFileReferenceData(int $uid[, bool $raw = false ]) : array|false|null

Parameters

$uid : int

The uid of the file usage (sys_file_reference) to be fetched

$raw : bool = false

Whether to get raw results without performing overlays

Return values

array|false|null
On this page