Skip to content

Commit

Permalink
[TASK] Deprecate extbase ReferringRequest
Browse files Browse the repository at this point in the history
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 <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Jochen <rothjochen@gmail.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jochen <rothjochen@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
lolli42 committed Jun 18, 2021
1 parent 14805bd commit 8eb528d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 15 deletions.
@@ -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
36 changes: 21 additions & 15 deletions typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions typo3/sysext/extbase/Classes/Mvc/Controller/Arguments.php
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions typo3/sysext/extbase/Classes/Mvc/Web/ReferringRequest.php
Expand Up @@ -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
*
Expand Down
Expand Up @@ -1664,4 +1664,9 @@
'Deprecation-94313-ClassAbstractService.rst'
],
],
'TYPO3\CMS\Extbase\Mvc\Web\ReferringRequest' => [
'restFiles' => [
'Deprecation-94367-ExtbaseReferringRequest.rst'
],
],
];

0 comments on commit 8eb528d

Please sign in to comment.