TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Request Class Reference
Inheritance diagram for Request:
Message ServerRequest

Public Member Functions

 __construct ($uri=null, $method=null, $body= 'php://input', array $headers=[])
 
 getHeaders ()
 
 getHeader ($header)
 
 getRequestTarget ()
 
 withRequestTarget ($requestTarget)
 
 getMethod ()
 
 withMethod ($method)
 
 getUri ()
 
 withUri (UriInterface $uri, $preserveHost=false)
 
- Public Member Functions inherited from Message
 getProtocolVersion ()
 
 withProtocolVersion ($version)
 
 getHeaders ()
 
 hasHeader ($name)
 
 getHeader ($name)
 
 getHeaderLine ($name)
 
 withHeader ($name, $value)
 
 withAddedHeader ($name, $value)
 
 withoutHeader ($name)
 
 getBody ()
 
 withBody (StreamInterface $body)
 
 filter ($value)
 
 validateHeaderName ($name)
 
 isValidHeaderValue ($value)
 

Protected Member Functions

 getHostFromUri ()
 
 validateMethod ($method)
 
- Protected Member Functions inherited from Message
 assertHeaders (array $headers)
 
 filterHeaders (array $originalHeaders)
 
 arrayContainsOnlyStrings (array $data)
 
 validateHeaderValues (array $values)
 

Protected Attributes

 $requestTarget
 
 $method
 
 $supportedMethods
 
 $uri
 
- Protected Attributes inherited from Message
 $protocolVersion = '1.1'
 
 $headers = []
 
 $lowercasedHeaderNames = []
 
 $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/

Definition at line 31 of file core/Classes/Http/Request.php.

Constructor & Destructor Documentation

__construct (   $uri = null,
  $method = null,
  $body = 'php://input',
array  $headers = [] 
)

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

Parameters
NULL | string$uriURI for the request, if any.
NULL | string$methodHTTP method for the request, if any.
string | resource | StreamInterface$bodyMessage body, if any.
array$headersHeaders for the message, if any.
Exceptions
InvalidArgumentException for any invalid value.

Definition at line 86 of file core/Classes/Http/Request.php.

References Message\$body, Message\$headers, Request\$method, Request\$uri, Message\assertHeaders(), Message\filterHeaders(), and Request\validateMethod().

Member Function Documentation

getHeader (   $header)

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$nameCase-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.

Definition at line 164 of file core/Classes/Http/Request.php.

References Request\getHostFromUri(), and Message\hasHeader().

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.

Definition at line 141 of file core/Classes/Http/Request.php.

References Message\$headers, Request\getHostFromUri(), and Message\hasHeader().

getHostFromUri ( )
protected

Retrieve the host from the URI instance

Returns
string

Definition at line 177 of file core/Classes/Http/Request.php.

Referenced by Request\getHeader(), and Request\getHeaders().

getMethod ( )

Retrieves the HTTP method of the request, defaults to GET

Returns
string Returns the request method.

Definition at line 253 of file core/Classes/Http/Request.php.

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 "/".

Returns
string

Definition at line 200 of file core/Classes/Http/Request.php.

References Request\$requestTarget.

getUri ( )

Retrieves the URI instance.

This method MUST return a UriInterface instance.

Returns a UriInterface instance representing the URI of the request.

Definition at line 289 of file core/Classes/Http/Request.php.

References Request\$uri.

validateMethod (   $method)
protected

Validate the HTTP method, helper function.

Parameters
NULL | string$method
Exceptions
InvalidArgumentException on invalid HTTP method.

Definition at line 355 of file core/Classes/Http/Request.php.

References Request\$method.

Referenced by Request\__construct().

withMethod (   $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$methodCase-sensitive method.
Returns
Request
Exceptions
InvalidArgumentException for invalid HTTP methods.

Definition at line 273 of file core/Classes/Http/Request.php.

References Request\$method.

withRequestTarget (   $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) mixed $requestTarget Request

Definition at line 238 of file core/Classes/Http/Request.php.

References Request\$requestTarget.

withUri ( UriInterface  $uri,
  $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.

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

Definition at line 325 of file core/Classes/Http/Request.php.

References Request\$uri.

Member Data Documentation

$requestTarget
protected
$supportedMethods
protected
Initial value:
= [
'CONNECT',
'DELETE',
'GET',
'HEAD',
'OPTIONS',
'PATCH',
'POST',
'PUT',
'TRACE',
'COPY',
'LOCK',
'MKCOL',
'MOVE',
'PROPFIND',
'PROPPATCH',
'UNLOCK'
]

Definition at line 51 of file core/Classes/Http/Request.php.