Documentation

JsonRateLimitStore
in package
implements RateLimitStoreInterface

Table of Contents

Interfaces

RateLimitStoreInterface

Properties

$data  : array<string|int, mixed>
$filename  : string

Methods

__construct()  : mixed
Create a JsonRateLimitStore backed by the given file and load any existing data.
allForClient()  : array<string|int, mixed>
Retrieve all rate-limit window entries for a client.
get()  : null|array{remaining: int, timestamp: int}
Retrieve the stored rate-limit entry for a client and window.
set()  : void
Store the remaining quota and associated timestamp for a client's rate-limit window and persist it to the configured JSON file.
load()  : void
save()  : void
Persist the in-memory rate limit data to the configured JSON file.

Properties

Methods

__construct()

Create a JsonRateLimitStore backed by the given file and load any existing data.

public __construct(string $filename) : mixed

If the file exists, its JSON contents are decoded into the in-memory store; decoding failures result in an empty dataset.

Parameters
$filename : string

path to the JSON file used to persist rate limit data

allForClient()

Retrieve all rate-limit window entries for a client.

public allForClient(string $clientId) : array<string|int, mixed>
Parameters
$clientId : string

the client identifier

Return values
array<string|int, mixed>

an associative array of windows to entries where each entry contains keys remaining (int) and timestamp (int); returns an empty array if the client has no entries

get()

Retrieve the stored rate-limit entry for a client and window.

public get(string $clientId, string $window) : null|array{remaining: int, timestamp: int}
Parameters
$clientId : string

the client identifier

$window : string

the rate-limit window identifier

Return values
null|array{remaining: int, timestamp: int}

the entry for the specified client and window: an array with keys remaining and timestamp, or null if not found

set()

Store the remaining quota and associated timestamp for a client's rate-limit window and persist it to the configured JSON file.

public set(string $clientId, string $window, int $remaining, int $timestamp) : void
Parameters
$clientId : string

identifier of the client

$window : string

identifier of the rate-limit window

$remaining : int

number of remaining requests for the specified window

$timestamp : int

unix timestamp associated with the stored entry

save()

Persist the in-memory rate limit data to the configured JSON file.

private save() : void

Writes the current $data as pretty-printed JSON into $this->filename.

On this page

Search results