[FEATURE] Add normalized server parameters to PSR-7 requests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Documentation / Changelog / master / Feature-83736-ExtendedPSR-7RequestsWithTYPO3ServerParameters.rst
1 .. include:: ../../Includes.txt
2
3 =================================================================================
4 Feature: #83736 - Extended PSR-7 requests with TYPO3 normalized server parameters
5 =================================================================================
6
7 See :issue:`83736`
8
9 Description
10 ===========
11
12 The PSR-7 based ServerRequest objects created by TYPO3 now contain a TYPO3-specific
13 attribute object for normalized server parameters that for instance resolves variables
14 if the instance is behind a reverse proxy. This substitutes :php:`GeneralUtility::getIndpEnv()`.
15
16 The object is **for now** available from :php:`ServerRequestInterface $request` objects as
17 attribute. The request object is given to controllers, example:
18
19 .. code-block:: php
20
21 /** @var NormalizedParams $normalizedParams */
22 $normalizedParams = $request->getAttribute('normalizedParams');
23 $requestPort = $normalizedParams->getRequestPort();
24
25 The request object is also available as a global variable in :php:`$GLOBALS['TYPO3_REQUEST']`.
26 This is a workaround for the core which has to access the server parameters at places where
27 $request is not available. So, while this object is globally available during any HTTP request,
28 it is considered bad practice to use it, and the extension scanner will mark an access to this
29 global variable as deprecated. The global object will vanish later if the core code has been
30 refactored enough to not rely on it anymore.
31
32 For now, class :php:`NormalizedParams` is a one-to-one transition of :php:`GeneralUtility::getIndpEnv()`,
33 the old arguments can be substituted with these calls:
34
35 - :php:`SCRIPT_NAME` is now :php:`->getScriptName()`
36 - :php:`SCRIPT_FILENAME` is now :php:`->getScriptFilename()`
37 - :php:`REQUEST_URI` is now :php:`->getRequestUri()`
38 - :php:`TYPO3_REV_PROXY` is now :php:`->isBehindReverseProxy()`
39 - :php:`REMOTE_ADDR` is now :php:`->getRemoteAddress()`
40 - :php:`HTTP_HOST` is now :php:`->getHttpHost()`
41 - :php:`TYPO3_DOCUMENT_ROOT` is now :php:`->getDocumentRoot()`
42 - :php:`TYPO3_HOST_ONLY` is now :php:`->getRequestHostOnly()`
43 - :php:`TYPO3_PORT` is now :php:`->getRequestPort()`
44 - :php:`TYPO3_REQUEST_HOST` is now :php:`->getRequestHost()`
45 - :php:`TYPO3_REQUEST_URL` is now :php:`->getRequestUrl()`
46 - :php:`TYPO3_REQUEST_SCRIPT` is now :php:`->getRequestScript()`
47 - :php:`TYPO3_REQUEST_DIR` is now :php:`->getRequestDir()`
48 - :php:`TYPO3_SITE_URL` is now :php:`->getSiteUrl()`
49 - :php:`TYPO3_SITE_PATH` is now :php:`->getSitePath()`
50 - :php:`TYPO3_SITE_SCRIPT` is now :php:`->getSiteScript()`
51 - :php:`TYPO3_SSL` is now :php:`->isHttps()`
52
53 Some further old :php:`getIndpEnv()` arguments directly access :php:`$request->serverParams()` and
54 do not apply any normalization. These have been transferred to the new class, too, but will be
55 deprecated later if the core does not use these anymore:
56
57 - :php:`PATH_INFO` is now :php:`->getPathInfo()`, but better use :php:`->getScriptPath()` instead
58 - :php:`HTTP_REFERER` is now :php:`->getHttpReferer()`, but better use :php:`$request->getServerParams()['HTTP_REFERER']` instead
59 - :php:`HTTP_USER_AGENT` is now :php:`->getHttpUserAgent()`, but better use :php:`$request->getServerParams()['HTTP_USER_AGENT']` instead
60 - :php:`HTTP_ACCEPT_ENCODING` is now :php:`->getHttpAcceptEncoding()`, but better use :php:`$request->getServerParams()['HTTP_ACCEPT_ENCODING']` instead
61 - :php:`HTTP_ACCEPT_LANGUAGE` is now :php:`->getHttpAcceptLanguage()`, but better use :php:`$request->getServerParams()['HTTP_ACCEPT_LANGUAGE']` instead
62 - :php:`REMOTE_HOST` is now :php:`->getRemoteHost()`, but better use :php:`$request->getServerParams()['REMOTE_HOST']` instead
63 - :php:`QUERY_STRING` is now :php:`->getQueryString()`, but better use :php:`$request->getServerParams()['QUERY_STRING']` instead
64
65
66 Impact
67 ======
68
69 The PSR-7 request objects created by TYPO3 now contain an instance of :php:`NormalizedParams` which can
70 be used instead of :php:`GeneralUtility::getIndpEnv()` to access normalized server params.
71
72 .. index:: PHP-API