ApiEnvelope
in package
FinalYes
Safe reader of the Api response envelope (`success`, `message`, `code`, `data`) that {@see \App\Core\Bridge\ApiBridge} returns as `mixed` (an array for internal calls, decoded JSON for external ones).
Replaces repeated $response['message'] ?? '...' / ResultCode::resolve($response['code'] ?? null)
in repositories: same behavior for a valid envelope, but an unexpected shape (not an array,
a message or code of another type) yields a default instead of a TypeError in
Result::success() / ResultCode::resolve().
Table of Contents
Methods
- arrayData() : array<string|int, mixed>|null
- Returns `data` only when it is an array (null otherwise).
- code() : ResultCode
- data() : mixed
- isSuccess() : bool
- Succeeds only when `success === true`.
- message() : string
- messageOrNull() : string|null
Methods
arrayData()
Returns `data` only when it is an array (null otherwise).
public
static arrayData(mixed $response) : array<string|int, mixed>|null
Parameters
- $response : mixed
Return values
array<string|int, mixed>|nullcode()
public
static code(mixed $response) : ResultCode
Parameters
- $response : mixed
Return values
ResultCodedata()
public
static data(mixed $response) : mixed
Parameters
- $response : mixed
isSuccess()
Succeeds only when `success === true`.
public
static isSuccess(mixed $response) : bool
Parameters
- $response : mixed
Return values
boolmessage()
public
static message(mixed $response, string $default) : string
Parameters
- $response : mixed
- $default : string
Return values
stringmessageOrNull()
public
static messageOrNull(mixed $response) : string|null
Parameters
- $response : mixed