[TASK] Deprecate extbase request getRequestUri()
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 28 May 2021 20:39:31 +0000 (22:39 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 30 May 2021 16:54:10 +0000 (18:54 +0200)
The next step towards a PSR-7 compatible request
object in extbase is to get rid of getRequestUri()
and setRequestUri().

The strategy is similar to getBaseUri() from issue
#94223: The Internal method setRequestUri() is dropped
and the unused getRequestUri() is deprecated.

Resolves: #94228
Related: #94223
Releases: master
Change-Id: I99f74ac989fd697404b63c90c3ee8843abb80626
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69316
Tested-by: core-ci <typo3@b13.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Simon Gilli <typo3@gilbertsoft.org>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Simon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-94228-DeprecateExtbaseRequestGetRequestUri.rst [new file with mode: 0644]
typo3/sysext/extbase/Classes/Mvc/Request.php
typo3/sysext/extbase/Classes/Mvc/Web/RequestBuilder.php
typo3/sysext/fluid/Classes/View/StandaloneView.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-94228-DeprecateExtbaseRequestGetRequestUri.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-94228-DeprecateExtbaseRequestGetRequestUri.rst
new file mode 100644 (file)
index 0000000..1b60cef
--- /dev/null
@@ -0,0 +1,52 @@
+.. include:: ../../Includes.txt
+
+===============================================================
+Deprecation: #94228 - Deprecate extbase request getRequestUri()
+===============================================================
+
+See :issue:`94228`
+
+Description
+===========
+
+To further prepare extbase towards PSR-7 compatible requests, the
+extbase :php:`TYPO3\CMS\Extbase\Mvc\Request` has to be streamlined.
+
+Method :php:`getRequestUri()` has been deprecated and shouldn't be
+used any longer.
+
+
+Impact
+======
+
+Using the method will log a deprecation message, it will be
+removed with v12.
+
+
+
+Affected Installations
+======================
+
+Extbase based extensions may use this method. The extension scanner
+will find usages as weak match.
+
+
+Migration
+=========
+
+When :php:`getRequestUri()` is called in extensions, the same information
+can be retrieved from the native PSR-7 request. At the moment, this is usually
+only available using :php:`$GLOBALS['TYPO3_REQUEST']`, but this will change
+when the extbase request is compatible with PSR-7 ServerRequestInterface.
+A substitution looks like this for now:
+
+.. code-block:: php
+
+    // @todo Adapt this example as soon as extbase Request implements ServerRequestInterface
+    $request = $GLOBALS['TYPO3_REQUEST'];
+    /** @var NormalizedParams $normalizedParams */
+    $normalizedParams = $request->getAttribute('normalizedParams');
+    $requestUrl = $normalizedParams->getRequestUrl();
+
+
+.. index:: PHP-API, FullyScanned, ext:extbase
index 37e6f5a..e185395 100644 (file)
@@ -103,11 +103,6 @@ class Request implements RequestInterface
      */
     protected $originalRequestMappingResults;
 
-    /**
-     * @var string
-     */
-    protected $requestUri;
-
     /**
      * @var bool TRUE if the current request is cached, false otherwise.
      */
@@ -519,25 +514,21 @@ class Request implements RequestInterface
         return $request->getMethod();
     }
 
-    /**
-     * Sets the request URI
-     *
-     * @param string $requestUri URI of this web request
-     * @internal only to be used within Extbase, not part of TYPO3 Core API.
-     */
-    public function setRequestUri($requestUri)
-    {
-        $this->requestUri = $requestUri;
-    }
-
     /**
      * Returns the request URI
      *
      * @return string URI of this web request
+     * @deprecated since v11, will be removed in v12
      */
     public function getRequestUri()
     {
-        return $this->requestUri;
+        trigger_error('Method ' . __METHOD__ . ' is deprecated and will be removed in TYPO3 12.0', E_USER_DEPRECATED);
+
+        // @todo Global access is obsolete as soon as this class implements ServerRequestInterface
+        $mainRequest = $GLOBALS['TYPO3_REQUEST'];
+        /** @var NormalizedParams $normalizedParams */
+        $normalizedParams = $mainRequest->getAttribute('normalizedParams');
+        return $normalizedParams->getRequestUrl();
     }
 
     /**
index 14a74e1..a45316c 100644 (file)
@@ -17,7 +17,6 @@ namespace TYPO3\CMS\Extbase\Mvc\Web;
 
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
-use TYPO3\CMS\Core\Http\NormalizedParams;
 use TYPO3\CMS\Core\Routing\PageArguments;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
@@ -161,8 +160,6 @@ class RequestBuilder implements SingletonInterface
     {
         $this->loadDefaultValues();
         $pluginNamespace = $this->extensionService->getPluginNamespace($this->extensionName, $this->pluginName);
-        /** @var NormalizedParams $normalizedParams */
-        $normalizedParams = $mainRequest->getAttribute('normalizedParams');
         $queryArguments = $mainRequest->getAttribute('routing');
         if ($queryArguments instanceof PageArguments) {
             $parameters = $queryArguments->get($pluginNamespace) ?? [];
@@ -190,7 +187,6 @@ class RequestBuilder implements SingletonInterface
         $request->setControllerAliasToClassNameMapping($this->controllerAliasToClassMapping);
         $request->setControllerName($this->controllerClassToAliasMapping[$controllerClassName]);
         $request->setControllerActionName($actionName);
-        $request->setRequestUri($normalizedParams->getRequestUrl());
         if (isset($parameters['format']) && is_string($parameters['format']) && $parameters['format'] !== '') {
             $request->setFormat(filter_var($parameters['format'], FILTER_SANITIZE_STRING));
         } else {
index 2e3074e..8e0bba6 100644 (file)
@@ -49,7 +49,6 @@ class StandaloneView extends AbstractTemplateView
         $configurationManager->setContentObject($contentObject);
 
         $request = $objectManager->get(Request::class);
-        $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
         $renderingContext = $objectManager->get(RenderingContext::class, $this);
         $renderingContext->setRequest($request);
         parent::__construct($renderingContext);
index 615fb16..615dbd9 100644 (file)
@@ -4823,4 +4823,11 @@ return [
             'Deprecation-94223-ExtbaseRequest-getBaseUri.rst'
         ],
     ],
+    'TYPO3\CMS\Extbase\Mvc\Request->getRequestUri' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-94228-DeprecateExtbaseRequestGetRequestUri.rst'
+        ],
+    ],
 ];