Commit 4ee479d6 authored by Benni Mack's avatar Benni Mack Committed by Oliver Hader
Browse files

[TASK] Replace ResourceFactory::getInstance() with makeInstance

The so-called "singleton factory instance" is a wrapper around makeInstance
which can be used directly anyways.

With Dependency Injection this is not even necessary anymore, and should
be avoided under all circumstances.

The constructor does not cache anything, so this can be replaced completely.

SingletonInterface + DI should be sufficient already.

Resolves: #90260
Releases: master
Change-Id: I964ddb90425b273c6e7588781c4b7e3fe39ddd18
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63076


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
parent f02f4e22
......@@ -42,7 +42,7 @@ class DefaultAvatarProvider implements AvatarProviderInterface
}
// Get file object
try {
$file = ResourceFactory::getInstance()->getFileObject($fileUid);
$file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
$processedImage = $file->process(
ProcessedFile::CONTEXT_IMAGECROPSCALEMASK,
['width' => $size . 'c', 'height' => $size . 'c']
......
......@@ -233,7 +233,7 @@ class ShortcutRepository
// Check if given id is a combined identifier
if (!empty($queryParameters['id']) && preg_match('/^[\d]+:/', $queryParameters['id'])) {
try {
$resourceFactory = ResourceFactory::getInstance();
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$resource = $resourceFactory->getObjectFromCombinedIdentifier($queryParameters['id']);
$title = trim(sprintf(
'%s (%s)',
......
......@@ -380,7 +380,7 @@ class Clipboard
[$table, $uid] = explode('|', $k);
// Rendering files/directories on the clipboard
if ($table === '_FILE') {
$fileObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
$fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($v);
if ($fileObject) {
$thumb = [];
$folder = $fileObject instanceof \TYPO3\CMS\Core\Resource\Folder;
......@@ -764,7 +764,7 @@ class Clipboard
[$table, $uid] = explode('|', $k);
// Rendering files/directories on the clipboard
if ($table === '_FILE') {
$file = ResourceFactory::getInstance()->getObjectFromCombinedIdentifier($v);
$file = GeneralUtility::makeInstance(ResourceFactory::class)->getObjectFromCombinedIdentifier($v);
if ($file instanceof AbstractFile) {
$params['tx_impexp']['record'][] = 'sys_file:' . $file->getUid();
}
......@@ -838,7 +838,7 @@ class Clipboard
$this->changed = 1;
} else {
try {
ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($v);
} catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) {
// The file has been deleted in the meantime, so just remove it silently
unset($this->clipData[$this->current]['el'][$k]);
......
......@@ -189,7 +189,7 @@ class ElementInformationController
*/
protected function initFileOrFolderRecord()
{
$fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->uid);
$fileOrFolderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($this->uid);
if ($fileOrFolderObject instanceof Folder) {
$this->folderObject = $fileOrFolderObject;
......
......@@ -86,7 +86,7 @@ class ThumbnailController
*/
protected function generateThumbnail($fileId, array $configuration): ResponseInterface
{
$file = ResourceFactory::getInstance()->getFileObject($fileId);
$file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileId);
if ($file === null || $file->isMissing()) {
return $this->generateNotFoundResponse();
}
......
......@@ -120,7 +120,7 @@ class OnlineMediaController
$targetFolder = null;
if ($targetFolderIdentifier) {
try {
$targetFolder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($targetFolderIdentifier);
$targetFolder = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($targetFolderIdentifier);
} catch (\Exception $e) {
$targetFolder = null;
}
......
......@@ -63,7 +63,7 @@ class ImageManipulationController
$image = null;
if (MathUtility::canBeInterpretedAsInteger($fileUid)) {
try {
$image = ResourceFactory::getInstance()->getFileObject($fileUid);
$image = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
} catch (FileDoesNotExistException $e) {
}
}
......
......@@ -351,7 +351,7 @@ class InlineRecordContainer extends AbstractContainer
if (!empty($fileUid)) {
try {
$fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
$fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
} catch (\InvalidArgumentException $e) {
$fileObject = null;
}
......
......@@ -48,7 +48,7 @@ class FileInfoElement extends AbstractFormElement
$fileObject = null;
if ($fileUid > 0) {
$fileObject = ResourceFactory::getInstance()->getFileObject($fileUid);
$fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
}
$resultArray['html'] = $this->renderFileInformationContent($fileObject);
return $resultArray;
......
......@@ -224,7 +224,7 @@ class ImageManipulationElement extends AbstractFormElement
}
if (MathUtility::canBeInterpretedAsInteger($fileUid)) {
try {
$file = ResourceFactory::getInstance()->getFileObject($fileUid);
$file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
} catch (FileDoesNotExistException|\InvalidArgumentException $e) {
}
}
......
......@@ -59,7 +59,7 @@ class UserSysFileStorageIsPublicElement extends AbstractFormElement
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
try {
$storage = ResourceFactory::getInstance()->getStorageObject((int)$row['uid']);
$storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject((int)$row['uid']);
$storageRecord = $storage->getStorageRecord();
$isPublic = $storage->isPublic() && $storageRecord['is_public'];
......
......@@ -134,7 +134,7 @@ class TcaGroup implements FormDataProviderInterface
continue;
}
try {
$folderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($folder);
$folderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($folder);
if ($folderObject instanceof Folder) {
$items[] = [
'folder' => $folder,
......
......@@ -66,7 +66,7 @@ class MetaInformation
}
} elseif (!empty($pageRecord['combined_identifier'])) {
try {
$resourceObject = ResourceFactory::getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
$resourceObject = GeneralUtility::makeInstance(ResourceFactory::class)->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
$title = $resourceObject->getStorage()->getName() . ':';
$title .= $resourceObject->getParentFolder()->getReadablePath();
} catch (ResourceDoesNotExistException|InsufficientFolderAccessPermissionsException $e) {
......@@ -194,7 +194,7 @@ class MetaInformation
} elseif (is_array($pageRecord) && !empty($pageRecord['combined_identifier'])) {
// If the module is about a FAL resource
try {
$resourceObject = ResourceFactory::getInstance()->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
$resourceObject = GeneralUtility::makeInstance(ResourceFactory::class)->getObjectFromCombinedIdentifier($pageRecord['combined_identifier']);
$fileMountTitle = $resourceObject->getStorage()->getFileMounts()[$resourceObject->getIdentifier()]['title'] ?? '';
$title = $fileMountTitle ?: $resourceObject->getName();
// If this is a folder but not in within file mount boundaries this is the root folder
......
......@@ -1068,7 +1068,7 @@ class BackendUtility
foreach ($referenceUids as $referenceUid) {
try {
$fileReference = ResourceFactory::getInstance()->getFileReferenceObject(
$fileReference = GeneralUtility::makeInstance(ResourceFactory::class)->getFileReferenceObject(
$referenceUid,
[],
$workspaceId === 0
......
......@@ -27,6 +27,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction;
use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\SysLog\Action as SystemLogGenericAction;
use TYPO3\CMS\Core\SysLog\Action\Login as SystemLogLoginAction;
......@@ -1943,7 +1944,7 @@ TCAdefaults.sys_note.email = ' . $this->user['email'];
{
$uploadFolder = $this->getTSConfig()['options.']['defaultUploadFolder'] ?? '';
if ($uploadFolder) {
$uploadFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($uploadFolder);
$uploadFolder = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($uploadFolder);
} else {
foreach ($this->getFileStorages() as $storage) {
if ($storage->isDefault() && $storage->isWritable()) {
......
......@@ -159,7 +159,7 @@ class SlotReplacement
[, $uid, $recordData, $fileIdentifier] = $this->signalSlotDispatcher->dispatch(
ResourceFactory::class,
'preProcessStorage',
[ResourceFactory::getInstance(), $event->getStorageUid(), $event->getRecord(), $event->getFileIdentifier()]
[GeneralUtility::makeInstance(ResourceFactory::class), $event->getStorageUid(), $event->getRecord(), $event->getFileIdentifier()]
);
$event->setStorageUid($uid);
$event->setRecord($recordData);
......@@ -171,7 +171,7 @@ class SlotReplacement
$this->signalSlotDispatcher->dispatch(
ResourceFactory::class,
'postProcessStorage',
[ResourceFactory::getInstance(), $event->getStorage()]
[GeneralUtility::makeInstance(ResourceFactory::class), $event->getStorage()]
);
}
......
......@@ -59,7 +59,7 @@ class FileDumpController
if (hash_equals(GeneralUtility::hmac(implode('|', $parameters), 'resourceStorageDumpFile'), $this->getGetOrPost($request, 'token'))) {
if (isset($parameters['f'])) {
try {
$file = ResourceFactory::getInstance()->getFileObject($parameters['f']);
$file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($parameters['f']);
if ($file->isDeleted() || $file->isMissing()) {
$file = null;
}
......
......@@ -8721,7 +8721,7 @@ class DataHandler implements LoggerAwareInterface
*/
protected function getResourceFactory()
{
return ResourceFactory::getInstance();
return GeneralUtility::makeInstance(ResourceFactory::class);
}
/**
......
......@@ -82,7 +82,7 @@ class CategoryBasedFileCollection extends AbstractFileCollection
)
)
->execute();
$resourceFactory = ResourceFactory::getInstance();
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
while ($record = $statement->fetch()) {
$this->add($resourceFactory->getFileObject((int)$record['file']));
}
......
......@@ -204,7 +204,7 @@ class File extends AbstractFile
$this->getType();
}
if (array_key_exists('storage', $properties) && in_array('storage', $this->updatedProperties)) {
$this->storage = ResourceFactory::getInstance()->getStorageObject($properties['storage']);
$this->storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($properties['storage']);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment