[TASK] Replace ResourceFactory::getInstance() with makeInstance 76/63076/3
authorBenni Mack <benni@typo3.org>
Thu, 30 Jan 2020 15:20:21 +0000 (16:20 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 30 Jan 2020 20:42:59 +0000 (21:42 +0100)
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: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
62 files changed:
typo3/sysext/backend/Classes/Backend/Avatar/DefaultAvatarProvider.php
typo3/sysext/backend/Classes/Backend/Shortcut/ShortcutRepository.php
typo3/sysext/backend/Classes/Clipboard/Clipboard.php
typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
typo3/sysext/backend/Classes/Controller/File/ThumbnailController.php
typo3/sysext/backend/Classes/Controller/OnlineMediaController.php
typo3/sysext/backend/Classes/Controller/Wizard/ImageManipulationController.php
typo3/sysext/backend/Classes/Form/Container/InlineRecordContainer.php
typo3/sysext/backend/Classes/Form/Element/FileInfoElement.php
typo3/sysext/backend/Classes/Form/Element/ImageManipulationElement.php
typo3/sysext/backend/Classes/Form/Element/UserSysFileStorageIsPublicElement.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaGroup.php
typo3/sysext/backend/Classes/Template/Components/MetaInformation.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php
typo3/sysext/core/Classes/Compatibility/SlotReplacement.php
typo3/sysext/core/Classes/Controller/FileDumpController.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Resource/Collection/CategoryBasedFileCollection.php
typo3/sysext/core/Classes/Resource/File.php
typo3/sysext/core/Classes/Resource/FileReference.php
typo3/sysext/core/Classes/Resource/Filter/FileExtensionFilter.php
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php
typo3/sysext/core/Classes/Resource/Index/Indexer.php
typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/AbstractOnlineMediaHelper.php
typo3/sysext/core/Classes/Resource/ProcessedFile.php
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Classes/Resource/Search/QueryRestrictions/FolderMountsRestriction.php
typo3/sysext/core/Classes/Resource/Search/Result/FileSearchResult.php
typo3/sysext/core/Classes/Resource/Security/FileMetadataPermissionsAspect.php
typo3/sysext/core/Classes/ServiceProvider.php
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-90260-ResourceFactorygetInstancePseudo-factory.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Functional/Resource/ResourceStorageTest.php
typo3/sysext/extbase/Classes/Domain/Model/File.php
typo3/sysext/extbase/Classes/Domain/Model/FileReference.php
typo3/sysext/extbase/Classes/Service/ImageService.php
typo3/sysext/filelist/Classes/ContextMenu/ItemProviders/FileProvider.php
typo3/sysext/filelist/Classes/Controller/File/CreateFolderController.php
typo3/sysext/filelist/Classes/Controller/File/EditFileController.php
typo3/sysext/filelist/Classes/Controller/File/FileUploadController.php
typo3/sysext/filelist/Classes/Controller/File/RenameFileController.php
typo3/sysext/filelist/Classes/Controller/File/ReplaceFileController.php
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/form/Tests/Functional/Hooks/FormFileExtensionUpdateTest.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Controller/ShowImageController.php
typo3/sysext/impexp/Classes/Controller/ImportController.php
typo3/sysext/impexp/Classes/Export.php
typo3/sysext/impexp/Classes/Import.php
typo3/sysext/impexp/Classes/ImportExport.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
typo3/sysext/recordlist/Classes/Browser/FolderBrowser.php
typo3/sysext/recordlist/Classes/LinkHandler/FileLinkHandler.php
typo3/sysext/scheduler/Classes/Task/FileStorageExtractionAdditionalFieldProvider.php
typo3/sysext/scheduler/Classes/Task/FileStorageExtractionTask.php
typo3/sysext/scheduler/Classes/Task/FileStorageIndexingAdditionalFieldProvider.php
typo3/sysext/scheduler/Classes/Task/FileStorageIndexingTask.php
typo3/sysext/setup/Classes/Controller/SetupModuleController.php
typo3/sysext/t3editor/Classes/Hook/FileEditHook.php

index 894b022..1828f57 100644 (file)
@@ -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']
index 8a3b446..3cee65f 100644 (file)
@@ -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)',
index 48485a8..684fd24 100644 (file)
@@ -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]);
index 7c36629..c58bf6d 100644 (file)
@@ -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;
index 7a9cbd2..4a88f7d 100644 (file)
@@ -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();
         }
index 24fee4b..d5ca0f6 100644 (file)
@@ -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;
             }
index 2fd647e..cabea95 100644 (file)
@@ -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) {
                 }
             }
index c78744c..1421799 100644 (file)
@@ -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;
                 }
index 0113ce4..4fe2156 100644 (file)
@@ -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;
index d11ea6b..9f65900 100644 (file)
@@ -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) {
             }
         }
