AbstractMessage
in package
implements
MessageInterface
AbstractMessage Class
This class represents an abstract HTTP message base class (PSR-7). It implements the MessageInterface.
Interfaces, Classes and Traits
- MessageInterface
- HTTP messages consist of requests from a client to a server and responses from a server to a client. This interface defines the methods common to each.
Table of Contents
- $headers : array<string|int, mixed>
- $protocol : string
- $stream : StreamInterface
- __construct() : mixed
- Initializes the class.
- getBody() : StreamInterface
- Get the body of the message.
- getHeader() : array<string|int, string>
- Get the specified header as an array.
- getHeaderLine() : string
- Get the specified header as a string.
- getHeaders() : array<string|int, mixed>
- Get all the headers.
- getProtocolVersion() : string
- Get the protocol version of the message.
- hasHeader() : bool
- Check if a header exists.
- withAddedHeader() : static
- Add a new header.
- withBody() : static
- Set the message body.
- withHeader() : static
- Set a header, replacing any existing values.
- withHeaders() : static
- Set multiple headers, replacing any existing values.
- withoutHeader() : static
- Remove a header.
- withProtocolVersion() : static
- Set the protocol version of the message.
- filterHeader() : mixed
- Check the validity of a header.
- getRequestHeaders() : array<string|int, mixed>
- Function to retrieve HTTP headers.
Properties
$headers
protected
array<string|int, mixed>
$headers
= []
The headers of the message.
$protocol
protected
string
$protocol
= '1.1'
The protocol version of the message.
$stream
protected
StreamInterface
$stream
The body of the message.
Methods
__construct()
Initializes the class.
public
__construct([bool $withHeader = false ]) : mixed
Parameters
- $withHeader : bool = false
-
Whether to include the HTTP header or not. Default is false.
Return values
mixed —getBody()
Get the body of the message.
public
getBody() : StreamInterface
Return values
StreamInterface —The message body.
getHeader()
Get the specified header as an array.
public
getHeader(string $name) : array<string|int, string>
Parameters
- $name : string
-
The name of the header.
Return values
array<string|int, string> —The values of the header as an array, or an empty array if not found.
getHeaderLine()
Get the specified header as a string.
public
getHeaderLine(string $name) : string
Parameters
- $name : string
-
The name of the header.
Return values
string —The concatenated values of the header, separated by commas, or an empty string if not found.
getHeaders()
Get all the headers.
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —The headers of the message.
getProtocolVersion()
Get the protocol version of the message.
public
getProtocolVersion() : string
Return values
string —The protocol version.
hasHeader()
Check if a header exists.
public
hasHeader(string $name) : bool
Parameters
- $name : string
-
The name of the header.
Return values
bool —True if the header exists, false otherwise.
withAddedHeader()
Add a new header.
public
withAddedHeader(string $name, string|array<string|int, string> $value) : static
Parameters
- $name : string
-
The name of the header.
- $value : string|array<string|int, string>
-
The value(s) of the header as a string or an array of strings.
Tags
Return values
static —withBody()
Set the message body.
public
withBody(StreamInterface $body) : static
Parameters
- $body : StreamInterface
-
The message body.
Return values
static —withHeader()
Set a header, replacing any existing values.
public
withHeader(string $name, string|array<string|int, string> $value) : static
Parameters
- $name : string
-
The name of the header.
- $value : string|array<string|int, string>
-
The value(s) of the header as a string or an array of strings.
Tags
Return values
static —withHeaders()
Set multiple headers, replacing any existing values.
public
withHeaders(array<string|int, mixed> $headers) : static
Parameters
- $headers : array<string|int, mixed>
-
An array of headers in the format: array($key => $value, $key => $value...)
Tags
Return values
static —withoutHeader()
Remove a header.
public
withoutHeader(string $name) : static
Parameters
- $name : string
-
The name of the header to remove.
Return values
static —withProtocolVersion()
Set the protocol version of the message.
public
withProtocolVersion(string $version) : static
Parameters
- $version : string
-
The protocol version (e.g., 1.1, 1.0).
Return values
static —filterHeader()
Check the validity of a header.
protected
filterHeader(string $name) : mixed
Parameters
- $name : string
-
The name of the header.
Tags
Return values
mixed —getRequestHeaders()
Function to retrieve HTTP headers.
protected
getRequestHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of HTTP headers.