Commit 8eb528d0 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[TASK] Deprecate extbase ReferringRequest

When extbase has been changed to PSR-7 responses,
class ReferringRequest has been nearly obsoleted:
It is only used to be immediately turned into a
ForwardResponse.
To further prepare towards PSR-7 requests, usage of
ReferringRequest which extends extbase Request is
dropped and the class marked as deprecated.

Change-Id: If16c09b0601792f6702fbacee064cd4d514c70c6
Resolves: #94367
Related: #92502
Releases: master
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69513

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 14805bdf
.. 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
......@@ -30,10 +30,12 @@ use TYPO3\CMS\Core\Messaging\FlashMessageService;
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\JsonView;
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 @@ abstract class ActionController implements ControllerInterface
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;
......
......@@ -274,6 +274,7 @@ class Arguments extends \ArrayObject
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);
......
......@@ -19,9 +19,21 @@ use TYPO3\CMS\Extbase\Mvc\Request;
/**
* 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
*
......
......@@ -1664,4 +1664,9 @@ return [
'Deprecation-94313-ClassAbstractService.rst'
],
],
'TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest' => [
'restFiles' => [
'Deprecation-94367-ExtbaseReferringRequest.rst'
],
],
];
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