index 3c74fe8..d6efa6f 100644 (file)
@@ -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'];
 
index 02990b6..94c4c4f 100644 (file)
@@ -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,
index ce73729..7ac685c 100644 (file)
@@ -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
index 4bebbbe..d4a6d4e 100644 (file)
@@ -1068,7 +1068,7 @@ class BackendUtility
 
         foreach ($referenceUids as $referenceUid) {
             try {
-                $fileReference = ResourceFactory::getInstance()->getFileReferenceObject(
+                $fileReference = GeneralUtility::makeInstance(ResourceFactory::class)->getFileReferenceObject(
                     $referenceUid,
                     [],
                     $workspaceId === 0
index 19e720e..7205a1d 100644 (file)
@@ -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()) {
index c418d79..d2f22b9 100644 (file)
@@ -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()]
         );
     }
 
index 9a470a1..1ec78dc 100644 (file)
@@ -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;
                     }
index 2e1429a..f6c7178 100644 (file)
@@ -8721,7 +8721,7 @@ class DataHandler implements LoggerAwareInterface
      */
     protected function getResourceFactory()
     {
-        return ResourceFactory::getInstance();
+        return GeneralUtility::makeInstance(ResourceFactory::class);
     }
 
     /**
index 84df0b4..e12cbce 100644 (file)
@@ -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']));
         }
index eaa31dd..47a72bf 100644 (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']);
         }
     }
 
index fd03bfa..ae97045 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Resource;
  * The TYPO3 project - inspiring people to share!
  */
 use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Representation of a specific usage of a file with possibilities to override certain
