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
stringgetReasonPhrase()
{@inheritdoc}
public
getReasonPhrase() : string
Return values
stringgetResponse()
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
ResponseInterfacegetStatusCode()
{@inheritdoc}
public
getStatusCode() : int
Return values
intisClientError()
Is this response a client error?
public
isClientError() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisEmpty()
Is this response empty?
public
isEmpty() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisForbidden()
Is this response forbidden?
public
isForbidden() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisInformational()
Is this response informational?
public
isInformational() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisNotFound()
Is this response not Found?
public
isNotFound() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisOk()
Is this response OK?
public
isOk() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisRedirect()
Is this response a redirect?
public
isRedirect() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisRedirection()
Is this response a redirection?
public
isRedirection() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisServerError()
Is this response a server error?
public
isServerError() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolisSuccessful()
Is this response successful?
public
isSuccessful() : bool
Note: This method is not part of the PSR-7 standard.
Return values
boolwithJson()
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
Return values
staticwithRedirect()
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
staticwithResponse()
Exchanges the underlying response with another.
public
withResponse(ResponseInterface $response) : self
Parameters
- $response : ResponseInterface
Return values
selfwithStatus()
{@inheritdoc}
public
withStatus(mixed $code[, mixed $reasonPhrase = '' ]) : self
Parameters
- $code : mixed
- $reasonPhrase : mixed = ''