RateLimitInterface
API reference › yii › filters › RateLimitInterface
RateLimitInterface is the interface that may be implemented by an identity object to enforce rate limiting.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
getRateLimit() abstract | Returns the maximum number of allowed requests and the window size. | RateLimitInterface |
loadAllowance() abstract | Loads the number of allowed requests and the corresponding timestamp from a persistent storage. | RateLimitInterface |
saveAllowance() abstract | Saves the number of allowed requests and the corresponding timestamp to a persistent storage. | RateLimitInterface |
Method details
Section titled “Method details”getRateLimit()
Section titled “getRateLimit() ”abstract public function getRateLimit(yii\web\Request $request, yii\base\Action $action): arrayReturns the maximum number of allowed requests and the window size.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | yii\ | The current request |
$action | yii\ | The action to be executed |
Returns
array: An array of two elements. The first element is the maximum number of allowed requests, and the second element is the size of the window in seconds.
loadAllowance()
Section titled “loadAllowance() ”abstract public function loadAllowance(yii\web\Request $request, yii\base\Action $action): arrayLoads the number of allowed requests and the corresponding timestamp from a persistent storage.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | yii\ | The current request |
$action | yii\ | The action to be executed |
Returns
array: An array of two elements. The first element is the number of allowed requests, and the second element is the corresponding UNIX timestamp.
saveAllowance()
Section titled “saveAllowance() ”abstract public function saveAllowance(yii\web\Request $request, yii\base\Action $action, int $allowance, int $timestamp): mixedSaves the number of allowed requests and the corresponding timestamp to a persistent storage.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | yii\ | The current request |
$action | yii\ | The action to be executed |
$allowance | int | The number of allowed requests remaining. |
$timestamp | int | The current timestamp. |
Returns
mixed