ApiStatusData
in package
Manages API status caching and provides service status checking.
This class implements smart caching with:
- Cache validity: 5 minutes
- Refresh trigger window: 4 minutes 30 seconds to 5 minutes
- Async refresh in refresh window
- Blocking refresh when cache is stale
Table of Contents
Properties
- $lastRefreshed : Carbon|null
- $online : array<string|int, mixed>
- $refreshPromise : PromiseInterface|null
- $service : array<string|int, mixed>
- $status : array<string|int, mixed>
- $updated : array<string|int, mixed>
- $uptimePct30d : array<string|int, mixed>
- $uptimePct90d : array<string|int, mixed>
Methods
- getApiStatus() : ApiStatusResult
- Get status for specific service.
- getCachedApiStatus() : ApiStatus|null
- Get cached ApiStatus object.
- getLastRefreshed() : Carbon|null
- Get last refresh timestamp.
- hasData() : bool
- Check if cache has data.
- inRefreshWindow() : bool
- Check if cache is in refresh window (4min30sec - 5min).
- isValid() : bool
- Check if cache is still valid (within 5 minutes).
- refresh() : bool
- Fetch fresh status from API.
- refreshAsync() : void
- Trigger non-blocking async refresh.
- update() : void
- Update internal state from API response.
- getServiceStatus() : ApiStatusResult
- Get status for a specific service from cached data.
- refreshBlocking() : bool
- Blocking refresh - wait for response.
Properties
$lastRefreshed
private
Carbon|null
$lastRefreshed
= null
When cache was last refreshed
$online
private
array<string|int, mixed>
$online
= []
Boolean online status array
$refreshPromise
private
PromiseInterface|null
$refreshPromise
= null
Async refresh promise (to prevent duplicate refreshes)
$service
private
array<string|int, mixed>
$service
= []
Service names array
$status
private
array<string|int, mixed>
$status
= []
Status strings array
$updated
private
array<string|int, mixed>
$updated
= []
Timestamp array
$uptimePct30d
private
array<string|int, mixed>
$uptimePct30d
= []
30-day uptime percentages
$uptimePct90d
private
array<string|int, mixed>
$uptimePct90d
= []
90-day uptime percentages
Methods
getApiStatus()
Get status for specific service.
public
getApiStatus(ClientBase $client, string $service[, bool $skipBlockingRefresh = false ]) : ApiStatusResult
Parameters
- $client : ClientBase
-
The API client instance (ClientBase or Client).
- $service : string
-
The service path to check (e.g., "/v1/stocks/quotes/").
- $skipBlockingRefresh : bool = false
-
If true, return UNKNOWN instead of blocking on refresh when cache is stale.
Return values
ApiStatusResult —The status result (ONLINE, OFFLINE, or UNKNOWN)
getCachedApiStatus()
Get cached ApiStatus object.
public
getCachedApiStatus() : ApiStatus|null
Return values
ApiStatus|null —The cached ApiStatus object, or null if no cache
getLastRefreshed()
Get last refresh timestamp.
public
getLastRefreshed() : Carbon|null
Return values
Carbon|null —The last refresh timestamp, or null if never refreshed
hasData()
Check if cache has data.
public
hasData() : bool
Return values
bool —True if cache has data, false otherwise
inRefreshWindow()
Check if cache is in refresh window (4min30sec - 5min).
public
inRefreshWindow() : bool
Return values
bool —True if cache is in refresh window, false otherwise
isValid()
Check if cache is still valid (within 5 minutes).
public
isValid() : bool
Return values
bool —True if cache is valid, false otherwise
refresh()
Fetch fresh status from API.
public
refresh(ClientBase $client[, bool $blocking = false ]) : bool
Parameters
- $client : ClientBase
-
The API client instance (ClientBase or Client).
- $blocking : bool = false
-
Whether to wait for response (true) or trigger async refresh (false).
Return values
bool —True on success, false on failure (only meaningful for blocking mode)
refreshAsync()
Trigger non-blocking async refresh.
public
refreshAsync(ClientBase $client) : void
Parameters
- $client : ClientBase
-
The API client instance (ClientBase or Client).
update()
Update internal state from API response.
public
update(object $data) : void
Parameters
- $data : object
-
The raw response object containing API status information.
Tags
getServiceStatus()
Get status for a specific service from cached data.
private
getServiceStatus(string $service) : ApiStatusResult
Parameters
- $service : string
-
The service path to check.
Return values
ApiStatusResult —The status result
refreshBlocking()
Blocking refresh - wait for response.
private
refreshBlocking(ClientBase $client) : bool
Parameters
- $client : ClientBase
-
The API client instance (ClientBase or Client).
Return values
bool —True on success, false on failure