Documentation

Response extends Message
in package
implements ResponseInterface, StatusCodeInterface

Implements a HTTP response message

Table of Contents

Interfaces

ResponseInterface
StatusCodeInterface

Constants

REASON_PHRASES  = [ //Informational 1xx self::STATUS_CONTINUE => 'Continue', self::STATUS_SWITCHING_PROTOCOLS => 'Switching Protocols', self::STATUS_PROCESSING => 'Processing', self::STATUS_EARLY_HINTS => 'Early Hints', //Successful 2xx self::STATUS_OK => 'OK', self::STATUS_CREATED => 'Created', self::STATUS_ACCEPTED => 'Accepted', self::STATUS_NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information', self::STATUS_NO_CONTENT => 'No Content', self::STATUS_RESET_CONTENT => 'Reset Content', self::STATUS_PARTIAL_CONTENT => 'Partial Content', self::STATUS_MULTI_STATUS => 'Multi-Status', self::STATUS_ALREADY_REPORTED => 'Already Reported', self::STATUS_IM_USED => 'IM Used', //Redirection 3xx self::STATUS_MULTIPLE_CHOICES => 'Multiple Choices', self::STATUS_MOVED_PERMANENTLY => 'Moved Permanently', self::STATUS_FOUND => 'Found', self::STATUS_SEE_OTHER => 'See Other', self::STATUS_NOT_MODIFIED => 'Not Modified', self::STATUS_USE_PROXY => 'Use Proxy', self::STATUS_RESERVED => 'Reserved', self::STATUS_TEMPORARY_REDIRECT => 'Temporary Redirect', self::STATUS_PERMANENT_REDIRECT => 'Permanent Redirect', //Client Error 4xx self::STATUS_BAD_REQUEST => 'Bad Request', self::STATUS_UNAUTHORIZED => 'Unauthorized', self::STATUS_PAYMENT_REQUIRED => 'Payment Required', self::STATUS_FORBIDDEN => 'Forbidden', self::STATUS_NOT_FOUND => 'Not Found', self::STATUS_METHOD_NOT_ALLOWED => 'Method Not Allowed', self::STATUS_NOT_ACCEPTABLE => 'Not Acceptable', self::STATUS_PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required', self::STATUS_REQUEST_TIMEOUT => 'Request Timeout', self::STATUS_CONFLICT => 'Conflict', self::STATUS_GONE => 'Gone', self::STATUS_LENGTH_REQUIRED => 'Length Required', self::STATUS_PRECONDITION_FAILED => 'Precondition Failed', self::STATUS_PAYLOAD_TOO_LARGE => 'Request Entity Too Large', self::STATUS_URI_TOO_LONG => 'Request-URI Too Long', self::STATUS_UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type', self::STATUS_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable', self::STATUS_EXPECTATION_FAILED => 'Expectation Failed', self::STATUS_IM_A_TEAPOT => 'I\'m a teapot', 420 => 'Enhance Your Calm', // https://http.cat/420 self::STATUS_MISDIRECTED_REQUEST => 'Misdirected Request', self::STATUS_UNPROCESSABLE_ENTITY => 'Unprocessable Entity', self::STATUS_LOCKED => 'Locked', self::STATUS_FAILED_DEPENDENCY => 'Failed Dependency', self::STATUS_TOO_EARLY => 'Too Early', self::STATUS_UPGRADE_REQUIRED => 'Upgrade Required', self::STATUS_PRECONDITION_REQUIRED => 'Precondition Required', self::STATUS_TOO_MANY_REQUESTS => 'Too Many Requests', self::STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large', 444 => 'Connection Closed Without Response', self::STATUS_UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons', 499 => 'Client Closed Request', //Server Error 5xx self::STATUS_INTERNAL_SERVER_ERROR => 'Internal Server Error', self::STATUS_NOT_IMPLEMENTED => 'Not Implemented', self::STATUS_BAD_GATEWAY => 'Bad Gateway', self::STATUS_SERVICE_UNAVAILABLE => 'Service Unavailable', self::STATUS_GATEWAY_TIMEOUT => 'Gateway Timeout', self::STATUS_VERSION_NOT_SUPPORTED => 'HTTP Version Not Supported', self::STATUS_VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates', self::STATUS_INSUFFICIENT_STORAGE => 'Insufficient Storage', self::STATUS_LOOP_DETECTED => 'Loop Detected', self::STATUS_NOT_EXTENDED => 'Not Extended', self::STATUS_NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required', 599 => 'Network Connect Timeout Error', ]
Status codes and reason phrases

Properties

$body  : StreamInterface
$headers  : array<string, array{name: string, value: string[]}>
$reasonPhrase  : string
$statusCode  : int
$version  : string

Methods

__construct()  : mixed
Response constructor.
getBody()  : StreamInterface
getHeader()  : array<string|int, mixed>
getHeaderLine()  : string
getHeaders()  : array<string|int, mixed>
getProtocolVersion()  : string
getReasonPhrase()  : string
getStatusCode()  : int
hasHeader()  : bool
withAddedHeader()  : static
withBody()  : static
withHeader()  : static
withoutHeader()  : static
withProtocolVersion()  : static
withStatus()  : static
checkName()  : string
checks/cleans a header name
checkValue()  : array<string|int, string>
getReasonPhraseFromStatusCode()  : string
Get the reason phrase for the given status code, returns an empty string if no matching phrase is found

Constants

REASON_PHRASES

Status codes and reason phrases

public array<int, string> REASON_PHRASES = [ //Informational 1xx self::STATUS_CONTINUE => 'Continue', self::STATUS_SWITCHING_PROTOCOLS => 'Switching Protocols', self::STATUS_PROCESSING => 'Processing', self::STATUS_EARLY_HINTS => 'Early Hints', //Successful 2xx self::STATUS_OK => 'OK', self::STATUS_CREATED => 'Created', self::STATUS_ACCEPTED => 'Accepted', self::STATUS_NON_AUTHORITATIVE_INFORMATION => 'Non-Authoritative Information', self::STATUS_NO_CONTENT => 'No Content', self::STATUS_RESET_CONTENT => 'Reset Content', self::STATUS_PARTIAL_CONTENT => 'Partial Content', self::STATUS_MULTI_STATUS => 'Multi-Status', self::STATUS_ALREADY_REPORTED => 'Already Reported', self::STATUS_IM_USED => 'IM Used', //Redirection 3xx self::STATUS_MULTIPLE_CHOICES => 'Multiple Choices', self::STATUS_MOVED_PERMANENTLY => 'Moved Permanently', self::STATUS_FOUND => 'Found', self::STATUS_SEE_OTHER => 'See Other', self::STATUS_NOT_MODIFIED => 'Not Modified', self::STATUS_USE_PROXY => 'Use Proxy', self::STATUS_RESERVED => 'Reserved', self::STATUS_TEMPORARY_REDIRECT => 'Temporary Redirect', self::STATUS_PERMANENT_REDIRECT => 'Permanent Redirect', //Client Error 4xx self::STATUS_BAD_REQUEST => 'Bad Request', self::STATUS_UNAUTHORIZED => 'Unauthorized', self::STATUS_PAYMENT_REQUIRED => 'Payment Required', self::STATUS_FORBIDDEN => 'Forbidden', self::STATUS_NOT_FOUND => 'Not Found', self::STATUS_METHOD_NOT_ALLOWED => 'Method Not Allowed', self::STATUS_NOT_ACCEPTABLE => 'Not Acceptable', self::STATUS_PROXY_AUTHENTICATION_REQUIRED => 'Proxy Authentication Required', self::STATUS_REQUEST_TIMEOUT => 'Request Timeout', self::STATUS_CONFLICT => 'Conflict', self::STATUS_GONE => 'Gone', self::STATUS_LENGTH_REQUIRED => 'Length Required', self::STATUS_PRECONDITION_FAILED => 'Precondition Failed', self::STATUS_PAYLOAD_TOO_LARGE => 'Request Entity Too Large', self::STATUS_URI_TOO_LONG => 'Request-URI Too Long', self::STATUS_UNSUPPORTED_MEDIA_TYPE => 'Unsupported Media Type', self::STATUS_RANGE_NOT_SATISFIABLE => 'Requested Range Not Satisfiable', self::STATUS_EXPECTATION_FAILED => 'Expectation Failed', self::STATUS_IM_A_TEAPOT => 'I\'m a teapot', 420 => 'Enhance Your Calm', // https://http.cat/420 self::STATUS_MISDIRECTED_REQUEST => 'Misdirected Request', self::STATUS_UNPROCESSABLE_ENTITY => 'Unprocessable Entity', self::STATUS_LOCKED => 'Locked', self::STATUS_FAILED_DEPENDENCY => 'Failed Dependency', self::STATUS_TOO_EARLY => 'Too Early', self::STATUS_UPGRADE_REQUIRED => 'Upgrade Required', self::STATUS_PRECONDITION_REQUIRED => 'Precondition Required', self::STATUS_TOO_MANY_REQUESTS => 'Too Many Requests', self::STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE => 'Request Header Fields Too Large', 444 => 'Connection Closed Without Response', self::STATUS_UNAVAILABLE_FOR_LEGAL_REASONS => 'Unavailable For Legal Reasons', 499 => 'Client Closed Request', //Server Error 5xx self::STATUS_INTERNAL_SERVER_ERROR => 'Internal Server Error', self::STATUS_NOT_IMPLEMENTED => 'Not Implemented', self::STATUS_BAD_GATEWAY => 'Bad Gateway', self::STATUS_SERVICE_UNAVAILABLE => 'Service Unavailable', self::STATUS_GATEWAY_TIMEOUT => 'Gateway Timeout', self::STATUS_VERSION_NOT_SUPPORTED => 'HTTP Version Not Supported', self::STATUS_VARIANT_ALSO_NEGOTIATES => 'Variant Also Negotiates', self::STATUS_INSUFFICIENT_STORAGE => 'Insufficient Storage', self::STATUS_LOOP_DETECTED => 'Loop Detected', self::STATUS_NOT_EXTENDED => 'Not Extended', self::STATUS_NETWORK_AUTHENTICATION_REQUIRED => 'Network Authentication Required', 599 => 'Network Connect Timeout Error', ]

Properties

$body

protected StreamInterface $body

$headers

protected array<string, array{name: string, value: string[]}> $headers = []

$reasonPhrase

protected string $reasonPhrase

$version

protected string $version = '1.1'

Methods

__construct()

Response constructor.

public __construct([int|null $status = null ][, string|null $reason = null ][, StreamInterface|string|null $body = null ]) : mixed
Parameters
$status : int|null = null
$reason : string|null = null
$body : StreamInterface|string|null = null

getBody()

public getBody() : StreamInterface
Return values
StreamInterface

getHeader()

public getHeader(string $name) : array<string|int, mixed>
Parameters
$name : string
Return values
array<string|int, mixed>

getHeaderLine()

public getHeaderLine(string $name) : string
Parameters
$name : string
Return values
string

getHeaders()

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

getProtocolVersion()

public getProtocolVersion() : string
Return values
string

getReasonPhrase()

public getReasonPhrase() : string
Return values
string

getStatusCode()

public getStatusCode() : int
Return values
int

hasHeader()

public hasHeader(string $name) : bool
Parameters
$name : string
Return values
bool

withAddedHeader()

public withAddedHeader(string $name, mixed $value) : static
Parameters
$name : string
$value : mixed
Return values
static

withBody()

public withBody(StreamInterface $body) : static
Parameters
$body : StreamInterface
Return values
static

withHeader()

public withHeader(string $name, mixed $value) : static
Parameters
$name : string
$value : mixed
Return values
static

withoutHeader()

public withoutHeader(string $name) : static
Parameters
$name : string
Return values
static

withProtocolVersion()

public withProtocolVersion(string $version) : static
Parameters
$version : string
Return values
static

withStatus()

public withStatus(int $code[, string $reasonPhrase = '' ]) : static
Parameters
$code : int
$reasonPhrase : string = ''
Return values
static

getReasonPhraseFromStatusCode()

Get the reason phrase for the given status code, returns an empty string if no matching phrase is found

protected getReasonPhraseFromStatusCode(int $status) : string
Parameters
$status : int
Return values
string

        
On this page

Search results