IpRateLimitIdentity ​
- Type
- Class
- Namespace
- craft\filters
- Inherits
- craft\filters\IpRateLimitIdentity » yii\base\BaseObject
- Implements
- yii\base\Configurable, yii\filters\RateLimitInterface
- Since
- 5.9.15
IP-based rate limit identity for use with RateLimiter.
This class implements RateLimitInterface to provide IP-based rate limiting for unauthenticated requests, using cache storage for allowance tracking.
Public Properties ​
| Property | Description |
|---|---|
| ip | string – The IP address to rate limit |
| keyPrefix | string – Cache key prefix for storing allowance data |
| limit | integer – Maximum number of requests allowed within the window |
| window | integer – Time window in seconds |
ip ​
- Type
- string
- Default value
null
The IP address to rate limit
keyPrefix ​
- Type
- string
- Default value
null
Cache key prefix for storing allowance data
limit ​
- Type
- integer
- Default value
null
Maximum number of requests allowed within the window
window ​
- Type
- integer
- Default value
null
Time window in seconds
Public Methods ​
| Method | Description |
|---|---|
| __call() | Calls the named method which is not a class method. |
| __construct() | Constructor. |
| __get() | Returns the value of an object property. |
| __isset() | Checks if a property is set, i.e. defined and not null. |
| __set() | Sets value of an object property. |
| __unset() | Sets an object property to null. |
| canGetProperty() | Returns a value indicating whether a property can be read. |
| canSetProperty() | Returns a value indicating whether a property can be set. |
| className() | Returns the fully qualified name of this class. |
| getRateLimit() | Returns the maximum number of allowed requests and the window size. |
| hasMethod() | Returns a value indicating whether a method is defined. |
| hasProperty() | Returns a value indicating whether a property is defined. |
| init() | Initializes the object. |
| loadAllowance() | Loads the number of allowed requests and the corresponding timestamp from a persistent storage. |
| saveAllowance() | Saves the number of allowed requests and the corresponding timestamp to a persistent storage. |
getRateLimit() ​
Returns the maximum number of allowed requests and the window size.
Arguments ​
$request(yii\web\Request) – The current request$action(yii\base\Action) – 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() ​
Loads the number of allowed requests and the corresponding timestamp from a persistent storage.
Arguments ​
$request(yii\web\Request) – The current request$action(yii\base\Action) – 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() ​
Saves the number of allowed requests and the corresponding timestamp to a persistent storage.
Arguments ​
$request(yii\web\Request) – The current request$action(yii\base\Action) – The action to be executed$allowance(integer) – The number of allowed requests remaining.$timestamp(integer) – The current timestamp.