Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
The StorageRepository class
The \TYPO3\
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);
namespace MyVendor\MyExtension\Classes\Resource;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Resource\StorageRepository;
final class GetDefaultStorageExample
{
private StorageRepository $storageRepository;
public function __construct(StorageRepository $storageRepository)
{
$this->storageRepository = $storageRepository;
}
public function doSomething(): void
{
$defaultStorage = $this->storageRepository->getDefaultStorage();
// getDefaultStorage() may return null, if no default storage is configured.
// Therefore, we check if we receive a ResourceStorage object
if ($defaultStorage instanceof ResourceStorage) {
// ... do something with the default storage
}
// ... more logic
}
}
Getting any storage
The Storage
class should be used for retrieving any storage.
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Classes\Resource;
use TYPO3\CMS\Core\Resource\StorageRepository;
final class GetStorageObjectExample
{
private StorageRepository $storageRepository;
public function __construct(StorageRepository $storageRepository) {
$this->storageRepository = $storageRepository;
}
public function doSomething(): void
{
$storage = $this->storageRepository->getStorageObject(3);
// ... more logic
}
}