Menu

## Message extends AbstractMessage
in package

Message.php : 18

HTTP messages class (PSR-7)

##### Tags

see
  https://www.kotchasan.com/

### 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

AbstractMessage.php : 29
`protected array<string|int, mixed> $headers = []`

The headers of the message.

#### $protocol

AbstractMessage.php : 34
`protected string $protocol = '1.1'`

The protocol version of the message.

#### $stream

AbstractMessage.php : 39
`protected StreamInterface $stream`

The body of the message.

### Methods

#### __construct()

AbstractMessage.php : 46

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()

AbstractMessage.php : 58

Get the body of the message.

`public getBody() : StreamInterface`

##### Return values

StreamInterface —

The message body.

#### getHeader()

AbstractMessage.php : 70

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()

AbstractMessage.php : 82

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()

AbstractMessage.php : 93

Get all the headers.

`public getHeaders() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

The headers of the message.

#### getProtocolVersion()

AbstractMessage.php : 103

Get the protocol version of the message.

`public getProtocolVersion() : string`

##### Return values

string —

The protocol version.

#### hasHeader()

AbstractMessage.php : 115

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()

AbstractMessage.php : 130

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

throws
  InvalidArgumentException

  If the header name is invalid.

##### Return values

static —

#### withBody()

AbstractMessage.php : 151

Set the message body.

`public withBody(StreamInterface $body) : static`

##### Parameters

$body : StreamInterface

  The message body.

##### Return values

static —

#### withHeader()

AbstractMessage.php : 168

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

throws
  InvalidArgumentException

  for invalid header names or values.

##### Return values

static —

#### withHeaders()

AbstractMessage.php : 185

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

throws
  InvalidArgumentException

  for invalid header names or values.

##### Return values

static —

#### withoutHeader()

AbstractMessage.php : 216

Remove a header.

`public withoutHeader(string $name) : static`

##### Parameters

$name : string

  The name of the header to remove.

##### Return values

static —

#### withProtocolVersion()

AbstractMessage.php : 202

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()

AbstractMessage.php : 230

Check the validity of a header.

`protected filterHeader(string $name) : mixed`

##### Parameters

$name : string

  The name of the header.

##### Tags

throws
  InvalidArgumentException

  If the header is invalid.

##### Return values

mixed —

#### getRequestHeaders()

AbstractMessage.php : 242

Function to retrieve HTTP headers.

`protected getRequestHeaders() : array<string|int, mixed>`

##### Return values

array<string|int, mixed> —

An array of HTTP headers.

## Search results