MessageInterface
in
Expected behavior of an HTTP message
Table of Contents
Methods
- 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
- Gets the body of the message.
- getHeaderLine() : string
- Retrieves a comma-separated string of the values for a single header.
- getProtocolVersion() : string
- Retrieves the HTTP protocol version as a string.
- hasHeader() : bool
- Checks if a header exists by the given case-insensitive name.
- 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.
- setProtocolVersion() : $this
- Sets the HTTP protocol version.
Methods
appendBody()
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()
Gets the body of the message.
public
getBody() : string|null
Tags
Return values
string|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
stringgetProtocolVersion()
Retrieves the HTTP protocol version as a string.
public
getProtocolVersion() : string
The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
Return values
string —HTTP protocol version.
hasHeader()
Checks if a header exists by the given case-insensitive name.
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
$thissetProtocolVersion()
Sets the HTTP protocol version.
public
setProtocolVersion(string $version) : $this
Parameters
- $version : string