Documentation

Response
in package
implements ResponseInterface uses ResponseDecoratorTrait

Class Response

Table of Contents

Interfaces

ResponseInterface

Constants

EOL  = "\r\n"

Methods

__construct()  : mixed
__toString()  : string
Convert response to string.
getReasonPhrase()  : string
{@inheritdoc}
getResponse()  : ResponseInterface
Returns the decorated response.
getStatusCode()  : int
{@inheritdoc}
isClientError()  : bool
Is this response a client error?
isEmpty()  : bool
Is this response empty?
isForbidden()  : bool
Is this response forbidden?
isInformational()  : bool
Is this response informational?
isNotFound()  : bool
Is this response not Found?
isOk()  : bool
Is this response OK?
isRedirect()  : bool
Is this response a redirect?
isRedirection()  : bool
Is this response a redirection?
isServerError()  : bool
Is this response a server error?
isSuccessful()  : bool
Is this response successful?
withJson()  : static
Json.
withRedirect()  : static
Redirect.
withResponse()  : self
Exchanges the underlying response with another.
withStatus()  : self
{@inheritdoc}

Constants

EOL

private string EOL = "\r\n"

EOL characters used for HTTP response.

Methods

__construct()

public __construct([int $status = 200 ][, array<string|int, mixed> $headers = [] ][, string|null|resource|StreamInterface $body = null ][, string $version = '1.1' ][, string|null $reason = null ]) : mixed
Parameters
$status : int = 200

Status code

$headers : array<string|int, mixed> = []

Response headers

$body : string|null|resource|StreamInterface = null

Response body

$version : string = '1.1'

Protocol version

$reason : string|null = null

Reason phrase (optional)

__toString()

Convert response to string.

public __toString() : string

Note: This method is not part of the PSR-7 standard.

Return values
string

getResponse()

Returns the decorated response.

public getResponse() : ResponseInterface

Since the underlying Response is immutable as well exposing it is not an issue, because it's state cannot be altered

Return values
ResponseInterface

isClientError()

Is this response a client error?

public isClientError() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isEmpty()

Is this response empty?

public isEmpty() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isForbidden()

Is this response forbidden?

public isForbidden() : bool
APIYes

Note: This method is not part of the PSR-7 standard.

Return values
bool

isInformational()

Is this response informational?

public isInformational() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isNotFound()

Is this response not Found?

public isNotFound() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isOk()

Is this response OK?

public isOk() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isRedirect()

Is this response a redirect?

public isRedirect() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isRedirection()

Is this response a redirection?

public isRedirection() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isServerError()

Is this response a server error?

public isServerError() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

isSuccessful()

Is this response successful?

public isSuccessful() : bool

Note: This method is not part of the PSR-7 standard.

Return values
bool

withJson()

Json.

public withJson(mixed $data[, int|null $status = null ][, int $options = 0 ][, int $depth = 512 ]) : static

Note: This method is not part of the PSR-7 standard.

This method prepares the response object to return an HTTP Json response to the client.

Parameters
$data : mixed

The data

$status : int|null = null

The HTTP status code.

$options : int = 0

Json encoding options

$depth : int = 512

Json encoding max depth

Tags
phpstan-param

positive-int $depth

Return values
static

withRedirect()

Redirect.

public withRedirect(string $url[, int|null $status = null ]) : static

Note: This method is not part of the PSR-7 standard.

This method prepares the response object to return an HTTP Redirect response to the client.

Parameters
$url : string

The redirect destination.

$status : int|null = null

The redirect HTTP status code.

Return values
static

withResponse()

Exchanges the underlying response with another.

public withResponse(ResponseInterface $response) : self
Parameters
$response : ResponseInterface
Return values
self

withStatus()

{@inheritdoc}

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

        
On this page

Search results