Documentation

Response
in package
implements ResponseInterface

Any HTTP response is built off a set of headers and a body that contains the message being delivered. This class represents an HTTP response that can be sent by the application.

I'd like to include the option to have in App return states. This way, if the app provides a return URL for success or error the Response could automatically handle that and send the user to the preferred location.

For this to work the application would have to define a onXXXXX GET parameter that would be read. If the return state of the application is "success" the Response should look for an "onsuccess" GET parameter and send the user to that endpoint.

Interfaces, Classes and Traits

ResponseInterface

Table of Contents

$body  : StreamInterface
Contains the Body of the response. Usually HTML. You can put any kind of data in the response body as long as it can be encoded properly with the defined encoding.
$headers  : Headers
The headers this response should be sent with. This includes anything from the status code, to redirections and even debugging messages.
__construct()  : mixed
Instantiates a new Response element. This element allows you application to generate several potential responses to a certain request and then pick the one it desires to use.
getBody()  : StreamInterface
Returns the content that is to be sent with the body. This is a string your application has to set beforehand.
getHeader()  : array<string|int, string>
getHeaderLine()  : string
The header line represents the data that is being sent to the browser, some headers allow sending multiple values, separated by commas, which the client cannot receive unless we convert our arrays in comma separated strings.
getHeaders()  : array<string|int, array<string|int, string>>
getProtocolVersion()  : string
Return the protocol for the HTTP communication. For our response, we just assume it's going to be the one our webserver is using.
getReasonPhrase()  : string
getStatusCode()  : int
The integer representation of the status code.
hasHeader()  : bool
headers()  : Headers
Returns the headers object. This allows to manipulate the answer headers for the current request.
setHeaders()  : Response
Changes the headers object. This allows your application to quickly change all headers and replace everything the way you want it.
withAddedHeader()  : Response
Returns a copy of the response, but with additional information on a header, which allows the user to push data onto the header.
withBody()  : Response
Creates a new response with the provided body. Please note that the response is immutable, which means that a copy of the object is created when setting a new body.
withHeader()  : Response
Returns a copy of the response, with the header that the user has added.
withoutHeader()  : Response
Returns a copy of the response, without the given header.
withProtocolVersion()  : Response
We currently do not allow the user to override the protocol version of the response object to ensure that the behavior of our application is correct.
withStatus()  : Response

Properties

$body

Contains the Body of the response. Usually HTML. You can put any kind of data in the response body as long as it can be encoded properly with the defined encoding.

private StreamInterface $body

$headers

The headers this response should be sent with. This includes anything from the status code, to redirections and even debugging messages.

private Headers $headers

[Notice] You should not include debugging messages into your headers in production environments.

Methods

__construct()

Instantiates a new Response element. This element allows you application to generate several potential responses to a certain request and then pick the one it desires to use.

public __construct(StreamInterface $body[, int $status = 200 ][, mixed $headers = null ]) : mixed

It also provides the App with the ability to discard a certain response before it was sent and generate a completely new one.

Parameters
$body : StreamInterface
$status : int = 200
$headers : mixed = null
Return values
mixed

getBody()

Returns the content that is to be sent with the body. This is a string your application has to set beforehand.

public getBody() : StreamInterface

In case you're using Spitfire's Context object to manage the context the response will get the view it contains and render that before returning it.

Return values
StreamInterface

getHeader()

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

getHeaderLine()

The header line represents the data that is being sent to the browser, some headers allow sending multiple values, separated by commas, which the client cannot receive unless we convert our arrays in comma separated strings.

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

getHeaders()

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

getProtocolVersion()

Return the protocol for the HTTP communication. For our response, we just assume it's going to be the one our webserver is using.

public getProtocolVersion() : string
Return values
string

getReasonPhrase()

public getReasonPhrase() : string
Return values
string

getStatusCode()

The integer representation of the status code.

public getStatusCode() : int
Return values
int

hasHeader()

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

headers()

Returns the headers object. This allows to manipulate the answer headers for the current request.

public headers() : Headers
Return values
Headers

setHeaders()

Changes the headers object. This allows your application to quickly change all headers and replace everything the way you want it.

public setHeaders(Headers $headers) : Response
Parameters
$headers : Headers
Return values
Response

withAddedHeader()

Returns a copy of the response, but with additional information on a header, which allows the user to push data onto the header.

public withAddedHeader(string $name, string|array<string|int, string> $value) : Response
Parameters
$name : string
$value : string|array<string|int, string>
Return values
Response

withBody()

Creates a new response with the provided body. Please note that the response is immutable, which means that a copy of the object is created when setting a new body.

public withBody(StreamInterface $body) : Response

However, the body itself is not immutable, which means that often it is possible to modify the body while the response is immutable. This can lead to performance improvements when working with the body, but also lead to issues with stability. You should avoid creating a response prematurely, and wait until the body is complete.

Parameters
$body : StreamInterface
Return values
Response

withHeader()

Returns a copy of the response, with the header that the user has added.

public withHeader(string $name, string|array<string|int, string> $value) : Response
Parameters
$name : string
$value : string|array<string|int, string>
Return values
Response

withoutHeader()

Returns a copy of the response, without the given header.

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

withProtocolVersion()

We currently do not allow the user to override the protocol version of the response object to ensure that the behavior of our application is correct.

public withProtocolVersion(mixed $version) : Response

The caller will receive this instance back.

Parameters
$version : mixed
Return values
Response

withStatus()

public withStatus(mixed $code[, mixed $reasonPhrase = '' ]) : Response
Parameters
$code : mixed
$reasonPhrase : mixed = ''
Return values
Response

Search results