Response
class Response extends Response
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected mixed | $decoded | The decoded JSON response. |
from Response |
| protected bool | $decodedJson | Indicates if the JSON response has been decoded. |
from Response |
| protected JSON_THROW_ON_ERROR> | $decodingFlags | The flags that were used when decoding the JSON response. |
from Response |
| protected Closure|null | $decodeUsing | The custom decode callback. |
from Response |
| CookieJar|null | $cookies | The request cookies. |
from Response |
| TransferStats|null | $transferStats | The transfer stats for the request. |
from Response |
| protected false|int|null | $truncateExceptionsAt | The length at which request exceptions will be truncated. |
from Response |
| static JSON_THROW_ON_ERROR> | $defaultJsonDecodingFlags | The flags passed to |
from Response |
| protected bool | $cached | Whether the response came from the cache. |
|
| protected bool | $mocked | Whether the response came from a mock client. |
|
| protected FakeResponse|null | $fakeResponse | The fake response that produced this response. |
|
| protected TDto> | $pendingRequest | The pending request that produced the response. |
|
| protected RequestInterface | $psrRequest | The final application-owned PSR request. |
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 handle calls to the class.
Get the response body.
Decode non-empty JSON lines from the current response body position.
Get the decoded JSON body of the response as an array or scalar value.
Get the decoded JSON body of the response as an object.
Decode the given response body.
Get the decoded JSON body of the response as a collection.
Get the decoded JSON body of the response as a fluent object.
Determine if the integration considers the response failed.
Execute the given callback if there was a server or client error.
Create an exception when the integration considers the response throwable.
Create a new request exception for the response.
Throw an exception when the integration considers the response throwable.
Throw an exception if a server or client error occurred and the given condition evaluates to true.
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.
Create a Saloon response from a framework response.
Get the response body stream.
Get the pending request.
Get the final application-owned PSR request.
Determine if the response should throw a request exception.
Get the JSON decoded body as an array. Provide a key to find a specific item in the JSON.
Convert the response into a data object.
Convert the response into a data object or fail.
Convert the XML response into a SimpleXMLElement.
Parse the HTML or XML response into a DOM crawler.
Convert the response into a data URL.
Determine if the response is in JSON format.
Determine if the response is in XML format.
Create a temporary resource containing the response body.
Save the response body to a path or resource.
Determine if the response came from the cache.
Determine if the response came from a mock client.
Determine if the response came from a short-circuit source.
Get the fake response that produced this 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 17
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
Response at line 84
__construct(ResponseInterface $response)
Create a new response instance.
at line 92
string
body()
Get the response body.
in
Response at line 101
Generator
lines()
Read lines from the current response body position without rewinding.
in
Response at line 112
Generator
jsonLines(int|null $flags = null)
Decode non-empty JSON lines from the current response body position.
in
Response at line 128
mixed
json(string|null $key = null, mixed $default = null, int|null $flags = null)
Get the decoded JSON body of the response as an array or scalar value.
in
Response at line 162
mixed
object(int|null $flags = null)
Get the decoded JSON 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. Scalar JSON values remain their decoded scalar type.
in
Response at line 180
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: Whether JSON objects should be decoded as objects.
in
Response at line 195
protected mixed
decode(string $body, bool $asObject = false, int $flags = 0)
Decode the given response body.
in
Response at line 209
Collection
collect(string|null $key = null, int|null $flags = null)
Get the decoded JSON body of the response as a collection.
in
Response at line 219
Fluent
fluent(string|null $key = null, int|null $flags = null)
Get the decoded JSON body of the response as a fluent object.
in
Response at line 231
mixed
resource()
Get the body of the response as a PHP resource.
in
Response at line 239
string
header(string $header)
Get a header from the response.
in
Response at line 247
array
headers()
Get the headers from the response.
in
Response at line 255
int
status()
Get the status code of the response.
in
Response at line 263
string
reason()
Get the reason phrase of the response.
in
Response at line 271
UriInterface|null
effectiveUri()
Get the effective URI of the response.
in
Response at line 279
bool
successful()
Determine if the request was successful.
in
Response at line 287
bool
redirect()
Determine if the response was a redirect.
at line 161
bool
failed()
Determine if the integration considers the response failed.
in
Response at line 303
bool
clientError()
Determine if the response indicates a client error occurred.
in
Response at line 311
bool
serverError()
Determine if the response indicates a server error occurred.
in
Response at line 321
Response
onError(callable $callback)
Execute the given callback if there was a server or client error.
in
Response at line 333
CookieJar|null
cookies()
Get the response cookies.
in
Response at line 341
array
handlerStats()
Get the handler stats of the response.
in
Response at line 361
ResponseInterface
toPsrResponse()
Get the underlying PSR response for the response.
at line 186
RequestException|null
toException()
Create an exception when the integration considers the response throwable.
at line 215
protected RequestException
newRequestException()
Create a new request exception for the response.
at line 197
Response
throw(callable|null $callback = null)
Throw an exception when the integration considers the response throwable.
in
Response at line 415
Response
throwIf(bool|Closure $condition, callable|null $callback = null)
Throw an exception if a server or client error occurred and the given condition evaluates to true.
in
Response at line 428
Response
throwUnless(bool|Closure $condition, callable|null $callback = null)
Throw an exception if a server or client error occurred and the given condition evaluates to false.
in
Response at line 440
Response
throwIfStatus(int|callable $statusCode)
Throw an exception if the response status code matches the given code.
in
Response at line 457
Response
throwUnlessStatus(int|callable $statusCode)
Throw an exception unless the response status code matches the given code.
in
Response at line 473
Response
throwIfClientError()
Throw an exception if the response status code is a 4xx level code.
in
Response at line 485
Response
throwIfServerError()
Throw an exception if the response status code is a 5xx level code.
in
Response at line 495
Response
truncateExceptionsAt(int $length)
Indicate that request exceptions should be truncated to the given length.
in
Response at line 507
Response
dontTruncateExceptions()
Indicate that request exceptions should not be truncated.
in
Response at line 541
never
dd(string|null $key = null)
Dump the content from the response and end the script.
in
Response at line 563
never
ddHeaders()
Dump the headers from the response and end the script.
in
Response at line 575
bool
offsetExists(string $offset)
Determine if the given offset exists.
in
Response at line 585
mixed
offsetGet(string $offset)
Get the value for a given offset.
in
Response at line 597
void
offsetSet(string $offset, mixed $value)
Set the value at the given offset.
in
Response at line 609
void
offsetUnset(string $offset)
Unset the value at the given offset.
in
Response at line 617
static void
flushState()
Flush all static state.
in
Response at line 626
string
__toString()
Get the body of the response.
at line 70
static Response
fromResponse(Response $response, PendingRequest $pendingRequest, RequestInterface $psrRequest)
Create a Saloon response from a framework response.
at line 114
StreamInterface
stream()
Get the response body stream.
at line 127
PendingRequest
pendingRequest()
Get the pending request.
at line 135
Connector
connector()
Get the connector.
at line 145
Request
request()
Get the original request.
at line 153
RequestInterface
toPsrRequest()
Get the final application-owned PSR request.
at line 177
bool
shouldThrowRequestException()
Determine if the response should throw a request exception.
at line 254
mixed
array(int|string|null $key = null, mixed $default = null)
Get the JSON decoded body as an array. Provide a key to find a specific item in the JSON.
Alias of json()
at line 264
mixed
dto()
Convert the response into a data object.
at line 281
mixed
dtoOrFail()
Convert the response into a data object or fail.
at line 299
SimpleXMLElement|false
xml(mixed ...$arguments)
Convert the XML response into a SimpleXMLElement.
at line 309
Crawler
dom()
Parse the HTML or XML response into a DOM crawler.
at line 317
string
dataUrl()
Convert the response into a data URL.
at line 325
bool
isJson()
Determine if the response is in JSON format.
at line 333
bool
isXml()
Determine if the response is in XML format.
at line 343
mixed
getRawStream()
Create a temporary resource containing the response body.
at line 361
void
saveBodyToFile(mixed $resourceOrPath, bool $closeResource = true)
Save the response body to a path or resource.
at line 409
bool
isCached()
Determine if the response came from the cache.
at line 419
Response
setCached(bool $cached)
Set whether the response came from the cache.
at line 429
bool
isMocked()
Determine if the response came from a mock client.
at line 439
Response
setMocked(bool $mocked)
Set whether the response came from a mock client.
at line 449
bool
isFaked()
Determine if the response came from a short-circuit source.
at line 459
Response
setFakeResponse(FakeResponse $fakeResponse)
Set the fake response that produced this response.
at line 469
FakeResponse|null
fakeResponse()
Get the fake response that produced this response.