OutgoingRequest
extends Message
in package
implements
OutgoingRequestInterface
Representation of an outgoing, client-side request.
Tags
Table of Contents
Interfaces
- OutgoingRequestInterface
- Representation of an outgoing, client-side request.
Properties
- $body : string|null
- Message body
- $headerMap : array<string|int, mixed>
- Holds a map of lower-case header names and their normal-case key as it is in $headers.
- $headers : array<string, Header|array<int, Header>>
- List of all HTTP request headers.
- $method : string
- Request method.
- $protocolVersion : string
- Protocol version
- $uri : URI|null
- A URI instance.
- $validProtocolVersions : array<string|int, mixed>
- List of valid protocol versions
Methods
- __construct() : mixed
- addHeader() : $this
- Adds a header (not a header value) with the same name.
- appendBody() : $this
- Appends data to the body of the current message.
- appendHeader() : $this
- Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
- getBody() : string|null
- Returns the Message's body.
- getHeader() : array<string|int, mixed>|Header|null
- Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects.
- getHeaderLine() : string
- Retrieves a comma-separated string of the values for a single header.
- getHeaders() : array<string, Header>
- Returns an array containing all headers.
- getMethod() : string
- Retrieves the HTTP method of the request.
- getProtocolVersion() : string
- Returns the HTTP Protocol Version.
- getUri() : URI|null
- Retrieves the URI instance.
- hasHeader() : bool
- Determines whether a header exists.
- header() : Header|array<int, Header>|null
- Returns a single Header object. If multiple headers with the same name exist, then will return an array of header objects.
- headers() : array<string, Header|array<int, Header>>
- Returns an array containing all Headers.
- populateHeaders() : void
- Populates the $headers array with any headers the server knows about.
- prependHeader() : $this
- Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
- removeHeader() : $this
- Removes a header from the list of headers we track.
- setBody() : $this
- Sets the body of the current message.
- setHeader() : $this
- Sets a header and it's value.
- setMethod() : $this
- Sets the request method. Used when spoofing the request.
- setProtocolVersion() : $this
- Sets the HTTP protocol version.
- withMethod() : static
- Returns an instance with the specified method.
- withUri() : static
- Returns an instance with the provided URI.
- getHeaderName() : string
- Takes a header name in any case, and returns the normal-case version of the header.
- checkMultipleHeaders() : void
- getHostFromUri() : string
- hasMultipleHeaders() : bool
- isHostHeaderMissingOrEmpty() : bool
Properties
$body
Message body
protected
string|null
$body
$headerMap
Holds a map of lower-case header names and their normal-case key as it is in $headers.
protected
array<string|int, mixed>
$headerMap
= []
Used for case-insensitive header access.
$headers
List of all HTTP request headers.
protected
array<string, Header|array<int, Header>>
$headers
= []
[name => Header] or [name => [Header1, Header2]]
$method
Request method.
protected
string
$method
$protocolVersion
Protocol version
protected
string
$protocolVersion
$uri
A URI instance.
protected
URI|null
$uri
$validProtocolVersions
List of valid protocol versions
protected
array<string|int, mixed>
$validProtocolVersions
= ['1.0', '1.1', '2.0', '3.0']
Methods
__construct()
public
__construct(string $method[, URI|null $uri = null ][, array<string|int, mixed> $headers = [] ][, string|null $body = null ][, string $version = '1.1' ]) : mixed
Parameters
- $method : string
-
HTTP method
- $uri : URI|null = null
- $headers : array<string|int, mixed> = []
- $body : string|null = null
- $version : string = '1.1'
addHeader()
Adds a header (not a header value) with the same name.
public
addHeader(string $name, string $value) : $this
Use this only when you set multiple headers with the same name,
typically, for Set-Cookie
.
Parameters
- $name : string
- $value : string
Return values
$thisappendBody()
Appends data to the body of the current message.
public
appendBody(string $data) : $this
Parameters
- $data : string
Return values
$thisappendHeader()
Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
public
appendHeader(string $name, string|null $value) : $this
Parameters
- $name : string
- $value : string|null
Return values
$thisgetBody()
Returns the Message's body.
public
getBody() : string|null
Return values
string|nullgetHeader()
Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects.
public
getHeader(string $name) : array<string|int, mixed>|Header|null
Use Message::header() to make room for PSR-7
Parameters
- $name : string
Tags
Return values
array<string|int, mixed>|Header|nullgetHeaderLine()
Retrieves a comma-separated string of the values for a single header.
public
getHeaderLine(string $name) : string
This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.
NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.
Parameters
- $name : string
Return values
stringgetHeaders()
Returns an array containing all headers.
public
getHeaders() : array<string, Header>
Use Message::headers() to make room for PSR-7
Tags
Return values
array<string, Header> —An array of the request headers
getMethod()
Retrieves the HTTP method of the request.
public
getMethod() : string
Return values
string —Returns the request method (always uppercase)
getProtocolVersion()
Returns the HTTP Protocol Version.
public
getProtocolVersion() : string
Return values
string —HTTP protocol version.
getUri()
Retrieves the URI instance.
public
getUri() : URI|null
Return values
URI|nullhasHeader()
Determines whether a header exists.
public
hasHeader(string $name) : bool
Parameters
- $name : string
-
Case-insensitive header field name.
Return values
bool —Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
header()
Returns a single Header object. If multiple headers with the same name exist, then will return an array of header objects.
public
header(string $name) : Header|array<int, Header>|null
Parameters
- $name : string
Return values
Header|array<int, Header>|nullheaders()
Returns an array containing all Headers.
public
headers() : array<string, Header|array<int, Header>>
Return values
array<string, Header|array<int, Header>> —An array of the Header objects
populateHeaders()
Populates the $headers array with any headers the server knows about.
public
populateHeaders() : void
prependHeader()
Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
public
prependHeader(string $name, string $value) : $this
Parameters
- $name : string
- $value : string
Return values
$thisremoveHeader()
Removes a header from the list of headers we track.
public
removeHeader(string $name) : $this
Parameters
- $name : string
Return values
$thissetBody()
Sets the body of the current message.
public
setBody(string $data) : $this
Parameters
- $data : string
Return values
$thissetHeader()
Sets a header and it's value.
public
setHeader(string $name, array<string|int, mixed>|string|null $value) : $this
Parameters
- $name : string
- $value : array<string|int, mixed>|string|null
Return values
$thissetMethod()
Sets the request method. Used when spoofing the request.
public
setMethod(string $method) : $this
Use withMethod() instead for immutability
Parameters
- $method : string
Return values
$thissetProtocolVersion()
Sets the HTTP protocol version.
public
setProtocolVersion(string $version) : $this
Parameters
- $version : string
Tags
Return values
$thiswithMethod()
Returns an instance with the specified method.
public
withMethod(string $method) : static
Parameters
- $method : string
Return values
staticwithUri()
Returns an instance with the provided URI.
public
withUri(URI $uri[, bool $preserveHost = false ]) : static
Parameters
- $uri : URI
-
New request URI to use.
- $preserveHost : bool = false
-
Preserve the original state of the Host header.
Return values
staticgetHeaderName()
Takes a header name in any case, and returns the normal-case version of the header.
protected
getHeaderName(string $name) : string
Parameters
- $name : string
Return values
stringcheckMultipleHeaders()
private
checkMultipleHeaders(string $name) : void
Parameters
- $name : string
getHostFromUri()
private
getHostFromUri(URI $uri) : string
Parameters
- $uri : URI
Return values
stringhasMultipleHeaders()
private
hasMultipleHeaders(string $name) : bool
Parameters
- $name : string
Return values
boolisHostHeaderMissingOrEmpty()
private
isHostHeaderMissingOrEmpty() : bool