Feature: #83736 - Extended PSR-7 requests with TYPO3 normalized server parameters
See forge#83736
Description
The PSR-7 based Server objects created by TYPO3 now contain a TYPO3-specific attribute object for normalized
server parameters that for instance resolves variables if the instance is behind a reverse proxy. This substitutes
General.
The object is for now available from
Server objects as attribute. The request object
is given to controllers, example:
$normalizedParams = $request->getAttribute('normalizedParams');
$requestPort = $normalizedParams->getRequestPort();
The request object is also available as a global variable in
$GLOBALS. This is a workaround for
the core which has to access the server parameters at places where $request is not available. So, while this object is
globally available during any HTTP request, it is considered bad practice to use it. The global object will vanish
later if the core code has been refactored enough to not rely on it anymore.
For now, class
Normalized is a one-to-one transition of
General, the old
arguments can be substituted with these calls:
SCRIPT_is nowNAME ->getScript Name () SCRIPT_is nowFILENAME ->getScript Filename () REQUEST_is nowURI ->getRequest Uri () TYPO3_is nowREV_ PROXY ->isBehind Reverse Proxy () REMOTE_is nowADDR ->getRemote Address () HTTP_is nowHOST ->getHttp Host () TYPO3_is nowDOCUMENT_ ROOT ->getDocument Root () TYPO3_is nowHOST_ ONLY ->getRequest Host Only () TYPO3_is nowPORT ->getRequest Port () TYPO3_is nowREQUEST_ HOST ->getRequest Host () TYPO3_is nowREQUEST_ URL ->getRequest Url () TYPO3_is nowREQUEST_ SCRIPT ->getRequest Script () TYPO3_is nowREQUEST_ DIR ->getRequest Dir () TYPO3_is nowSITE_ URL ->getSite Url () TYPO3_is nowSITE_ PATH ->getSite Path () TYPO3_is nowSITE_ SCRIPT ->getSite Script () TYPO3_is nowSSL ->isHttps ()
Some further old
get arguments directly access
$request->server and do not apply any
normalization. These have been transferred to the new class, too, but will be deprecated later if the core does not use
these anymore:
PATH_is nowINFO ->get, but better usePath Info () ->getinsteadScript Name () HTTP_is nowREFERER ->get, but better useHttp Referer () $request->getinsteadServer Params () ['HTTP_ REFERER'] HTTP_is nowUSER_ AGENT ->get, but better useHttp User Agent () $request->getinsteadServer Params () ['HTTP_ USER_ AGENT'] HTTP_is nowACCEPT_ ENCODING ->get, but better useHttp Accept Encoding () $request->getinsteadServer Params () ['HTTP_ ACCEPT_ ENCODING'] HTTP_is nowACCEPT_ LANGUAGE ->get, but better useHttp Accept Language () $request->getinsteadServer Params () ['HTTP_ ACCEPT_ LANGUAGE'] REMOTE_is nowHOST ->get, but better useRemote Host () $request->getinsteadServer Params () ['REMOTE_ HOST'] QUERY_is nowSTRING ->get, but better useQuery String () $request->getinsteadServer Params () ['QUERY_ STRING']
Impact
The PSR-7 request objects created by TYPO3 now contain an instance of
Normalized which can
be used instead of
General to access normalized server params.