StorageRepository
class \
Repository for accessing the file storages configured in config/system/file-storages.yaml
Attributes
- #[Autoconfigure]
- $public: true
Table of Contents
Properties
- $configuration : FileStorageConfiguration
- $configurationWriter : FileStorageConfigurationWriter
- $connectionPool : ConnectionPool
- $driverRegistry : DriverRegistry
- $eventDispatcher : EventDispatcherInterface
- $flexFormTools : FlexFormTools
- $localDriverStorageCache : array<int<0, max>, LocalPath>|null
- $logger : LoggerInterface
- $storageInstances : array<int<0, max>, ResourceStorage>
- $storageRowCache : array<positive-int, array<string, mixed>>|null
Methods
- __construct() : mixed
- addLocalStorage() : positive-int
- Adds a local storage to config/system/file-storages.yaml, e.g. for a directory next to fileadmin/. The base path is absolute or relative to the project path.
- createFromRecord() : ResourceStorage
- Creates a storage object from a storage definition that is not part of the configuration, e.g. for checks. The definition is normalized first.
- createLocalStorage() : positive-int
- findAll() : array<int, ResourceStorage>
- Returns a list of mountpoints that are available in the VFS.
- findBestMatchingStorageByLocalPath() : int<0, max>
- Checks whether a file resides within a real storage in local file system.
- findByCombinedIdentifier() : ResourceStorage|null
- Gets a storage object from a combined identifier
- findByStorageType() : array<int, ResourceStorage>
- Finds storages by type, i.e. the driver used
- findByUid() : ResourceStorage|null
- flush() : void
- Flush the internal storage caches to force reloading of storages with the next fetch.
- getDefaultStorage() : ResourceStorage|null
- Returns the Default Storage
- getDefaultStorageUid() : int|null
- Resolves the uid of the default storage without instantiating any storage object.
- getStorageObject() : ResourceStorage
- Creates an instance of the storage from given UID. The $recordData can be supplied to increase performance.
- onConfigurationChanged() : void
- createStorageObject() : ResourceStorage
- Creates a storage object from a normalized storage definition.
- fetchRecordDataByUid() : array
- getDriverObject() : DriverInterface
- Creates a driver object for a specified storage object.
- getNextIdentifier() : positive-int
- Identifiers are never handed out twice: files, processed files, file mounts and folder collections of a removed storage may still reference its identifier.
- initializeLocalCache() : void
- Reads the storage definitions from the configuration, sorted by name.
- initializeLocalStorageCache() : void
- Creates an array mapping all uids to the basePath of storages using the "local" driver.
- migrateLegacyRecordKeys() : array
- Listeners of BeforeResourceStorageInitializationEvent may still set the keys of the former sys_file_storage row. They are mapped to the normalized definition.
- toCompactEntry() : array<string, mixed>
Properties
$configuration read-only
protected
FileStorageConfiguration
$configuration
$configurationWriter read-only
protected
FileStorageConfigurationWriter
$configurationWriter
$connectionPool read-only
protected
ConnectionPool
$connectionPool
$driverRegistry read-only
protected
DriverRegistry
$driverRegistry
$eventDispatcher read-only
protected
EventDispatcherInterface
$eventDispatcher
$flexFormTools read-only
protected
FlexFormTools
$flexFormTools
$localDriverStorageCache
protected
array<int<0, max>, LocalPath>|null
$localDriverStorageCache
= null
$logger read-only
protected
LoggerInterface
$logger
$storageInstances
protected
array<int<0, max>, ResourceStorage>
$storageInstances
= []
$storageRowCache
protected
array<positive-int, array<string, mixed>>|null
$storageRowCache
= null
Methods
__construct()
public
__construct(EventDispatcherInterface $eventDispatcher, FileStorageConfiguration $configuration, FileStorageConfigurationWriter $configurationWriter, DriverRegistry $driverRegistry, LoggerInterface $logger, ConnectionPool $connectionPool, FlexFormTools $flexFormTools) : mixed
Parameters
- $eventDispatcher : EventDispatcherInterface
- $configuration : FileStorageConfiguration
- $configurationWriter : FileStorageConfigurationWriter
- $driverRegistry : DriverRegistry
- $logger : LoggerInterface
- $connectionPool : ConnectionPool
- $flexFormTools : FlexFormTools
addLocalStorage()
Adds a local storage to config/system/file-storages.yaml, e.g. for a directory next to fileadmin/. The base path is absolute or relative to the project path.
public
addLocalStorage(non-empty-string $name, non-empty-string $basePath[, bool $default = false ]) : positive-int
The file is part of the deployment: call this from command line tools or set up code, not during regular web requests.
Parameters
- $name : non-empty-string
- $basePath : non-empty-string
- $default : bool = false
Return values
positive-int —the identifier of the new storage
createFromRecord()
Creates a storage object from a storage definition that is not part of the configuration, e.g. for checks. The definition is normalized first.
public
createFromRecord(array<string, mixed> $storageRecord) : ResourceStorage
Parameters
- $storageRecord : array<string, mixed>
Internal
Return values
ResourceStoragecreateLocalStorage()
public
createLocalStorage(non-empty-string $name, non-empty-string $basePath, non-empty-string $pathType[, string $description = '' ][, bool $default = false ]) : positive-int
Deprecated
since TYPO3 v15, will be removed in TYPO3 v16. Use addLocalStorage() instead.
Parameters
- $name : non-empty-string
- $basePath : non-empty-string
- $pathType : non-empty-string
-
"relative" to the public path, or "absolute"
- $description : string = ''
- $default : bool = false
Return values
positive-int —the identifier of the new storage
findAll()
Returns a list of mountpoints that are available in the VFS.
public
findAll() : array<int, ResourceStorage>
Return values
array<int, ResourceStorage>findBestMatchingStorageByLocalPath()
Checks whether a file resides within a real storage in local file system.
public
findBestMatchingStorageByLocalPath(non-empty-string &$localPath) : int<0, max>
If no match is found, 0 is returned, meaning the path is not part of any storage.
The file identifier is adapted accordingly to match the new storage's base path.
Parameters
- $localPath : non-empty-string
Internal
Only to be used by the File Abstraction Layer to resolve paths without a storage prefix.
Tags
Return values
int<0, max>findByCombinedIdentifier()
Gets a storage object from a combined identifier
public
findByCombinedIdentifier(non-empty-string $identifier) : ResourceStorage|null
Parameters
- $identifier : non-empty-string
-
An identifier of the form [storage uid]:[object identifier]
Return values
ResourceStorage|nullfindByStorageType()
Finds storages by type, i.e. the driver used
public
findByStorageType(non-empty-string $storageType) : array<int, ResourceStorage>
Parameters
- $storageType : non-empty-string
Return values
array<int, ResourceStorage>findByUid()
public
findByUid(int $uid) : ResourceStorage|null
Parameters
- $uid : int
Return values
ResourceStorage|nullflush()
Flush the internal storage caches to force reloading of storages with the next fetch.
public
flush() : void
Internal
getDefaultStorage()
Returns the Default Storage
public
getDefaultStorage() : ResourceStorage|null
The Default Storage is considered to be the replacement for the fileadmin/ construct. Without a configuration file, it is the local storage of the fileadmin/ directory. getDefaultStorage->getDefaultFolder() will get you fileadmin/user_upload/ in a standard TYPO3 installation.
Return values
ResourceStorage|nullgetDefaultStorageUid()
Resolves the uid of the default storage without instantiating any storage object.
public
getDefaultStorageUid() : int|null
As with all other lookups of this repository, the default local storage is created if no storage record exists yet.
Internal
Needed while file mounts are resolved, as instantiating a storage applies them.
Return values
int|nullgetStorageObject()
Creates an instance of the storage from given UID. The $recordData can be supplied to increase performance.
public
getStorageObject(int|string $uid[, array<string, mixed> $recordData = [] ][, non-empty-string|null &$fileIdentifier = null ]) : ResourceStorage
Parameters
- $uid : int|string
-
The uid of the storage to instantiate, must be a positive integer.
- $recordData : array<string, mixed> = []
-
The normalized storage definition from the configuration.
- $fileIdentifier : non-empty-string|null = null
-
Identifier for a file, listeners of BeforeResourceStorageInitializationEvent may use it to determine the storage
Tags
Return values
ResourceStorageonConfigurationChanged()
public
onConfigurationChanged(FileStorageConfigurationChangedEvent $event) : void
Parameters
- $event : FileStorageConfigurationChangedEvent
Internal
Attributes
createStorageObject()
Creates a storage object from a normalized storage definition.
protected
createStorageObject(array<string, mixed> $storageRecord) : ResourceStorage
Parameters
- $storageRecord : array<string, mixed>
Return values
ResourceStoragefetchRecordDataByUid()
protected
fetchRecordDataByUid(int $uid) : array
Parameters
- $uid : int
Return values
arraygetDriverObject()
Creates a driver object for a specified storage object.
protected
getDriverObject(non-empty-string $driverIdentificationString, array $driverConfiguration) : DriverInterface
Parameters
- $driverIdentificationString : non-empty-string
-
The driver class (or identifier) to use.
- $driverConfiguration : array
-
The configuration of the storage
Return values
DriverInterfacegetNextIdentifier()
Identifiers are never handed out twice: files, processed files, file mounts and folder collections of a removed storage may still reference its identifier.
protected
getNextIdentifier() : positive-int
Return values
positive-intinitializeLocalCache()
Reads the storage definitions from the configuration, sorted by name.
protected
initializeLocalCache() : void
initializeLocalStorageCache()
Creates an array mapping all uids to the basePath of storages using the "local" driver.
protected
initializeLocalStorageCache() : void
migrateLegacyRecordKeys()
Listeners of BeforeResourceStorageInitializationEvent may still set the keys of the former sys_file_storage row. They are mapped to the normalized definition.
protected
migrateLegacyRecordKeys(array $recordData) : array
Deprecated
since TYPO3 v15, will be removed in TYPO3 v16 together with the mapping.
Parameters
- $recordData : array
Return values
arraytoCompactEntry()
protected
toCompactEntry(array<string, mixed> $storageRow) : array<string, mixed>
Parameters
- $storageRow : array<string, mixed>
-
normalized definition
Return values
array<string, mixed> —the definition without the identifier, as the writer expects it