Request
in package
implements
RequestInterface
Uses
MessageTrait
PSR-7 request implementation.
Interfaces, Classes and Traits
- RequestInterface
- Representation of an outgoing, client-side request.
Table of Contents
- $headerNames : array<string|int, mixed>
- $headers : array<string|int, mixed>
- $method : string
- $protocol : string
- $requestTarget : string|null
- $stream : StreamInterface|null
- $uri : UriInterface
- __construct() : mixed
- getBody() : mixed
- getHeader() : mixed
- getHeaderLine() : mixed
- getHeaders() : mixed
- getMethod() : string
- Retrieves the HTTP method of the request.
- getProtocolVersion() : mixed
- getRequestTarget() : string
- Retrieves the message's request target.
- getUri() : UriInterface
- Retrieves the URI instance.
- hasHeader() : mixed
- withAddedHeader() : mixed
- withBody() : mixed
- withHeader() : mixed
- withMethod() : static
- Return an instance with the provided HTTP method.
- withoutHeader() : mixed
- withProtocolVersion() : mixed
- withRequestTarget() : static
- Return an instance with the specific request-target.
- withUri() : static
- Returns an instance with the provided URI.
- assertHeader() : mixed
- assertMethod() : mixed
- normalizeHeaderValue() : mixed
- setHeaders() : mixed
- trimHeaderValues() : array<string|int, string>
- Trims whitespace from the header values.
- updateHostFromUri() : mixed
Properties
$headerNames
private
array<string|int, mixed>
$headerNames
= []
$headers
private
array<string|int, mixed>
$headers
= []
$method
private
string
$method
$protocol
private
string
$protocol
= '1.1'
$requestTarget
private
string|null
$requestTarget
$stream
private
StreamInterface|null
$stream
$uri
private
UriInterface
$uri
Methods
__construct()
public
__construct(string $method, string|UriInterface $uri[, array<string|int, mixed> $headers = [] ][, string|resource|StreamInterface|null $body = null ][, string $version = '1.1' ]) : mixed
Parameters
- $method : string
-
HTTP method
- $uri : string|UriInterface
-
URI
- $headers : array<string|int, mixed> = []
-
Request headers
- $body : string|resource|StreamInterface|null = null
-
Request body
- $version : string = '1.1'
-
Protocol version
Return values
mixed —getBody()
public
getBody() : mixed
Return values
mixed —getHeader()
public
getHeader(mixed $header) : mixed
Parameters
- $header : mixed
Return values
mixed —getHeaderLine()
public
getHeaderLine(mixed $header) : mixed
Parameters
- $header : mixed
Return values
mixed —getHeaders()
public
getHeaders() : mixed
Return values
mixed —getMethod()
Retrieves the HTTP method of the request.
public
getMethod() : string
Return values
string —Returns the request method.
getProtocolVersion()
public
getProtocolVersion() : mixed
Return values
mixed —getRequestTarget()
Retrieves the message's request target.
public
getRequestTarget() : string
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 "/".
Return values
string —getUri()
Retrieves the URI instance.
public
getUri() : UriInterface
This method MUST return a UriInterface instance.
Return values
UriInterface —Returns a UriInterface instance representing the URI of the request.
hasHeader()
public
hasHeader(mixed $header) : mixed
Parameters
- $header : mixed
Return values
mixed —withAddedHeader()
public
withAddedHeader(mixed $header, mixed $value) : mixed
Parameters
- $header : mixed
- $value : mixed
Return values
mixed —withBody()
public
withBody(StreamInterface $body) : mixed
Parameters
- $body : StreamInterface
Return values
mixed —withHeader()
public
withHeader(mixed $header, mixed $value) : mixed
Parameters
- $header : mixed
- $value : mixed
Return values
mixed —withMethod()
Return an instance with the provided HTTP method.
public
withMethod(mixed $method) : static
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
- $method : mixed
-
Case-sensitive method.
Return values
static —withoutHeader()
public
withoutHeader(mixed $header) : mixed
Parameters
- $header : mixed
Return values
mixed —withProtocolVersion()
public
withProtocolVersion(mixed $version) : mixed
Parameters
- $version : mixed
Return values
mixed —withRequestTarget()
Return an instance with the specific request-target.
public
withRequestTarget(mixed $requestTarget) : static
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.
Parameters
- $requestTarget : mixed
Return values
static —withUri()
Returns an instance with the provided URI.
public
withUri(UriInterface $uri[, mixed $preserveHost = false ]) : static
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 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.
Parameters
- $uri : UriInterface
-
New request URI to use.
- $preserveHost : mixed = false
-
Preserve the original state of the Host header.
Return values
static —assertHeader()
private
assertHeader(mixed $header) : mixed
Parameters
- $header : mixed
Return values
mixed —assertMethod()
private
assertMethod(mixed $method) : mixed
Parameters
- $method : mixed
Return values
mixed —normalizeHeaderValue()
private
normalizeHeaderValue(mixed $value) : mixed
Parameters
- $value : mixed
Return values
mixed —setHeaders()
private
setHeaders(array<string|int, mixed> $headers) : mixed
Parameters
- $headers : array<string|int, mixed>
Return values
mixed —trimHeaderValues()
Trims whitespace from the header values.
private
trimHeaderValues(array<string|int, string> $values) : array<string|int, string>
Spaces and tabs ought to be excluded by parsers when extracting the field value from a header field.
header-field = field-name ":" OWS field-value OWS OWS = *( SP / HTAB )
Parameters
- $values : array<string|int, string>
-
Header values
Tags
Return values
array<string|int, string> —Trimmed header values
updateHostFromUri()
private
updateHostFromUri() : mixed