final class DatabaseRateLimiter implements RateLimiterInterface (View source)

Stores fixed-window buckets atomically in a MySQL or MariaDB table.

Constants

private TABLE

private SCOPE_MAX_LENGTH

Methods

__construct(Database $database, string $secret)

Initializes database persistence and the application secret used for bucket HMACs.

status(string $key, string $scope, RateLimitPolicy $policy)

Reads the current bucket state without creating or modifying a database row.

hit(string $key, string $scope, RateLimitPolicy $policy)

Atomically records an attempt and locks the resulting row until its decision is read.

void
clear(string $key)

Deletes the HMAC-addressed bucket for one opaque key.

void

Details

__construct

__construct(Database $database, string $secret)

Initializes database persistence and the application secret used for bucket HMACs.

Parameters

Database $database
string $secret

status

RateLimitResult status(string $key, string $scope, RateLimitPolicy $policy)

Reads the current bucket state without creating or modifying a database row.

Scope is validated but never persisted or otherwise applied by a status read.

Parameters

string $key
string $scope
RateLimitPolicy $policy

Return Value

RateLimitResult

hit

RateLimitResult hit(string $key, string $scope, RateLimitPolicy $policy)

Atomically records an attempt and locks the resulting row until its decision is read.

Scope replaces prior bucket metadata for the same HMAC-addressed bucket.

Parameters

string $key
string $scope
RateLimitPolicy $policy

Return Value

RateLimitResult

clear

void clear(string $key)

Deletes the HMAC-addressed bucket for one opaque key.

Parameters

string $key

Return Value

void