‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Http\ServerRequest Class Reference
Inheritance diagram for TYPO3\CMS\Core\Http\ServerRequest:
TYPO3\CMS\Core\Http\Request TYPO3\CMS\Core\Http\Message

Public Member Functions

 __construct (string|UriInterface|null $uri=null, $method=null, $body='php://input', array $headers=[], array $serverParams=[], array $uploadedFiles=null)
 
 getServerParams ()
 
 getCookieParams ()
 
 getQueryParams ()
 
array getUploadedFiles ()
 
array object null getParsedBody ()
 
array getAttributes ()
 
mixed getAttribute (string $name, $default=null)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Http\Request
 __construct (UriInterface|string|null $uri=null, string $method='GET', $body='php://input', array $headers=[])
 
array getHeaders ()
 
string[] getHeader (string $name)
 
 getRequestTarget ()
 
 withRequestTarget (mixed $requestTarget)
 
 getMethod ()
 
 withMethod (string $method)
 
UriInterface getUri ()
 
 withUri (UriInterface $uri, bool $preserveHost=false)
 
- ‪Public Member Functions inherited from ‪TYPO3\CMS\Core\Http\Message
string getProtocolVersion ()
 
bool hasHeader (string $name)
 
string getHeaderLine (string $name)
 
StreamInterface getBody ()
 
 filter (string $value)
 
 validateHeaderName (string $name)
 
 isValidHeaderValue (string $value)
 

Static Public Member Functions

static withCookieParams (array $cookies)
 
static withQueryParams (array $query)
 
static withUploadedFiles (array $uploadedFiles)
 
static withParsedBody ($data)
 
static withAttribute (string $name, $value)
 
static withoutAttribute (string $name)
 
- ‪Static Public Member Functions inherited from ‪TYPO3\CMS\Core\Http\Message
static withProtocolVersion (string $version)
 
static withHeader (string $name, $value)
 
static withAddedHeader (string $name, $value)
 
static withoutHeader (string $name)
 
static withBody (StreamInterface $body)
 

Protected Member Functions

 validateUploadedFiles (array $uploadedFiles)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Core\Http\Request
 getHostFromUri ()
 
 validateMethod (?string $method)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Core\Http\Message
 assertHeaders (array $headers)
 
array filterHeaders (array $originalHeaders)
 
 arrayContainsOnlyStrings (array $data)
 
 validateHeaderValues (array $values)
 

Protected Attributes

array $attributes = []
 
array $cookieParams = []
 
array $queryParams = []
 
array $serverParams = []
 
array $uploadedFiles = []
 
array object null $parsedBody
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Core\Http\Request
string $requestTarget = null
 
string $method = 'GET'
 
array $supportedMethods
 
UriInterface $uri
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Core\Http\Message
string $protocolVersion = '1.1'
 
array $headers = []
 
array $lowercasedHeaderNames = []
 
StreamInterface $body = null
 

Detailed Description

Represents a typical request incoming from the server to be processed by the TYPO3 Core. The original request is built from the ServerRequestFactory inside TYPO3's Bootstrap.

Note that the PSR-7 standard works with immutable value objects, meaning that any modification to a Request object using the "with" methods will result in a new Request object.

Highly inspired by https://github.com/phly/http/

Note that this is not public API yet.

Definition at line 38 of file ServerRequest.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Http\ServerRequest::__construct ( string|UriInterface|null  $uri = null,
  $method = null,
  $body = 'php://input',
array  $headers = [],
array  $serverParams = [],
array  $uploadedFiles = null 
)

Constructor, the only place to set all parameters of this Message/Request

Parameters
string | UriInterface | null$uri‪URI for the request, if any.
string | null$method‪HTTP method for the request, if any.
string | resource | StreamInterface | null$bodyMessage body, if any.
array$headers‪Headers for the message, if any.
array$serverParams‪Server parameters, typically from $_SERVER
array | null$uploadedFiles‪Upload file information, a tree of UploadedFiles
Exceptions

Definition at line 61 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\Message\$body, TYPO3\CMS\Core\Http\Message\$headers, TYPO3\CMS\Core\Http\Request\$method, TYPO3\CMS\Core\Http\ServerRequest\$serverParams, TYPO3\CMS\Core\Http\ServerRequest\$uploadedFiles, TYPO3\CMS\Core\Http\Request\$uri, and TYPO3\CMS\Core\Http\ServerRequest\validateUploadedFiles().

Member Function Documentation

◆ getAttribute()

mixed TYPO3\CMS\Core\Http\ServerRequest::getAttribute ( string  $name,
  $default = null 
)

Retrieve a single derived request attribute.

Retrieves a single derived request attribute as described in getAttributes(). If the attribute has not been previously set, returns the default value as provided.

This method obviates the need for a hasAttribute() method, as it allows specifying a default value to return if the attribute is not found.

See also
getAttributes()
Parameters
string$name‪The attribute name.
mixed$default‪Default value to return if the attribute does not exist.
Returns
‪mixed

Definition at line 289 of file ServerRequest.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withAttributeMutatorReturnsCloneWithChanges().