@@ -86,8 +87,7 @@ class FileReference implements FileInterface
             throw new \InvalidArgumentException('Incorrect reference to original file given for FileReference.', 1300098528);
         }
         if (!$factory) {
-            /** @var ResourceFactory $factory */
-            $factory = ResourceFactory::getInstance();
+            $factory = GeneralUtility::makeInstance(ResourceFactory::class);
         }
         $this->originalFile = $factory->getFileObject($fileReferenceData['uid_local']);
         if (!is_object($this->originalFile)) {
index f12119a..d243b7b 100644 (file)
@@ -64,7 +64,7 @@ class FileExtensionFilter
                 $parts = GeneralUtility::revExplode('_', $value, 2);
                 $fileReferenceUid = $parts[count($parts) - 1];
                 try {
-                    $fileReference = ResourceFactory::getInstance()->getFileReferenceObject($fileReferenceUid);
+                    $fileReference = GeneralUtility::makeInstance(ResourceFactory::class)->getFileReferenceObject($fileReferenceUid);
                     $file = $fileReference->getOriginalFile();
                     if ($this->isAllowed($file->getExtension())) {
                         $cleanValues[] = $value;
index 93f182c..ba4dba0 100644 (file)
@@ -69,7 +69,7 @@ class FileIndexRepository implements SingletonInterface
      */
     protected function getResourceFactory()
     {
-        return ResourceFactory::getInstance();
+        return GeneralUtility::makeInstance(ResourceFactory::class);
     }
 
     /**
index 4e69422..9b66454 100644 (file)
@@ -412,7 +412,7 @@ class Indexer implements LoggerAwareInterface
      */
     protected function getResourceFactory()
     {
-        return ResourceFactory::getInstance();
+        return GeneralUtility::makeInstance(ResourceFactory::class);
     }
 
     /**
index ac3da0c..7d3e945 100644 (file)
@@ -146,6 +146,6 @@ abstract class AbstractOnlineMediaHelper implements OnlineMediaHelperInterface
      */
     protected function getResourceFactory()
     {
-        return ResourceFactory::getInstance();
+        return GeneralUtility::makeInstance(ResourceFactory::class);
     }
 }
index 7e4caa6..4a0b81e 100644 (file)
@@ -141,7 +141,7 @@ class ProcessedFile extends AbstractFile
         $this->properties = $databaseRow;
 
         if (!empty($databaseRow['storage']) && (int)$this->storage->getUid() !== (int)$databaseRow['storage']) {
-            $this->storage = ResourceFactory::getInstance()->getStorageObject($databaseRow['storage']);
+            $this->storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($databaseRow['storage']);
         }
     }
 
index 6f24d7a..5ae3564 100644 (file)
@@ -23,23 +23,25 @@ use TYPO3\CMS\Core\Resource\Event\AfterResourceStorageInitializationEvent;
 use TYPO3\CMS\Core\Resource\Event\BeforeResourceStorageInitializationEvent;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
 use TYPO3\CMS\Core\Service\FlexFormService;
+use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Factory class for FAL objects
- * @todo implement constructor-level caching
  */
-class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\SingletonInterface
+class ResourceFactory implements ResourceFactoryInterface, SingletonInterface
 {
     /**
      * Gets a singleton instance of this class.
      *
      * @return ResourceFactory
+     * @deprecated use regular DI or - if not possible - GeneralUtility::makeInstance instead, as this Factory does not serve any purpose
      */
     public static function getInstance()
     {
+        trigger_error('ResourceFactory::getInstance() will be removed in TYPO3 v11.0. Use constructor-level Dependency Injection or GeneralUtility::makeInstance(ResourceFactory::class) instead.', E_USER_DEPRECATED);
         return GeneralUtility::makeInstance(__CLASS__);
     }
 
index a6fadb3..3d8c85d 100644 (file)
@@ -2874,7 +2874,7 @@ class ResourceStorage implements ResourceStorageInterface
      */
     public function getResourceFactoryInstance(): ResourceFactory
     {
-        return ResourceFactory::getInstance();
+        return GeneralUtility::makeInstance(ResourceFactory::class);
     }
 
     /**
index b6ade2a..dd8dd09 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
 use TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer;
 use TYPO3\CMS\Core\Resource\Folder;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Restricts the result to available file mounts.
@@ -85,7 +86,7 @@ class FolderMountsRestriction extends AbstractRestrictionContainer
         $this->folderMounts = [];
         $fileMounts = $this->backendUser->getFileMountRecords();
         foreach ($fileMounts as $fileMount) {
-            $this->folderMounts[] = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($fileMount['base'] . ':' . $fileMount['path']);
+            $this->folderMounts[] = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($fileMount['base'] . ':' . $fileMount['path']);
         }
 
         return $this->folderMounts;
index 22f579d..76b4d7b 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Resource\Search\FileSearchDemand;
 use TYPO3\CMS\Core\Resource\Search\FileSearchQuery;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Represents a search result for a given search query
@@ -121,7 +122,7 @@ class FileSearchResult implements FileSearchResultInterface
         $this->resultCount = count($this->result);
         $this->result = array_map(
             function (array $fileRow) {
-                return ResourceFactory::getInstance()->getFileObject($fileRow['uid'], $fileRow);
+                return GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileRow['uid'], $fileRow);
             },
             $this->result
         );
index 4386f6a..965c136 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\DataHandling\DataHandlerCheckModifyAccessListHookInterface;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\SingletonInterface;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 
 /**
@@ -162,7 +163,7 @@ class FileMetadataPermissionsAspect implements DataHandlerCheckModifyAccessListH
             if (strpos($file, 'sys_file_') !== false) {
                 $file = substr($file, strlen('sys_file_'));
             }
-            $fileObject = ResourceFactory::getInstance()->getFileObject((int)$file);
+            $fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject((int)$file);
             $accessAllowed = $fileObject->checkActionPermission('editMeta');
         }
         return $accessAllowed;
index 4866b3b..4810673 100644 (file)
@@ -41,6 +41,7 @@ class ServiceProvider extends AbstractServiceProvider
             Http\MiddlewareStackResolver::class => [ static::class, 'getMiddlewareStackResolver' ],
             Service\DependencyOrderingService::class => [ static::class, 'getDependencyOrderingService' ],
             Crypto\PasswordHashing\PasswordHashFactory::class => [ static::class, 'getPasswordHashFactory' ],
+            Resource\ResourceFactory::class => [ static::class, 'getResourceFactory' ],
             'middlewares' => [ static::class, 'getMiddlewares' ],
         ];
     }
@@ -115,6 +116,13 @@ class ServiceProvider extends AbstractServiceProvider
         );
     }
 
+    public static function getResourceFactory(ContainerInterface $container): Resource\ResourceFactory
+    {
+        return self::new($container, Resource\ResourceFactory::class, [
+            $container->get(EventDispatcherInterface::class)
+        ]);
+    }
+
     public static function getMiddlewares(ContainerInterface $container): ArrayObject
     {
         return new ArrayObject();
index 3901ee9..845e231 100644 (file)
@@ -170,7 +170,7 @@ class ExtendedFileUtility extends BasicFileUtility
     public function start($fileCmds)
     {
         // Initialize Object Factory
-        $this->fileFactory = ResourceFactory::getInstance();
+        $this->fileFactory = GeneralUtility::makeInstance(ResourceFactory::class);
         // Initializing file processing commands:
         $this->fileCmdMap = $fileCmds;
     }
@@ -1086,7 +1086,7 @@ class ExtendedFileUtility extends BasicFileUtility
             try {
                 /** @var File $fileObject */
                 $fileObject = $targetFolderObject->addUploadedFile($fileInfo, (string)$this->existingFilesConflictMode);
-                $fileObject = ResourceFactory::getInstance()->getFileObjectByStorageAndIdentifier($targetFolderObject->getStorage()->getUid(), $fileObject->getIdentifier());
+                $fileObject = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectByStorageAndIdentifier($targetFolderObject->getStorage()->getUid(), $fileObject->getIdentifier());
                 if ($this->existingFilesConflictMode->equals(DuplicationBehavior::REPLACE)) {
                     $this->getIndexer($fileObject->getStorage())->updateIndexEntry($fileObject);
                 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-90260-ResourceFactorygetInstancePseudo-factory.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-90260-ResourceFactorygetInstancePseudo-factory.rst
new file mode 100644 (file)
index 0000000..a49d111
--- /dev/null
@@ -0,0 +1,42 @@
+.. include:: ../../Includes.txt
+
+=================================================================
+Deprecation: #90260 - ResourceFactory::getInstance pseudo-factory
+=================================================================
+
+See :issue:`90260`
+
+Description
+===========
+
+The method :php:`ResourceFactory::getInstance()` acts as a wrapper
+for the constructor which originally was meant as a performance
+improvement as pseudo-singleton concept in TYPO3 v4.7.
+
+However, ResourceFactory was never optimized and now with Dependency
+Injection, ResourceFactory can be used directly.
+
+Therefore the method is marked as deprecated.
+
+
+Impact
+======
+
+Calling :php:`ResourceFactory::getInstance()` will trigger a PHP deprecation warning.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation with custom PHP code calling this method.
+
+
+Migration
+=========
+
+Check TYPO3's "Extension Scanner" in the Install Tool if you're affected and replace this with constructor injection via Dependency
+Injection if possible, or use :php:`GeneralUtility::makeInstance(ResourceFactory::class)` instead.
+
+The latter can already applied in earlier versions (TYPO3 v7 or higher) to ease optimal migration of this deprecation.
+
+.. index:: FAL, PHP-API, FullyScanned, ext:core
\ No newline at end of file
index 813fd24..c12a410 100644 (file)
@@ -55,7 +55,7 @@ class ResourceStorageTest extends FunctionalTestCase
         file_put_contents(Environment::getPublicPath() . '/fileadmin/adirectory/bar.txt', 'myData');
         clearstatcache();
         $subject->addFileMount('/adirectory/', ['read_only' => false]);
-        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/adirectory/bar.txt');
+        $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier('1:/adirectory/bar.txt');
 
         $rootProcessingFolder = $subject->getProcessingFolder();
         $processingFolder = $subject->getProcessingFolder($file);
@@ -90,7 +90,7 @@ class ResourceStorageTest extends FunctionalTestCase
         }
         file_put_contents(Environment::getPublicPath() . '/fileadmin/' . $targetDirectory . '/' . $fileName, 'myData');
         clearstatcache();
-        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/' . $targetDirectory . '/' . $fileName);
+        $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier('1:/' . $targetDirectory . '/' . $fileName);
 
         $subject = (new StorageRepository())->findByUid(1);
         $subject->setEvaluatePermissions(true);
@@ -194,7 +194,7 @@ class ResourceStorageTest extends FunctionalTestCase
         GeneralUtility::mkdir_deep(Environment::getPublicPath() . '/fileadmin/foo');
         file_put_contents(Environment::getPublicPath() . '/fileadmin/foo/bar.txt', 'myData');
         clearstatcache();
-        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
+        $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
 
         $this->expectException(\InvalidArgumentException::class);
         $this->expectExceptionCode(1325842622);
@@ -229,7 +229,7 @@ class ResourceStorageTest extends FunctionalTestCase
         file_put_contents(Environment::getPublicPath() . '/fileadmin/foo/bar.txt', 'myData');
         clearstatcache();
 
-        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
+        $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
         $subject->deleteFile($file);
 
         self::assertTrue(file_exists(Environment::getPublicPath() . '/fileadmin/_recycler_/bar.txt'));
@@ -249,7 +249,7 @@ class ResourceStorageTest extends FunctionalTestCase
         file_put_contents(Environment::getPublicPath() . '/fileadmin/foo/bar.txt', 'myData');
         clearstatcache();
 
-        $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
+        $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier('1:/foo/bar.txt');
         $subject->deleteFile($file);
 
         self::assertFalse(file_exists(Environment::getPublicPath() . '/fileadmin/foo/bar.txt'));
@@ -403,7 +403,7 @@ class ResourceStorageTest extends FunctionalTestCase
             file_put_contents(Environment::getPublicPath() . '/fileadmin/bar/blupp.txt', 'myData');
             clearstatcache();
 
-            $folder = $searchFolder ? ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier('1:' . $searchFolder) : null;
+            $folder = $searchFolder ? GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier('1:' . $searchFolder) : null;
             $search = FileSearchDemand::createForSearchTerm($searchTerm);
             if ($recursive) {
                 $search = $search->withRecursive();
index 1979bb9..bcf129f 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * A file object (File Abstraction Layer)
  *
@@ -27,7 +30,7 @@ class File extends \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder
     public function getOriginalResource()
     {
         if ($this->originalResource === null) {
-            $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($this->getUid());
+            $this->originalResource = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($this->getUid());
         }
 
         return $this->originalResource;
index 43f987a..31a67b1 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * A file reference object (File Abstraction Layer)
  *
@@ -45,7 +48,7 @@ class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder
     {
         if ($this->originalResource === null) {
             $uid = $this->_localizedUid;
-            $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($uid);
+            $this->originalResource = GeneralUtility::makeInstance(ResourceFactory::class)->getFileReferenceObject($uid);
         }
 
         return $this->originalResource;
index 38512b1..8f3611c 100644 (file)
@@ -49,7 +49,7 @@ class ImageService implements \TYPO3\CMS\Core\SingletonInterface
     public function __construct(EnvironmentService $environmentService = null, ResourceFactory $resourceFactory = null)
     {
         $this->environmentService = $environmentService ?? GeneralUtility::makeInstance(EnvironmentService::class);
-        $this->resourceFactory = $resourceFactory ?? ResourceFactory::getInstance();
+        $this->resourceFactory = $resourceFactory ?? GeneralUtility::makeInstance(ResourceFactory::class);
     }
 
     /**
index e988fb2..78b56d1 100644 (file)
@@ -113,7 +113,7 @@ class FileProvider extends \TYPO3\CMS\Backend\ContextMenu\ItemProviders\Abstract
     protected function initialize()
     {
         parent::initialize();
-        $fileObject = ResourceFactory::getInstance()
+        $fileObject = GeneralUtility::makeInstance(ResourceFactory::class)
                 ->retrieveFileOrFolderObject($this->identifier);
         $this->record = $fileObject;
     }
@@ -243,7 +243,7 @@ class FileProvider extends \TYPO3\CMS\Backend\ContextMenu\ItemProviders\Abstract
             return false;
         }
         $selItem = reset($elArr);
-        $fileOrFolderInClipBoard = ResourceFactory::getInstance()->retrieveFileOrFolderObject($selItem);
+        $fileOrFolderInClipBoard = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($selItem);
 
         return $this->isFolder()
             && $this->record->checkActionPermission('write')
@@ -357,7 +357,7 @@ class FileProvider extends \TYPO3\CMS\Backend\ContextMenu\ItemProviders\Abstract
         if ($itemName === 'pasteInto' && $this->backendUser->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE)) {
             $elArr = $this->clipboard->elFromTable('_FILE');
             $selItem = reset($elArr);
-            $fileOrFolderInClipBoard = ResourceFactory::getInstance()->retrieveFileOrFolderObject($selItem);
+            $fileOrFolderInClipBoard = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($selItem);
 
             $title = $this->languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:clip_paste');
 
index a6b1831..5c64ea5 100644 (file)
@@ -111,7 +111,7 @@ class CreateFolderController
         $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
         // create the folder object
         if ($combinedIdentifier) {
-            $this->folderObject = ResourceFactory::getInstance()
+            $this->folderObject = GeneralUtility::makeInstance(ResourceFactory::class)
                 ->getFolderObjectFromCombinedIdentifier($combinedIdentifier);
         }
         // Cleaning and checking target directory
index ecd205f..38a886d 100644 (file)
@@ -123,7 +123,7 @@ class EditFileController
         $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
         // create the file object
         if ($this->target) {
-            $this->fileObject = ResourceFactory::getInstance()
+            $this->fileObject = GeneralUtility::makeInstance(ResourceFactory::class)
                 ->retrieveFileOrFolderObject($this->target);
         }
         // Cleaning and checking target directory
index 7a88a32..163c858 100644 (file)
@@ -104,7 +104,7 @@ class FileUploadController
         }
         // Create the folder object
         if ($this->target) {
-            $this->folderObject = ResourceFactory::getInstance()
+            $this->folderObject = GeneralUtility::makeInstance(ResourceFactory::class)
                 ->retrieveFileOrFolderObject($this->target);
         }
         if ($this->folderObject->getStorage()->getUid() === 0) {
index 65c82c7..b976d40 100644 (file)
@@ -26,6 +26,7 @@ use TYPO3\CMS\Core\Resource\DuplicationBehavior;
 use TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\Folder;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 
@@ -94,7 +95,7 @@ class RenameFileController
         $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? '');
         // Cleaning and checking target
         if ($this->target) {
-            $this->fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
+            $this->fileOrFolderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($this->target);
         }
         if (!$this->fileOrFolderObject) {
             $title = $this->getLanguageService()->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:paramError');
index 9993df6..3d949da 100644 (file)
@@ -95,7 +95,7 @@ class ReplaceFileController
 
         // Cleaning and checking uid
         if ($this->uid > 0) {
-            $this->fileOrFolderObject = ResourceFactory::getInstance()
+            $this->fileOrFolderObject = GeneralUtility::makeInstance(ResourceFactory::class)
                 ->retrieveFileOrFolderObject('file:' . $this->uid);
         }
         if (!$this->fileOrFolderObject) {
index 3814f20..53b0378 100644 (file)
@@ -319,7 +319,7 @@ class FileList
         // Setting the maximum length of the filenames to the user's settings or minimum 30 (= $this->fixedL)
         $this->fixedL = max($this->fixedL, $this->getBackendUser()->uc['titleLen']);
         $this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_common.xlf');
-        $this->resourceFactory = ResourceFactory::getInstance();
+        $this->resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
     }
 
     /**
index 9744de3..4488e90 100644 (file)
@@ -79,7 +79,7 @@ class FormFileExtensionUpdateTest extends FunctionalTestCase
         Bootstrap::initializeLanguageObject();
 
         $folderIdentifier = 'form_definitions';
-        $storage = ResourceFactory::getInstance()->getStorageObject(1);
+        $storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject(1);
 
         if ($storage->hasFolder($folderIdentifier)) {
             $storage->getFolder($folderIdentifier)->delete(true);
index 4333cb6..587b49f 100644 (file)
@@ -502,9 +502,9 @@ class ContentObjectRenderer implements LoggerAwareInterface
             [$objectType, $identifier] = explode(':', $this->currentFile, 2);
             try {
                 if ($objectType === 'File') {
-                    $this->currentFile = ResourceFactory::getInstance()->retrieveFileOrFolderObject($identifier);
+                    $this->currentFile = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($identifier);
                 } elseif ($objectType === 'FileReference') {
-                    $this->currentFile = ResourceFactory::getInstance()->getFileReferenceObject($identifier);
+                    $this->currentFile = GeneralUtility::makeInstance(ResourceFactory::class)->getFileReferenceObject($identifier);
                 }
             } catch (ResourceDoesNotExistException $e) {
                 $this->currentFile = null;
@@ -1294,9 +1294,9 @@ class ContentObjectRenderer implements LoggerAwareInterface
             $file = $imageFile->getOriginalFile();
         } else {
             if (MathUtility::canBeInterpretedAsInteger($imageFile)) {
-                $file = ResourceFactory::getInstance()->getFileObject((int)$imageFile);
+                $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject((int)$imageFile);
             } else {
-                $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier($imageFile);
+                $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier($imageFile);
             }
         }
 
@@ -7001,7 +7001,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
      */
     protected function getResourceFactory()
     {
-        return ResourceFactory::getInstance();
+        return GeneralUtility::makeInstance(ResourceFactory::class);
     }
 
     /**
index 100c9ec..ce02eec 100644 (file)
@@ -134,9 +134,9 @@ EOF;
         }
 
         if (MathUtility::canBeInterpretedAsInteger($fileUid)) {
-            $this->file = ResourceFactory::getInstance()->getFileObject((int)$fileUid);
+            $this->file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject((int)$fileUid);
         } else {
-            $this->file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileUid);
+            $this->file = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($fileUid);
         }
         $this->frame = $this->request->getQueryParams()['frame'] ?? null;
     }
index a1a4c84..7bf18b6 100644 (file)
@@ -322,7 +322,7 @@ class ImportController extends ImportExportController
     protected function getFile(string $combinedIdentifier): ?File
     {
         try {
-            $file = ResourceFactory::getInstance()->getFileObjectFromCombinedIdentifier($combinedIdentifier);
+            $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObjectFromCombinedIdentifier($combinedIdentifier);
         } catch (\Exception $exception) {
             $file = null;
         }
index 74f485e..1d418d6 100644 (file)
@@ -380,7 +380,7 @@ class Export extends ImportExport
                         if (isset($newRelation['softrefs']['keys']['typolink'])) {
                             foreach ($newRelation['softrefs']['keys']['typolink'] as $softrefKey => $softRefData) {
                                 if ($softRefData['subst']['type'] === 'file') {
-                                    $file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($softRefData['subst']['relFileName']);
+                                    $file = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($softRefData['subst']['relFileName']);
                                     if ($file instanceof File) {
                                         if ($file->getUid() == $dbRelationData['id']) {
                                             unset($newRelation['softrefs']['keys']['typolink'][$softrefKey]);
@@ -630,7 +630,7 @@ class Export extends ImportExport
         }
         foreach ($this->dat['header']['records']['sys_file'] as $sysFileUid => $_) {
             $recordData = $this->dat['records']['sys_file:' . $sysFileUid]['data'];
-            $file = ResourceFactory::getInstance()->createFileObject($recordData);
+            $file = GeneralUtility::makeInstance(ResourceFactory::class)->createFileObject($recordData);
             $this->export_addSysFile($file);
         }
     }
index 444ef5f..f730101 100644 (file)
@@ -217,7 +217,7 @@ class Import extends ImportExport
 
         $defaultStorageUid = null;
         // get default storage
-        $defaultStorage = ResourceFactory::getInstance()->getDefaultStorage();
+        $defaultStorage = GeneralUtility::makeInstance(ResourceFactory::class)->getDefaultStorage();
         if ($defaultStorage !== null) {
             $defaultStorageUid = $defaultStorage->getUid();
         }
@@ -244,7 +244,7 @@ class Import extends ImportExport
             && (bool)$storageObject->isWritable() === (bool)$storageRecord['is_writable']
             && (bool)$storageObject->isOnline() === (bool)$storageRecord['is_online']
         ) {
-            $storageRecordConfiguration = ResourceFactory::getInstance()->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
+            $storageRecordConfiguration = GeneralUtility::makeInstance(ResourceFactory::class)->convertFlexFormDataToConfigurationArray($storageRecord['configuration']);
             $storageObjectConfiguration = $storageObject->getConfiguration();
             // compare the properties: pathType and basePath
             if ($storageRecordConfiguration['pathType'] === $storageObjectConfiguration['pathType']
@@ -303,7 +303,7 @@ class Import extends ImportExport
                         // storage object will check whether the target folder exists and set the
                         // isOnline flag depending on the outcome.
                         $storageRecord['uid'] = 0;
-                        $resourceStorage = ResourceFactory::getInstance()->createStorageObject($storageRecord);
+                        $resourceStorage = GeneralUtility::makeInstance(ResourceFactory::class)->createStorageObject($storageRecord);
                         if (!$resourceStorage->isOnline()) {
                             $configuration = $resourceStorage->getConfiguration();
                             $messages['resourceStorageFolderMissing_' . $storageRecordUid] =
@@ -333,7 +333,7 @@ class Import extends ImportExport
         // fetch fresh storage records from database
         $storageRecords = $this->fetchStorageRecords();
 
-        $defaultStorage = ResourceFactory::getInstance()->getDefaultStorage();
+        $defaultStorage = GeneralUtility::makeInstance(ResourceFactory::class)->getDefaultStorage();
 
         $sanitizedFolderMappings = [];
 
@@ -377,9 +377,9 @@ class Import extends ImportExport
             // mapping. Only in this case we could be sure, that it's a local, online and writable storage.
             if ($useStorageFromStorageRecords && isset($storageRecords[$fileRecord['storage']])) {
                 /** @var \TYPO3\CMS\Core\Resource\ResourceStorage $storage */
-                $storage = ResourceFactory::getInstance()->getStorageObject($fileRecord['storage'], $storageRecords[$fileRecord['storage']]);
+                $storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($fileRecord['storage'], $storageRecords[$fileRecord['storage']]);
             } elseif ($this->isFallbackStorage($fileRecord['storage'])) {
-                $storage = ResourceFactory::getInstance()->getStorageObject(0);
+                $storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject(0);
             } elseif ($defaultStorage !== null) {
                 $storage = $defaultStorage;
             } else {
@@ -1055,7 +1055,7 @@ class Import extends ImportExport
                     // Fallback value
                     $value = 'file:' . $fileUid;
                     try {
-                        $file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($fileUid);
+                        $file = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($fileUid);
                     } catch (\Exception $e) {
                         $file = null;
                     }
@@ -1536,7 +1536,7 @@ class Import extends ImportExport
         // Just for security, check again. Should actually not be necessary.
         if (!$bypassMountCheck) {
             try {
-                ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier(PathUtility::dirname($fileName));
+                GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier(PathUtility::dirname($fileName));
             } catch (InsufficientFolderAccessPermissionsException $e) {
                 $this->error('ERROR: Filename "' . $fileName . '" was not allowed in destination path!');
                 return false;
index fda86d7..dc6f7ff 100644 (file)
@@ -921,7 +921,7 @@ abstract class ImportExport
     {
         // Check the absolute path for public web path, if the user has access - no problem
         try {
-            ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($dirPrefix);
+            GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($dirPrefix);
             return $dirPrefix;
         } catch (InsufficientFolderAccessPermissionsException $e) {
             // Check all storages available for the user as alternative
index 03c169a..480fee8 100644 (file)
@@ -959,4 +959,11 @@ return [
             'Deprecation-89756-BackendUtilityTYPO3_copyRightNotice.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Resource\ResourceFactory::getInstance' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-90260-ResourceFactorygetInstancePseudo-factory.rst',
+        ],
+    ],
 ];
index daf06e1..11642fd 100644 (file)
@@ -149,7 +149,7 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
             // Try to fetch the folder the user had open the last time he browsed files
             // Fallback to the default folder in case the last used folder is not existing
             try {
-                $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
+                $fileOrFolderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($this->expandFolder);
             } catch (Exception $accessException) {
                 // We're just catching the exception here, nothing to be done if folder does not exist or is not accessible.
             } catch (\InvalidArgumentException $driverMissingExecption) {
index 32d80d8..865a4e9 100644 (file)
@@ -85,7 +85,7 @@ class FolderBrowser extends AbstractElementBrowser implements ElementBrowserInte
     {
         $selectedFolder = null;
         if ($this->expandFolder) {
-            $selectedFolder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
+            $selectedFolder = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($this->expandFolder);
         }
 
         // Create folder tree:
index 1e8649d..47c2883 100644 (file)
@@ -269,7 +269,7 @@ class FileLinkHandler extends AbstractLinkHandler implements LinkHandlerInterfac
         $selectedFolder = false;
         if ($folderIdentifier) {
             try {
-                $fileOrFolderObject = ResourceFactory::getInstance()->retrieveFileOrFolderObject($folderIdentifier);
+                $fileOrFolderObject = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($folderIdentifier);
                 if ($fileOrFolderObject instanceof Folder) {
                     // It's a folder
                     $selectedFolder = $fileOrFolderObject;
index 6bd42c6..0cb4bd9 100644 (file)
@@ -161,7 +161,7 @@ class FileStorageExtractionAdditionalFieldProvider implements AdditionalFieldPro
         ) {
             return false;
         }
-        if (ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) === null) {
+        if (GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) === null) {
             return false;
         }
         if (!MathUtility::isIntegerInRange($submittedData['scheduler_fileStorageIndexing_fileCount'], 1, 9999)) {
index 8dec869..24ad9e3 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Scheduler\Task;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * This task which indexes files in storage
  * @internal This class is a specific scheduler task implementation is not considered part of the Public TYPO3 API.
@@ -43,7 +46,7 @@ class FileStorageExtractionTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
     {
         $success = false;
         if ((int)$this->storageUid > 0) {
-            $storage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($this->storageUid);
+            $storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($this->storageUid);
             $currentEvaluatePermissionsValue = $storage->getEvaluatePermissions();
             $storage->setEvaluatePermissions(false);
             $indexer = $this->getIndexer($storage);
@@ -67,6 +70,6 @@ class FileStorageExtractionTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
      */
     protected function getIndexer(\TYPO3\CMS\Core\Resource\ResourceStorage $storage)
     {
-        return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $storage);
+        return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $storage);
     }
 }
index cfdc75a..ba355a5 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Scheduler\Task;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * Additional BE fields for tasks which indexes files in a storage
  * @internal This class is a specific scheduler task implementation is not considered part of the Public TYPO3 API.
@@ -87,7 +90,7 @@ class FileStorageIndexingAdditionalFieldProvider implements \TYPO3\CMS\Scheduler
         if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($value)) {
             return false;
         }
-        if (\TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) !== null) {
+        if (GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) !== null) {
             return true;
         }
         return false;
index 41efa1a..da88eae 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Scheduler\Task;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * This task tries to find changes in storage and writes them back to DB
  * @internal This class is a specific scheduler task implementation is not considered part of the Public TYPO3 API.
@@ -35,7 +38,7 @@ class FileStorageIndexingTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
     public function execute()
     {
         if ((int)$this->storageUid > 0) {
-            $storage = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($this->storageUid);
+            $storage = GeneralUtility::makeInstance(ResourceFactory::class)->getStorageObject($this->storageUid);
             $currentEvaluatePermissionsValue = $storage->getEvaluatePermissions();
             $storage->setEvaluatePermissions(false);
             $indexer = $this->getIndexer($storage);
@@ -53,6 +56,6 @@ class FileStorageIndexingTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
      */
     protected function getIndexer(\TYPO3\CMS\Core\Resource\ResourceStorage $storage)
     {
-        return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $storage);
+        return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\Index\Indexer::class, $storage);
     }
 }
index 583fd35..527980e 100644 (file)
@@ -889,7 +889,7 @@ class SetupModuleController
 
             // Get file object
             try {
-                $file = ResourceFactory::getInstance()->getFileObject($fileUid);
+                $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
             } catch (FileDoesNotExistException $e) {
                 $file = false;
             }
index a5aa7a9..a142575 100644 (file)
@@ -47,7 +47,7 @@ class FileEditHook
             $target = $parameters['target'];
         }
 
-        $fileExtension = ResourceFactory::getInstance()->retrieveFileOrFolderObject($target)->getExtension();
+        $fileExtension = GeneralUtility::makeInstance(ResourceFactory::class)->retrieveFileOrFolderObject($target)->getExtension();
         $modeRegistry = GeneralUtility::makeInstance(ModeRegistry::class);
         try {
             $mode = $modeRegistry->getByFileExtension($fileExtension);