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

Public Member Functions

 __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)
 

Protected Member Functions

 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

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
 

Additional Inherited Members

- ‪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)
 

Detailed Description

Default implementation for the RequestInterface of the PSR-7 standard It is the base for any request sent BY PHP.

Please see ServerRequest for the typical use cases in the framework.

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

Note that this is not public API yet.

Definition at line 34 of file Request.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

Parameters
string | UriInterface | null$uri‪URI for the request, if any.
string$method‪HTTP method for the request, if any.
string | resource | StreamInterface | null$bodyMessage body, if any.
array$headers‪Headers for the message, if any.
Exceptions

Definition at line 91 of file Request.php.

References TYPO3\CMS\Core\Http\Message\$body, TYPO3\CMS\Core\Http\Message\$headers, TYPO3\CMS\Core\Http\Message\$lowercasedHeaderNames, TYPO3\CMS\Core\Http\Request\$method, TYPO3\CMS\Core\Http\Request\$uri, TYPO3\CMS\Core\Http\Message\assertHeaders(), TYPO3\CMS\Core\Http\Message\filterHeaders(), and TYPO3\CMS\Core\Http\Request\validateMethod().

Member Function Documentation

◆ getHeader()

string [] TYPO3\CMS\Core\Http\Request::getHeader ( string  $name)

Retrieves a message header value by the given case-insensitive name.

This method returns an array of all the header values of the given case-insensitive header name.

If the header does not appear in the message, this method MUST return an empty array.

Parameters
string$name‪Case-insensitive header field name.
Returns
‪string[] An array of string values as provided for the given header. If the header does not appear in the message, this method MUST return an empty array.

Reimplemented from TYPO3\CMS\Core\Http\Message.

Definition at line 168 of file Request.php.