◆ getAttributes()

array TYPO3\CMS\Core\Http\ServerRequest::getAttributes ( )

Retrieve attributes derived from the request.

The request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.

Returns
‪array Attributes derived from the request.

Definition at line 268 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$attributes.

◆ getCookieParams()

TYPO3\CMS\Core\Http\ServerRequest::getCookieParams ( )

Retrieve cookies.

Retrieves cookies sent by the client to the server.

The data MUST be compatible with the structure of the $_COOKIE super global.

Definition at line 93 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$cookieParams.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withCookieParamsMutatorReturnsCloneWithChanges().

◆ getParsedBody()

array object null TYPO3\CMS\Core\Http\ServerRequest::getParsedBody ( )

Retrieve any parameters provided in the request body.

If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, this method MUST return the contents of $_POST.

Otherwise, this method may return any results of deserializing the request body content; as parsing returns structured content, the potential types MUST be arrays or objects only. A null value indicates the absence of body content.

Returns
‪array|object|null The deserialized body parameters, if any. These will typically be an array or object.

Definition at line 217 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$parsedBody.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withParsedBodyMutatorReturnsCloneWithChanges().

◆ getQueryParams()

TYPO3\CMS\Core\Http\ServerRequest::getQueryParams ( )

Retrieve query string arguments.

Retrieves the deserialized query string arguments, if any.

Note: the query params might not be in sync with the URI or server params. If you need to ensure you are only getting the original values, you may need to parse the query string from getUri()->getQuery() or from the QUERY_STRING server param.

Definition at line 132 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$queryParams.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withQueryParamsMutatorReturnsCloneWithChanges().

◆ getServerParams()

TYPO3\CMS\Core\Http\ServerRequest::getServerParams ( )

Retrieve server parameters.

Retrieves data related to the incoming request environment, typically derived from PHP's $_SERVER superglobal. The data IS NOT REQUIRED to originate from $_SERVER.

Definition at line 80 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$serverParams.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\constructorUsesProvidedArguments().

◆ getUploadedFiles()

array TYPO3\CMS\Core\Http\ServerRequest::getUploadedFiles ( )

Retrieve normalized file upload data.

This method returns upload metadata in a normalized tree, with each leaf an instance of Psr\Http\Message\UploadedFileInterface.

These values MAY be prepared from $_FILES or the message body during instantiation, or MAY be injected via withUploadedFiles().

Returns
‪array An array tree of UploadedFileInterface instances; an empty array MUST be returned if no data is present.

Definition at line 178 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$uploadedFiles.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\constructorUsesProvidedArguments(), TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestFactoryTest\uploadedFilesAreNormalizedFromFilesSuperGlobal(), TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestFactoryTest\uploadedFilesAreNotCreatedForEmptyFilesArray(), and TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestFactoryTest\uploadedFilesAreNotCreatedIfTmpNameIsEmpty().

◆ validateUploadedFiles()

TYPO3\CMS\Core\Http\ServerRequest::validateUploadedFiles ( array  $uploadedFiles)
protected

Recursively validate the structure in an uploaded files array.

Exceptions

Definition at line 347 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$uploadedFiles.

Referenced by TYPO3\CMS\Core\Http\ServerRequest\__construct(), and TYPO3\CMS\Core\Http\ServerRequest\withUploadedFiles().

◆ withAttribute()

static TYPO3\CMS\Core\Http\ServerRequest::withAttribute ( string  $name,
  $value 
)
static

Return an instance with the specified derived request attribute.

This method allows setting a single derived request attribute as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated attribute.

See also
getAttributes()
Parameters
string$name‪The attribute name.
mixed$value‪The value of the attribute.
Returns
‪static

Definition at line 310 of file ServerRequest.php.

Referenced by TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestAddsFormOnInteractionViewsTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestAddsInformationAboutMfaBeingRequiredAndRecommendedTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestFallsBackToOverviewActionIfNoActionGivenTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestForwardsToCorrectActionTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestIndicatesDefaultProviderTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestRedirectsToOverviewOnActionProviderMismatchTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestRespectsReturnUrlTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestReturnsBadRequestForInvalidActionTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaConfigurationControllerTest\handleRequestShowsAllRegisteredProvidersTest(), TYPO3\CMS\Extbase\Tests\Functional\Mvc\Web\RequestBuilderTest\multipleUploadedFileCanBeRetrievedFromRequest(), TYPO3\CMS\Extbase\Tests\Functional\Mvc\Web\RequestBuilderTest\uploadedFileCanBeRetrievedFromRequest(), and TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withAttributeMutatorReturnsCloneWithChanges().

◆ withCookieParams()

static TYPO3\CMS\Core\Http\ServerRequest::withCookieParams ( array  $cookies)
static

Return an instance with the specified cookies.

The data IS NOT REQUIRED to come from the $_COOKIE superglobal, but MUST be compatible with the structure of $_COOKIE. Typically, this data will be injected at instantiation.

