Basicis - Core

Logo

As the name says, it is made to be basic and direct.

View the Project on GitHub basicis/core

Basicis\Http\Message\Response

Response class Representation of an outgoing, server-side response.

Per the HTTP specification, this interface includes properties for each of the following:

Responses are considered immutable; all methods that might change state MUST be implemented such that they retain the internal state of the current message and return an instance that contains the changed state.

Implements:

Psr\Http\Message\MessageInterface, Psr\Http\Message\ResponseInterface

Extend:

Basicis\Http\Message\Message

Methods

Name Description
__construct Function ___contruct
getReasonPhrase Function getReasonPhrase
Gets the response reason phrase associated with the status code.  
getStatusCode Function getStatusCode
Gets the response status code.  
isValid Function isValid
Check if response status code is valid, it is in the array const CODE_LIST  
withStatus Function withStatus
Return an instance with the specified status code and, optionally, reason phrase.  

Inherited methods

Name Description
getBody Function getBody
Gets the body of the message.  
getHeader Function getHeader
Retrieves a message header value by the given case-insensitive name.  
getHeaderLine Function getHeaderLine
getHeaderLines Function getHeaderLines
getHeaders Funtion getHeaders
Retrieves all message header values  
getProtocolVersion Function getProtocolVersion
Retrieves the HTTP protocol version as a string.  
hasHeader Function hasHeader
Checks if a header exists by the given case-insensitive name.  
normalizeHeaderKey Function normalizeHeaderKey
parseHeader Function parseHeader
Pass an line to the current header, if the parameter $rewrite === false  
parseHeaders Function parseHeaders
Pass an array of lines to the current header, if the parameter $rewrite === false.  
withAddedHeader FunctionwithAddedHeader
Return an instance with the specified header appended with the given value.  
withBody Function withBody
Return an instance with the specified message body.  
withHeader Function withHeader
Return an instance with the provided value replacing the specified header.  
withHeaders Function withHeaders
withProtocolVersion Function withProtocolVersion
Return an instance with the specified HTTP protocol version.  
withoutHeader Function withoutHeader
Return an instance without the specified header.  

Response::__construct

Description

public __construct (int $code, string $reasonPhrase)

Function ___contruct

Parameters

Return Values

void


Response::getReasonPhrase

Description

public getReasonPhrase (void)

Function getReasonPhrase Gets the response reason phrase associated with the status code.

Because a reason phrase is not a required element in a response
status line, the reason phrase value MAY be null. Implementations MAY
choose to return the default RFC 7231 recommended reason phrase (or those
listed in the IANA HTTP Status Code Registry) for the response’s
status code.

Parameters

This function has no parameters.

Return Values

string

Reason phrase; must return an empty string if none present.


Response::getStatusCode

Description

public getStatusCode (void)

Function getStatusCode Gets the response status code.

The status code is a 3-digit integer result code of the server’s attempt
to understand and satisfy the request.

Parameters

This function has no parameters.

Return Values

int

Status code.


Response::isValid

Description

public isValid (void)

Function isValid Check if response status code is valid, it is in the array const CODE_LIST

Parameters

This function has no parameters.

Return Values

bool


Response::withStatus

Description

public withStatus (int $code, string $reasonPhrase)

Function withStatus Return an instance with the specified status code and, optionally, reason phrase.

If no reason phrase is specified, implementations MAY choose to default
to the RFC 7231 or IANA recommended reason phrase for the response’s
status code.

This method MUST be implemented in such a way as to retain the
immutability of the message, and MUST return an instance that has the
updated status and reason phrase.

Parameters

Return Values

static

Throws Exceptions

\InvalidArgumentException

For invalid status code arguments.