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 If not set, the request’s user IP will be used. |
| keyPrefix | string – Cache key prefix for storing allowance data |
| limit | integer – Maximum number of requests allowed within the window If not set, the config5:defaultRateLimit config setting will be used. |
| window | integer – Time window in seconds If not set, the config5:defaultRateLimitDuration config setting will be used. |
ip ​
- Type
- string
- Default value
null
The IP address to rate limit
If not set, the request’s user IP will be used.
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
If not set, the config5:defaultRateLimit config setting will be used.
window ​
- Type
- integer
- Default value
null
Time window in seconds
If not set, the config5:defaultRateLimitDuration config setting will be used.
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. |
| createDefault() | Returns a new identity configured with the default rate limit settings, or null if config5:defaultRateLimit is disabled. |
| 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. |
createDefault() ​
- Since
- 5.12.0
Returns a new identity configured with the default rate limit settings, or null if config5:defaultRateLimit is disabled.
Arguments ​
$keyPrefix(string) – The cache key prefix for storing allowance data
Returns ​
self, null
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.
init() ​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
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.