This method MUST NOT update the related Cookie header of the request instance, nor related values in the server params.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated cookie values.

Parameters
array$cookies‪Array of key/value pairs representing cookies.
Returns
‪static

Definition at line 115 of file ServerRequest.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withCookieParamsMutatorReturnsCloneWithChanges().

◆ withoutAttribute()

static TYPO3\CMS\Core\Http\ServerRequest::withoutAttribute ( string  $name)
static

Return an instance that removes the specified derived request attribute.

This method allows removing a single derived request attribute as described in getAttributes().

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the attribute.

See also
getAttributes()
Parameters
string$name‪The attribute name.
Returns
‪static

Definition at line 332 of file ServerRequest.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withoutAttributeReturnsCloneWithoutAttribute().

◆ withParsedBody()

static TYPO3\CMS\Core\Http\ServerRequest::withParsedBody (   $data)
static

Return an instance with the specified body parameters.

These MAY be injected during instantiation.

If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, use this method ONLY to inject the contents of $_POST.

The data IS NOT REQUIRED to come from $_POST, but MUST be the results of deserializing the request body content. Deserialization/parsing returns structured data, and, as such, this method ONLY accepts arrays or objects, or a null value if nothing was available to parse.

As an example, if content negotiation determines that the request data is a JSON payload, this method could be used to create a request instance with the deserialized parameters.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated body parameters.

Parameters
array | object | null$data‪The deserialized body data. This will typically be in an array or object.
Returns
‪static
Exceptions

Definition at line 250 of file ServerRequest.php.

Referenced by TYPO3\CMS\Backend\Tests\Functional\Controller\ShortcutControllerTest\addShortcutTest(), and TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withParsedBodyMutatorReturnsCloneWithChanges().

◆ withQueryParams()

static TYPO3\CMS\Core\Http\ServerRequest::withQueryParams ( array  $query)
static

Return an instance with the specified query string arguments.

These values SHOULD remain immutable over the course of the incoming request. They MAY be injected during instantiation, such as from PHP's $_GET superglobal, or MAY be derived from some other value such as the URI. In cases where the arguments are parsed from the URI, the data MUST be compatible with what PHP's parse_str() would return for purposes of how duplicate query parameters are handled, and how nested sets are handled.

Setting query string arguments MUST NOT change the URI stored by the request, nor the values in the server params.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated query string arguments.

Parameters
array$query‪Array of query string arguments, typically from $_GET.
Returns
‪static

Definition at line 159 of file ServerRequest.php.

Referenced by TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestAddsRedirectParameters(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestCancelsSetup(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestRedirectsToAuthViewOnUnsuccessfulAuthenticationTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestRedirectsToLoginOnCancelTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestRedirectsToLoginOnInvalidRequestTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestRedirectsToLoginOnLockedProviderRequestTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestReturns404OnInvalidAction(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestReturns404OnWrongHttpMethod(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestReturnsAlternativeProvidersInAuthViewTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestReturnsAuthViewTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestReturnsLockedAuthViewTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestReturnsSetupView(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestSetsSessionKeyOnSuccessfulAuthenticationTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestThrowsExceptionOnInactiveProviderTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestThrowsExceptionOnInvalidActionTest(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaControllerTest\handleRequestThrowsExceptionOnMissingProviderTest(), and TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\withQueryParamsMutatorReturnsCloneWithChanges().

◆ withUploadedFiles()

static TYPO3\CMS\Core\Http\ServerRequest::withUploadedFiles ( array  $uploadedFiles)
static

Create a new instance with the specified uploaded files.

This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated body parameters.

Parameters
array$uploadedFiles‪An array tree of UploadedFileInterface instances.
Returns
‪static
Exceptions

Definition at line 194 of file ServerRequest.php.

References TYPO3\CMS\Core\Http\ServerRequest\$uploadedFiles, and TYPO3\CMS\Core\Http\ServerRequest\validateUploadedFiles().

Member Data Documentation

◆ $attributes

array TYPO3\CMS\Core\Http\ServerRequest::$attributes = []
protected

Definition at line 40 of file ServerRequest.php.

Referenced by TYPO3\CMS\Core\Http\ServerRequest\getAttributes().

◆ $cookieParams

array TYPO3\CMS\Core\Http\ServerRequest::$cookieParams = []
protected

Definition at line 41 of file ServerRequest.php.

Referenced by TYPO3\CMS\Core\Http\ServerRequest\getCookieParams().

◆ $parsedBody

array object null TYPO3\CMS\Core\Http\ServerRequest::$parsedBody
protected

Definition at line 48 of file ServerRequest.php.

Referenced by TYPO3\CMS\Core\Http\ServerRequest\getParsedBody().

◆ $queryParams

array TYPO3\CMS\Core\Http\ServerRequest::$queryParams = []
protected

Definition at line 42 of file ServerRequest.php.

Referenced by TYPO3\CMS\Core\Http\ServerRequest\getQueryParams().

◆ $serverParams

array TYPO3\CMS\Core\Http\ServerRequest::$serverParams = []
protected

◆ $uploadedFiles