class ApiResource implements Stringable, ArrayAccess, JsonSerializable, Arrayable, Jsonable mixin ApiResponse

Traits

Methods

mixed
forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

mixed
forwardDecoratedCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object, returning $this if the forwarded call returned itself.

static never
throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

__construct(ApiResponse $response, ApiRequest $request)

Create a new resource instance.

string
__toString()

Get the resource body as a string.

bool
__isset(string $key)

Determine if an attribute exists on the resource.

void
__set(string $key, mixed $value)

Reject property assignment on the resource.

void
__unset(string $key)

Reject unsetting a property on the resource.

mixed
__get(string $key)

Dynamically get properties from the underlying resource.

mixed
__call(string $method, array $parameters)

Dynamically pass method calls to the underlying resource.

getResponse()

Get the API response.

getRequest()

Get the API request.

static ApiResource
make(ApiResponse $response, ApiRequest $request)

Create a new resource instance.

array
resolve()

Resolve the resource to an array.

array
toArray()

Transform the resource into an array.

string
toJson(int $options = 0)

Convert the resource to its JSON representation.

string
toPrettyJson(int $options = 0)

Convert the resource to its pretty-printed JSON representation.

array
jsonSerialize()

Prepare the resource for JSON serialization.

bool
offsetExists(mixed $offset)

Determine if the given offset exists.

mixed
offsetGet(mixed $offset)

Get the value for a given offset.

void
offsetSet(mixed $offset, mixed $value)

Set the value at the given offset.

void
offsetUnset(mixed $offset)

Unset the value at the given offset.

Details

in ForwardsCalls at line 22
protected mixed forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in ForwardsCalls at line 52
protected mixed forwardDecoratedCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object, returning $this if the forwarded call returned itself.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in ForwardsCalls at line 66
static protected never throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

never

Exceptions

BadMethodCallException

at line 28
__construct(ApiResponse $response, ApiRequest $request)

Create a new resource instance.

Parameters

ApiResponse $response
ApiRequest $request

at line 37
string __toString()

Get the resource body as a string.

Return Value

string

at line 47
bool __isset(string $key)

Determine if an attribute exists on the resource.

Parameters

string $key

Return Value

bool

Exceptions

JsonException

at line 57
void __set(string $key, mixed $value)

Reject property assignment on the resource.

Parameters

string $key
mixed $value

Return Value

void

at line 65
void __unset(string $key)

Reject unsetting a property on the resource.

Parameters

string $key

Return Value

void

at line 76
mixed __get(string $key)

Dynamically get properties from the underlying resource.

Parameters

string $key

Return Value

mixed

Exceptions

InvalidResourceDataException
JsonException

at line 84
mixed __call(string $method, array $parameters)

Dynamically pass method calls to the underlying resource.

Parameters

string $method
array $parameters

Return Value

mixed

at line 92
ApiResponse getResponse()

Get the API response.

Return Value

ApiResponse

at line 100
ApiRequest getRequest()

Get the API request.

Return Value

ApiRequest

at line 108
static ApiResource make(ApiResponse $response, ApiRequest $request)

Create a new resource instance.

Parameters

ApiResponse $response
ApiRequest $request

Return Value

ApiResource

at line 120
array resolve()

Resolve the resource to an array.

Return Value

array

Exceptions

InvalidResourceDataException
JsonException

at line 132
array toArray()

Transform the resource into an array.

Return Value

array

Exceptions

InvalidResourceDataException
JsonException

at line 143
string toJson(int $options = 0)

Convert the resource to its JSON representation.

Parameters

int $options

Return Value

string

Exceptions

InvalidResourceDataException
JsonException

at line 154
string toPrettyJson(int $options = 0)

Convert the resource to its pretty-printed JSON representation.

Parameters

int $options

Return Value

string

Exceptions

InvalidResourceDataException
JsonException

at line 166
array jsonSerialize()

Prepare the resource for JSON serialization.

Return Value

array

Exceptions

InvalidResourceDataException
JsonException

at line 176
bool offsetExists(mixed $offset)

Determine if the given offset exists.

Parameters

mixed $offset

Return Value

bool

Exceptions

JsonException

at line 187
mixed offsetGet(mixed $offset)

Get the value for a given offset.

Parameters

mixed $offset

Return Value

mixed

Exceptions

InvalidResourceDataException
JsonException

at line 195
void offsetSet(mixed $offset, mixed $value)

Set the value at the given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

at line 203
void offsetUnset(mixed $offset)

Unset the value at the given offset.

Parameters

mixed $offset

Return Value

void