diff --git a/typo3/sysext/backend/Classes/Controller/File/CreateFolderController.php b/typo3/sysext/backend/Classes/Controller/File/CreateFolderController.php index 1bc22522f6e8..b448bc4057f0 100644 --- a/typo3/sysext/backend/Classes/Controller/File/CreateFolderController.php +++ b/typo3/sysext/backend/Classes/Controller/File/CreateFolderController.php @@ -1,4 +1,5 @@ 'Using $number of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.', + 'folderNumber' => 'Using $folderNumber of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.', + 'target' => 'Using $target of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.', + 'content' => 'Using $content of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.', + 'returnUrl' => 'Using $content of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.', + 'title' => 'Using $content of class CreateFolderController from outside is discouraged, as this variable is only used for internal storage.', + ]; + /** * @var int */ - public $folderNumber = 10; + protected $folderNumber = 10; /** * Name of the filemount * * @var string + * @deprecated since v9, will be removed in v10, unused */ - public $title; + protected $title; /** * @var int */ - public $number; + protected $number; /** * Set with the target path inputted in &target * * @var string */ - public $target; + protected $target; /** * The folder object which is the target directory @@ -70,7 +89,7 @@ class CreateFolderController * * @var string */ - public $returnUrl; + protected $returnUrl; /** * @var array @@ -81,8 +100,9 @@ class CreateFolderController * Accumulating content * * @var string + * @deprecated since v9, will be removed in v10, unused */ - public $content; + protected $content; /** * ModuleTemplate object @@ -98,19 +118,36 @@ public function __construct() { $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); $GLOBALS['SOBE'] = $this; - $this->init(); + // @deprecated since v9, will be moved out of __construct() in v10 + $this->init($GLOBALS['TYPO3_REQUEST']); + } + + /** + * Processes the request, currently everything is handled and put together via "main()" + * + * @param ServerRequestInterface $request the current request + * @return ResponseInterface the response with the content + */ + public function mainAction(ServerRequestInterface $request): ResponseInterface + { + $this->main(); + return new HtmlResponse($this->moduleTemplate->renderContent()); } /** + * @param ServerRequestInterface|null $request + * * @throws InsufficientFolderAccessPermissionsException * @throws \RuntimeException */ - protected function init() + protected function init(ServerRequestInterface $request): void { - // Initialize GPvars: - $this->number = GeneralUtility::_GP('number'); - $this->target = ($combinedIdentifier = GeneralUtility::_GP('target')); - $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl')); + $parsedBody = $request->getParsedBody(); + $queryParams = $request->getQueryParams(); + + $this->number = $parsedBody['number'] ?? $queryParams['number'] ?? 0; + $this->target = ($combinedIdentifier = $parsedBody['target'] ?? $queryParams['target'] ?? ''); + $this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? ''); // create the folder object if ($combinedIdentifier) { $this->folderObject = ResourceFactory::getInstance() @@ -132,8 +169,7 @@ protected function init() $pathInfo = [ 'combined_identifier' => $this->folderObject->getCombinedIdentifier(), ]; - /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ - $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($pathInfo); $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu'); @@ -178,12 +214,18 @@ function backToList() { */ public function main() { + // Foreign class call? Method will be protected in v10, giving core freedom to move stuff around + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + if (end($backtrace)['class'] !== __CLASS__) { + // @deprecated since TYPO3 v9, this method will be set to protected in v10 + trigger_error('Method main() will be set to protected in v10. Do not call from other extension', E_USER_DEPRECATED); + } + $lang = $this->getLanguageService(); $assigns = []; $assigns['target'] = $this->target; if ($this->folderObject->checkActionPermission('add')) { - /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ - $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $assigns['moduleUrlTceFile'] = (string)$uriBuilder->buildUriFromRoute('tce_file'); $assigns['cshFileNewFolder'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newfolder'); // Making the selector box for the number of concurrent folder-creations @@ -206,8 +248,7 @@ public function main() } if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')) { - /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ - $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); + $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $assigns['moduleUrlOnlineMedia'] = (string)$uriBuilder->buildUriFromRoute('online_media'); $assigns['cshFileNewMedia'] = BackendUtility::cshItem('xMOD_csh_corebe', 'file_newMedia'); // Create a list of allowed file extensions with the readable format "youtube, vimeo" etc. @@ -257,28 +298,15 @@ public function main() 'EXT:backend/Resources/Private/Templates/File/CreateFolder.html' )); $view->assignMultiple($assigns); - $this->content = $view->render(); - $this->moduleTemplate->setContent($this->content); - } - - /** - * Processes the request, currently everything is handled and put together via "main()" - * - * @param ServerRequestInterface $request the current request - * @return ResponseInterface the response with the content - */ - public function mainAction(ServerRequestInterface $request): ResponseInterface - { - $this->main(); - return new HtmlResponse($this->moduleTemplate->renderContent()); + $this->moduleTemplate->setContent($view->render()); } /** * Returns LanguageService * - * @return \TYPO3\CMS\Core\Localization\LanguageService + * @return LanguageService */ - protected function getLanguageService() + protected function getLanguageService(): LanguageService { return $GLOBALS['LANG']; } diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84289-UseServerRequestInterfaceInFileCreateFolderController.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84289-UseServerRequestInterfaceInFileCreateFolderController.rst new file mode 100644 index 000000000000..bdd873b6e349 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-84289-UseServerRequestInterfaceInFileCreateFolderController.rst @@ -0,0 +1,50 @@ +.. include:: ../../Includes.txt + +=============================================================================== +Deprecation: #84289 - Use ServerRequestInterface in File/CreateFolderController +=============================================================================== + +See :issue:`84289` + +Description +=========== + +A series of class properties has been set to protected. +They will throw deprecation warnings if called public from outside: + +* :php:`$number` +* :php:`$folderNumber` +* :php:`$target` +* [not scanned] :php:`$title` +* [not scanned] :php:`$returnUrl` +* :php:`$content` + +All methods not used as entry points by :php:`TYPO3\CMS\Backend\Http\RouteDispatcher` will be +removed or set to protected in v10 and throw deprecation warnings if used from a third party: + +* [not scanned] :php:`main()` + +Impact +====== + +Calling one of the above methods or accessing one of the above properties on an instance of +:php:`CreateFolderController` will throw a deprecation warning in v9 and a PHP fatal in v10. + + +Affected Installations +====================== + +The extension scanner will find most usages, but may also find some false positives. The most +common property and method names like :php:`$title` are not registered and will not be found +if an extension uses that on an instance of :php:`CreateFolderController`. In general all extensions +that set properties or call methods except :php:`mainAction()` are affected. + + +Migration +========= + +In general, extensions should not instantiate and re-use controllers of the core. Existing +usages should be rewritten to be free of calls like these. + + +.. index:: Backend, PHP-API, PartiallyScanned, ext:backend diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php index 5b4898d82556..f266d9bc9d15 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php @@ -341,4 +341,24 @@ 'Deprecation-83904-ArrayHandlingInAbstractTreeView.rst', ], ], + 'TYPO3\CMS\Backend\Controller\File\CreateFolderController->number' => [ + 'restFiles' => [ + 'Deprecation-84289-UseServerRequestInterfaceInFileCreateFolderController.rst', + ], + ], + 'TYPO3\CMS\Backend\Controller\File\CreateFolderController->folderNumber' => [ + 'restFiles' => [ + 'Deprecation-84289-UseServerRequestInterfaceInFileCreateFolderController.rst', + ], + ], + 'TYPO3\CMS\Backend\Controller\File\CreateFolderController->target' => [ + 'restFiles' => [ + 'Deprecation-84289-UseServerRequestInterfaceInFileCreateFolderController.rst', + ], + ], + 'TYPO3\CMS\Backend\Controller\File\CreateFolderController->content' => [ + 'restFiles' => [ + 'Deprecation-84289-UseServerRequestInterfaceInFileCreateFolderController.rst', + ], + ], ];