diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-94367-ExtbaseReferringRequest.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-94367-ExtbaseReferringRequest.rst new file mode 100644 index 000000000000..aedfa26853f6 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-94367-ExtbaseReferringRequest.rst @@ -0,0 +1,37 @@ +.. include:: ../../Includes.txt + +============================================== +Deprecation: #94367 - extbase ReferringRequest +============================================== + +See :issue:`94367` + +Description +=========== + +To further prepare extbase towards PSR-7 compatible requests, extbase class +:php:`TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest` has been deprecated. + + +Impact +====== + +Creating an instance of :php:`ReferringRequest` will trigger a PHP deprecation warning. + + +Affected Installations +====================== + +:php:`ReferringRequest` has been mostly extbase internal and rarely used in +extbase extensions, probably only in cases where +:php:`ActionController->forwardToReferringRequest()` is overridden. +The extension scanner will find usages with a strong match. + +Migration +========= + +Extbase internally, :php:`ReferringRequest` has only been used to +immediately create a :php:`ForwardResponse` from it. Consuming extensions +should follow his approach and create a :php:`ForwardResponse` directly. + +.. index:: PHP-API, FullyScanned, ext:extbase diff --git a/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php b/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php index 46cfa6e8b75c..08c88348a1c9 100644 --- a/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php +++ b/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php @@ -30,10 +30,12 @@ use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; +use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Event\Mvc\BeforeActionCallEvent; use TYPO3\CMS\Extbase\Http\ForwardResponse; use TYPO3\CMS\Extbase\Mvc\Controller\Exception\RequiredArgumentMissingException; +use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException; use TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException; use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException; use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException; @@ -43,7 +45,6 @@ use TYPO3\CMS\Extbase\Mvc\View\NotFoundView; use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; use TYPO3\CMS\Extbase\Mvc\View\ViewResolverInterface; -use TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Property\Exception\TargetNotFoundException; @@ -795,20 +796,25 @@ protected function forwardToReferringRequest(): ?ResponseInterface base64_decode($this->hashService->validateAndStripHmac($referringRequestArguments['arguments'])) ); } - // todo: Remove ReferringRequest. It's only used here in this context to trigger the logic of - // \TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest::setArgument() and its parent method which should then - // be extracted from the request class. - $referringRequest = new ReferringRequest(); - $referringRequest->setArguments(array_replace_recursive($arguments, $referrerArray)); - } - - if ($referringRequest !== null) { - return (new ForwardResponse((string)$referringRequest->getControllerActionName())) - ->withControllerName((string)$referringRequest->getControllerName()) - ->withExtensionName((string)$referringRequest->getControllerExtensionName()) - ->withArguments($referringRequest->getArguments()) - ->withArgumentsValidationResult($this->arguments->validate()) - ; + $replacedArguments = array_replace_recursive($arguments, $referrerArray); + $nonExtbaseBaseArguments = []; + foreach ($replacedArguments as $argumentName => $argumentValue) { + if (!is_string($argumentName) || $argumentName === '') { + throw new InvalidArgumentNameException('Invalid argument name.', 1623940985); + } + if (StringUtility::beginsWith($argumentName, '__') + || in_array($argumentName, ['@extension', '@subpackage', '@controller', '@action', '@format'], true) + ) { + // Don't handle internalArguments here, not needed for forwardResponse() + continue; + } + $nonExtbaseBaseArguments[$argumentName] = $argumentValue; + } + return (new ForwardResponse((string)($replacedArguments['@action'] ?? 'index'))) + ->withControllerName((string)($replacedArguments['@controller'] ?? 'Standard')) + ->withExtensionName((string)($replacedArguments['@extension'] ?? '')) + ->withArguments($nonExtbaseBaseArguments) + ->withArgumentsValidationResult($this->arguments->validate()); } return null; diff --git a/typo3/sysext/extbase/Classes/Mvc/Controller/Arguments.php b/typo3/sysext/extbase/Classes/Mvc/Controller/Arguments.php index e58ad7fc1f73..ce0edd4ce9b5 100644 --- a/typo3/sysext/extbase/Classes/Mvc/Controller/Arguments.php +++ b/typo3/sysext/extbase/Classes/Mvc/Controller/Arguments.php @@ -274,6 +274,7 @@ public function validate(): Result foreach ($this as $argument) { $argumentValidationResults = $argument->validate(); if ($argumentValidationResults === null) { + // @todo: Obsolete?! "validate(): Result", can't be null! continue; } $results->forProperty($argument->getName())->merge($argumentValidationResults); diff --git a/typo3/sysext/extbase/Classes/Mvc/Web/ReferringRequest.php b/typo3/sysext/extbase/Classes/Mvc/Web/ReferringRequest.php index d8e06f47d02e..19d78222d88e 100644 --- a/typo3/sysext/extbase/Classes/Mvc/Web/ReferringRequest.php +++ b/typo3/sysext/extbase/Classes/Mvc/Web/ReferringRequest.php @@ -19,9 +19,21 @@ /** * Represents a referring web request. + * + * @deprecated since v11, will be removed in v12. Create a ForwardResponse instead, see ActionController->forwardToReferringRequest() */ class ReferringRequest extends Request { + /** + * @param string $controllerClassName + */ + public function __construct(string $controllerClassName = '') + { + // @todo: Move to parent::__construct() in case Request is deprecated in v11, too, otherwise drop this todo. + trigger_error(__CLASS__ . ' will be removed in TYPO3 v12, use ForwardResponse instead, see ActionController->forwardToReferringRequest().', E_USER_DEPRECATED); + parent::__construct($controllerClassName); + } + /** * Sets the value of the specified argument * diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php index 9a95fd5944bc..6f9dde682cf5 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php @@ -1664,4 +1664,9 @@ 'Deprecation-94313-ClassAbstractService.rst' ], ], + 'TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest' => [ + 'restFiles' => [ + 'Deprecation-94367-ExtbaseReferringRequest.rst' + ], + ], ];