The StorageRepository Class¶
The \TYPO3\CMS\Core\Resource\StorageRepository
is the
main class for creating and retrieving file storage objects.
It contains a number of utility methods, some of
which are described here, some others which appear in the
other code samples provided in this chapter.
Getting the Default Storage¶
Of all available storages, one may be marked as default. This is the storage that will be used for any operation whenever no storage has been explicitly chosen or defined (for example, when not using a combined identifier).
<?php
declare(strict_types=1);
use TYPO3\CMS\Core\Resource\StorageRepository;
class GetDefaultStorageExample
{
public function __construct(
private readonly StorageRepository $storageRepository
) {
}
public function doSomething(): void
{
$defaultStorage = $this->storageRepository->getDefaultStorage();
// .. more logic
}
}
Note
The method getDefaultStorage()
may return null
if no default
storage exists.
Getting any storage¶
The StorageRepository
class should be used when retrieving any storage.
<?php
declare(strict_types=1);
use TYPO3\CMS\Core\Resource\StorageRepository;
class GetStorageObjectExample
{
public function __construct(
private readonly StorageRepository $storageRepository
) {
}
public function doSomething(): void
{
$storage = $this->storageRepository->getStorageObject(3);
// .. more logic
}
}