References TYPO3\CMS\Core\Http\Request\getHostFromUri(), and TYPO3\CMS\Core\Http\Message\hasHeader().

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderWithHostReturnsEmptyArrayIfNoUriPresent(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderWithHostReturnsEmptyArrayIfUriDoesNotContainHost(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderWithHostReturnsUriHostWhenPresent(), and TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\headerCanBeRetrieved().

◆ getHeaders()

array TYPO3\CMS\Core\Http\Request::getHeaders ( )

Retrieves all message header values.

The keys represent the header name as it will be sent over the wire, and each value is an array of strings associated with the header.

// Represent the headers as a string
foreach ($message->getHeaders() as $name => $values) {
echo $name . ": " . implode(", ", $values);
}
// Emit headers iteratively:
foreach ($message->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}

While header names are not case-sensitive, getHeaders() will preserve the exact case in which headers were originally specified.

Returns
‪array Returns an associative array of the message's headers. Each key MUST be a header name, and each value MUST be an array of strings for that header.

Reimplemented from TYPO3\CMS\Core\Http\Message.

Definition at line 145 of file Request.php.

References TYPO3\CMS\Core\Http\Message\$headers, TYPO3\CMS\Core\Http\Request\getHostFromUri(), and TYPO3\CMS\Core\Http\Message\hasHeader().

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\constructorCanAcceptAllMessageParts(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\constructorIgnoresInvalidHeaders(), TYPO3\CMS\Core\Tests\Unit\Http\ServerRequestTest\constructorUsesProvidedArguments(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeadersContainsHostHeaderIfUriWithHostIsPresent(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeadersContainsNoHostHeaderIfNoUriPresent(), and TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeadersContainsNoHostHeaderIfUriDoesNotContainHost().

◆ getHostFromUri()

TYPO3\CMS\Core\Http\Request::getHostFromUri ( )
protected

Retrieve the host from the URI instance

Definition at line 179 of file Request.php.

Referenced by TYPO3\CMS\Core\Http\Request\getHeader(), and TYPO3\CMS\Core\Http\Request\getHeaders().

◆ getMethod()

◆ getRequestTarget()

TYPO3\CMS\Core\Http\Request::getRequestTarget ( )

Retrieves the message's request target.

Retrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()).

In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below).

If no URI is available, and no request-target has been specifically provided, this method MUST return the string "/".

Definition at line 200 of file Request.php.

References TYPO3\CMS\Core\Http\Request\$requestTarget.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetCanProvideARequestTarget(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetDoesNotCacheBetweenInstances(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetIsResetWithNewUri(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetIsSlashWhenNoUriPresent(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetIsSlashWhenUriHasNoPathOrQuery(), and TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetWhenUriIsPresent().

◆ getUri()

UriInterface TYPO3\CMS\Core\Http\Request::getUri ( )

◆ validateMethod()

TYPO3\CMS\Core\Http\Request::validateMethod ( ?string  $method)
protected

Validate the HTTP method, helper function.

Exceptions

Definition at line 349 of file Request.php.

References TYPO3\CMS\Core\Http\Request\$method.

Referenced by TYPO3\CMS\Core\Http\Request\__construct().

◆ withMethod()

TYPO3\CMS\Core\Http\Request::withMethod ( string  $method)

Return an instance with the provided HTTP method.

While HTTP method names are typically all uppercase characters, HTTP method names are case-sensitive and thus implementations SHOULD NOT modify the given string.

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 changed request method.

Parameters
string$method‪Case-sensitive method.
Exceptions

Definition at line 269 of file Request.php.

References TYPO3\CMS\Core\Http\Request\$method.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getMethodMutatorReturnsCloneWithChangedMethod(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestActivatesRequestedProvider(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestRedirectsToSetupOnInvalidProvider(), TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestRedirectsToSetupOnMissingProvider(), and TYPO3\CMS\Backend\Tests\Functional\Controller\MfaSetupControllerTest\handleRequestRedirectsWithErrorOnActivationFailure().

◆ withRequestTarget()

TYPO3\CMS\Core\Http\Request::withRequestTarget ( mixed  $requestTarget)

Return an instance with the specific request-target.

If the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim.

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 changed request target.

(for the various request-target forms allowed in request messages)

Definition at line 237 of file Request.php.

References TYPO3\CMS\Core\Http\Request\$requestTarget.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\withRequestTargetCannotContainWhitespace().

◆ withUri()

TYPO3\CMS\Core\Http\Request::withUri ( UriInterface  $uri,
bool  $preserveHost = false 
)

Returns an instance with the provided URI.

This method MUST update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.

You can opt-in to preserving the original state of the Host header by setting $preserveHost to true. When $preserveHost is set to true, this method interacts with the Host header in the following ways:

  • ‪If the the Host header is missing or empty, and the new URI contains a host component, this method MUST update the Host header in the returned request.
  • ‪If the Host header is missing or empty, and the new URI does not contain a host component, this method MUST NOT update the Host header in the returned request.
  • ‪If a Host header is present and non-empty, this method MUST NOT update the Host header in the returned request.

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 new UriInterface instance.

UriInterface $uri New request URI to use. bool $preserveHost Preserve the original state of the Host header.

Definition at line 320 of file Request.php.

References TYPO3\CMS\Core\Http\Request\$uri.

Referenced by TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderLineWithHostDoesNotTakePrecedenceOverHostWithPortFromUri(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderLineWithHostTakesPrecedenceOverEmptyUri(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getHeaderLineWithHostTakesPrecedenceOverModifiedUri(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetDoesNotCacheBetweenInstances(), TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\getRequestTargetIsResetWithNewUri(), and TYPO3\CMS\Core\Tests\Unit\Http\RequestTest\withUriReturnsNewInstanceWithNewUri().

Member Data Documentation

◆ $method

◆ $requestTarget

string TYPO3\CMS\Core\Http\Request::$requestTarget = null
protected

The request-target, if it has been provided or calculated.

Definition at line 39 of file Request.php.

Referenced by TYPO3\CMS\Core\Http\Request\getRequestTarget(), and TYPO3\CMS\Core\Http\Request\withRequestTarget().

◆ $supportedMethods

array TYPO3\CMS\Core\Http\Request::$supportedMethods
protected
Initial value:
= [
'CONNECT',
'DELETE',
'GET',
'HEAD',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'TRACE',
'COPY',
'LOCK',
'MKCOL',
'MOVE',
'PROPFIND',
'PROPPATCH',
'REPORT',
'UNLOCK',
'PURGE',
'BAN',
]

Definition at line 51 of file Request.php.

◆ $uri

UriInterface TYPO3\CMS\Core\Http\Request::$uri
protected

An instance of the Uri object

Todo:
‪It is a PSR-7 spec violation for this to be null. This should be corrected.

Definition at line 80 of file Request.php.

Referenced by TYPO3\CMS\Core\Http\ServerRequest\__construct(), TYPO3\CMS\Core\Http\Request\__construct(), TYPO3\CMS\Core\Http\Request\getUri(), and TYPO3\CMS\Core\Http\Request\withUri().