Menu

## Response extends Message
in package
implements ResponseInterface

Response.php : 23

Represents an HTTP response.

This class extends the Message class and implements the ResponseInterface. It provides methods to handle and manipulate HTTP responses.

##### Tags

see
  https://www.kotchasan.com/

### Interfaces, Classes and Traits

ResponseInterface
  Representation of an outgoing, server-side response.

### Table of Contents

$statusTexts : array<string|int, mixed>
  Status codes and their corresponding text phrases.
$content : string
  The response content.
$headers : array<string|int, mixed>
$protocol : string
$reasonPhrase : string
  The reason phrase associated with the status code.
$statusCode : int
  The status code of the response.
$stream : StreamInterface
__construct() : mixed
  Create a new Response instance.
getBody() : StreamInterface
  Get the body of the message.
getContent() : string
  Get the content of the response.
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.
getReasonPhrase() : string
  Get the reason phrase associated with the status code.
getStatusCode() : int
  Get the status code of the response.
hasHeader() : bool
  Check if a header exists.
send() : Response
  Send the HTTP headers and content.
withAddedHeader() : static
  Add a new header.
withBody() : static
  Set the message body.
withContent() : Response
  Set the content of the response.
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.
withStatus() : Response
  Set the status code and reason phrase of the response.
filterHeader() : mixed
  Check the validity of a header.
getRequestHeaders() : array<string|int, mixed>
  Function to retrieve HTTP headers.
sendContent() : Response
  Send the response content.
sendHeaders() : Response
  Send the HTTP headers.

### Properties

#### $statusTexts

Response.php : 30

Status codes and their corresponding text phrases.

`public static array<string|int, mixed> $statusTexts = [ 100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', // RFC2518 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', // RFC4918 208 => 'Already Reported', // RFC5842 226 => 'IM Used', // RFC3229 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', // RFC7238 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 418 => 'I'm a teapot', // RFC2324 422 => 'Unprocessable Entity', // RFC4918 423 => 'Locked', // RFC4918 424 => 'Failed Dependency', // RFC4918 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 426 => 'Upgrade Required', // RFC2817 428 => 'Precondition Required', // RFC6585 429 => 'Too Many Requests', // RFC6585 431 => 'Request Header Fields Too Large', // RFC6585 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported', 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 507 => 'Insufficient Storage', // RFC4918 508 => 'Loop Detected', // RFC5842 510 => 'Not Extended', // RFC2774 511 => 'Network Authentication Required', ]`

#### $content

Response.php : 98

The response content.

`protected string $content`

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

#### $reasonPhrase

Response.php : 105

The reason phrase associated with the status code.

`protected string $reasonPhrase`

#### $statusCode

Response.php : 112

The status code of the response.

`protected int $statusCode`

#### $stream

AbstractMessage.php : 39
`protected StreamInterface $stream`

The body of the message.

### Methods

#### __construct()

Response.php : 120

Create a new Response instance.

`public __construct([int $code = 200 ][, string|null $reasonPhrase = null ]) : mixed`

##### Parameters

$code : int = 200

  The status code.

$reasonPhrase : string|null = null

  The reason phrase (optional).

##### Return values

mixed —

#### getBody()

AbstractMessage.php : 58

Get the body of the message.

`public getBody() : StreamInterface`

##### Return values

StreamInterface —

The message body.

#### getContent()

Response.php : 131

Get the content of the response.

`public getContent() : string`

##### Return values

string —

The response content.

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

#### getReasonPhrase()

Response.php : 144

Get the reason phrase associated with the status code.

`public getReasonPhrase() : string`

##### Tags

see
  http://tools.ietf.org/html/rfc7231#section-6
see
  http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml

##### Return values

string —

The reason phrase.

#### getStatusCode()

Response.php : 160

Get the status code of the response.

`public getStatusCode() : int`

##### Return values

int —

The status code.

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

#### send()

Response.php : 170

Send the HTTP headers and content.

`public send() : Response`

##### Return values

Response —

The Response object.

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

#### withContent()

Response.php : 186

Set the content of the response.

`public withContent(mixed $content) : Response`

##### Parameters

$content : mixed

  The response content.

##### Tags

throws
  InvalidArgumentException

  if the content is not a string.

##### Return values

Response —

The Response object.

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

#### withStatus()

Response.php : 203

Set the status code and reason phrase of the response.

`public withStatus(int $code[, string $reasonPhrase = '' ]) : Response`

##### Parameters

$code : int

  The status code.

$reasonPhrase : string = ''

  The reason phrase (optional).

##### Return values

Response —

The new Response object.

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

#### sendContent()

Response.php : 216

Send the response content.

`protected sendContent() : Response`

##### Return values

Response —

The Response object.

#### sendHeaders()

Response.php : 229

Send the HTTP headers.

`protected sendHeaders() : Response`

##### Return values

Response —

The Response object.

## Search results