Response
class Response implements ArrayAccess, Stringable mixin ResponseInterface
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected mixed | $decoded | The decoded JSON response. |
|
| protected bool | $hasDecoded | Whether the response body has been decoded. |
|
| protected int | $decodingFlags | The flags that were used when decoding the JSON response. |
|
| protected Closure|null | $decodeUsing | The custom decode callback. |
|
| CookieJar|null | $cookies | The request cookies. |
|
| TransferStats|null | $transferStats | The transfer stats for the request. |
|
| protected false|int|null | $truncateExceptionsAt | The length at which request exceptions will be truncated. |
|
| static int | $defaultJsonDecodingFlags | The flags passed to json_decode by default. |
Methods
Determine if the response code was 202 "Accepted" response.
Determine if the response code was the given status code and the body has no content.
Determine if the response code was a 301 "Moved Permanently".
Determine if the response code was a 304 "Not Modified" response.
Determine if the response was a 400 "Bad Request" response.
Determine if the response was a 401 "Unauthorized" response.
Determine if the response was a 402 "Payment Required" response.
Determine if the response was a 403 "Forbidden" response.
Determine if the response was a 408 "Request Timeout" response.
Determine if the response was a 422 "Unprocessable Content" response.
Determine if the response was a 422 "Unprocessable Content" response.
Determine if the response was a 429 "Too Many Requests" response.
Call the given Closure with this instance then return the instance.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically proxy other methods to the underlying response.
Create a new response instance.
Get the body of the response.
Get the JSON decoded body of the response as an array or scalar value.
Get the JSON decoded body of the response as an object.
Decode the given response body.
Get the JSON decoded body of the response as a collection.
Get the JSON decoded body of the response as a fluent object.
Get the body of the response as a PHP resource.
Get a header from the response.
Get the headers from the response.
Get the status code of the response.
Get the reason phrase of the response.
Get the effective URI of the response.
Determine if the request was successful.
Determine if the response was a redirect.
Determine if the response indicates a client or server error occurred.
Determine if the response indicates a client error occurred.
Determine if the response indicates a server error occurred.
Execute the given callback if there was a server or client error.
Get the response cookies.
Get the handler stats of the response.
Get the underlying PSR response for the response.
Create an exception if a server or client error occurred.
Throw an exception if a server or client error occurred and the given condition evaluates to false.
Throw an exception if the response status code matches the given code.
Throw an exception unless the response status code matches the given code.
Throw an exception if the response status code is a 4xx level code.
Throw an exception if the response status code is a 5xx level code.
Indicate that request exceptions should be truncated to the given length.
Indicate that request exceptions should not be truncated.
Dump the content from the response and end the script.
Dump the headers from the response.
Dump the headers from the response and end the script.
Determine if the given offset exists.
Get the value for a given offset.
Set the value at the given offset.
Unset the value at the given offset.
Flush all static state.
Get the body of the response.
Details
in
DeterminesStatusCode at line 12
bool
ok()
Determine if the response code was 200 "OK" response.
in
DeterminesStatusCode at line 20
bool
created()
Determine if the response code was 201 "Created" response.
in
DeterminesStatusCode at line 28
bool
accepted()
Determine if the response code was 202 "Accepted" response.
in
DeterminesStatusCode at line 36
bool
noContent(int $status = 204)
Determine if the response code was the given status code and the body has no content.
in
DeterminesStatusCode at line 44
bool
movedPermanently()
Determine if the response code was a 301 "Moved Permanently".
in
DeterminesStatusCode at line 52
bool
found()
Determine if the response code was a 302 "Found" response.
in
DeterminesStatusCode at line 60
bool
notModified()
Determine if the response code was a 304 "Not Modified" response.
in
DeterminesStatusCode at line 68
bool
badRequest()
Determine if the response was a 400 "Bad Request" response.
in
DeterminesStatusCode at line 76
bool
unauthorized()
Determine if the response was a 401 "Unauthorized" response.
in
DeterminesStatusCode at line 84
bool
paymentRequired()
Determine if the response was a 402 "Payment Required" response.
in
DeterminesStatusCode at line 92
bool
forbidden()
Determine if the response was a 403 "Forbidden" response.
in
DeterminesStatusCode at line 100
bool
notFound()
Determine if the response was a 404 "Not Found" response.
in
DeterminesStatusCode at line 108
bool
requestTimeout()
Determine if the response was a 408 "Request Timeout" response.
in
DeterminesStatusCode at line 116
bool
conflict()
Determine if the response was a 409 "Conflict" response.
in
DeterminesStatusCode at line 124
bool
unprocessableContent()
Determine if the response was a 422 "Unprocessable Content" response.
in
DeterminesStatusCode at line 132
bool
unprocessableEntity()
Determine if the response was a 422 "Unprocessable Content" response.
in
DeterminesStatusCode at line 140
bool
tooManyRequests()
Determine if the response was a 429 "Too Many Requests" response.
in
Tappable at line 15
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
at line 567
mixed
__call(string $method, array $parameters)
Dynamically proxy other methods to the underlying response.
at line 75
__construct(ResponseInterface $response)
Create a new response instance.
at line 82
string
body()
Get the body of the response.
at line 90
mixed
json(string|null $key = null, mixed $default = null, int|null $flags = null)
Get the JSON decoded body of the response as an array or scalar value.
at line 121
array|object|null
object(int|null $flags = null)
Get the JSON decoded body of the response as an object.
Example: If the response body is: [ {"id": 1, "name": "John"}, {"id": 2, "name": "Jane"} ]
This method will return an array of objects.
at line 137
Response
decodeUsing(Closure|null $callback)
Set a custom decode callback.
The callback will be invoked with the following parameters:
- string $body: The raw response body.
- bool $asObject: When true, the decoder should return an array of objects.
at line 150
protected mixed
decode(string $body, bool $asObject = false, int $flags = 0)
Decode the given response body.
at line 162
Collection
collect(string|null $key = null, int|null $flags = null)
Get the JSON decoded body of the response as a collection.
at line 170
Fluent
fluent(string|null $key = null, int|null $flags = null)
Get the JSON decoded body of the response as a fluent object.
at line 182
resource
resource()
Get the body of the response as a PHP resource.
at line 190
string
header(string $header)
Get a header from the response.
at line 198
array
headers()
Get the headers from the response.
at line 206
int
status()
Get the status code of the response.
at line 214
string
reason()
Get the reason phrase of the response.
at line 222
UriInterface|null
effectiveUri()
Get the effective URI of the response.
at line 230
bool
successful()
Determine if the request was successful.
at line 238
bool
redirect()
Determine if the response was a redirect.
at line 246
bool
failed()
Determine if the response indicates a client or server error occurred.
at line 254
bool
clientError()
Determine if the response indicates a client error occurred.
at line 262
bool
serverError()
Determine if the response indicates a server error occurred.
at line 270
Response
onError(callable $callback)
Execute the given callback if there was a server or client error.
at line 282
CookieJar
cookies()
Get the response cookies.
at line 290
array
handlerStats()
Get the handler stats of the response.
at line 298
Response
close()
Close the stream and any underlying resources.
at line 308
ResponseInterface
toPsrResponse()
Get the underlying PSR response for the response.
at line 316
RequestException|null
toException()
Create an exception if a server or client error occurred.
at line 330
Response
throw()
Throw an exception if a server or client error occurred.
at line 350
Response
throwIf(bool|Closure $condition)
Throw an exception if a server or client error occurred and the given condition evaluates to true.
at line 360
Response
throwUnless(bool|Closure $condition)
Throw an exception if a server or client error occurred and the given condition evaluates to false.
at line 372
Response
throwIfStatus(callable|int $statusCode)
Throw an exception if the response status code matches the given code.
at line 389
Response
throwUnlessStatus(callable|int $statusCode)
Throw an exception unless the response status code matches the given code.
at line 403
Response
throwIfClientError()
Throw an exception if the response status code is a 4xx level code.
at line 413
Response
throwIfServerError()
Throw an exception if the response status code is a 5xx level code.
at line 421
Response
truncateExceptionsAt(int $length)
Indicate that request exceptions should be truncated to the given length.
at line 431
Response
dontTruncateExceptions()
Indicate that request exceptions should not be truncated.
at line 443
Response
dump(string|null $key = null)
Dump the content from the response.
at line 467
void
dd(string|null $key = null)
Dump the content from the response and end the script.
at line 477
Response
dumpHeaders()
Dump the headers from the response.
at line 489
never
ddHeaders()
Dump the headers from the response and end the script.
at line 501
bool
offsetExists(string $offset)
Determine if the given offset exists.
at line 511
mixed
offsetGet(string $offset)
Get the value for a given offset.
at line 523
void
offsetSet(string $offset, mixed $value)
Set the value at the given offset.
at line 535
void
offsetUnset(string $offset)
Unset the value at the given offset.
at line 543
static void
flushState()
Flush all static state.
at line 554
string
__toString()
Get the body of the response.