PHP Class yii\filters\RateLimiter
You may use RateLimiter by attaching it as a behavior to a controller or module, like the following,
php
public function behaviors()
{
return [
'rateLimiter' => [
'class' => \yii\filters\RateLimiter::className(),
],
];
}
When the user has exceeded his rate limit, RateLimiter will throw a [[TooManyRequestsHttpException]] exception.
Note that RateLimiter requires [[user]] to implement the
RateLimitInterface. RateLimiter will
do nothing if [[user]] is not set or does not implement
RateLimitInterface.
Mostrar archivo
Open project: yiisoft/yii2
Class Usage Examples
Public Properties
Property |
Type |
Description |
|
$enableRateLimitHeaders |
|
whether to include rate limit headers in the response |
|
$errorMessage |
|
the message to be displayed when rate limit exceeds |
|
$request |
|
the current request. If not set, the request application component will be used. |
|
$response |
|
the response to be sent. If not set, the response application component will be used. |
|
$user |
|
the user object that implements the RateLimitInterface.
If not set, it will take the value of Yii::$app->user->getIdentity(false). |
|
Public Methods
Method |
Description |
|
addRateLimitHeaders ( Response $response, integer $limit, integer $remaining, integer $reset ) |
Adds the rate limit headers to the response |
|
beforeAction ( $action ) |
|
|
checkRateLimit ( yii\filters\RateLimitInterface $user, Request $request, Response $response, Action $action ) |
Checks whether the rate limit exceeds. |
|
Method Details
beforeAction()
public method
checkRateLimit()
public method
Checks whether the rate limit exceeds.
public checkRateLimit ( yii\filters\RateLimitInterface $user, Request $request, Response $response, Action $action ) |
$user |
yii\filters\RateLimitInterface |
the current user |
$request |
yii\web\Request |
|
$response |
yii\web\Response |
|
$action |
yii\base\Action |
the action to be executed |
Property Details
$errorMessage public_oe property
the message to be displayed when rate limit exceeds
$request public_oe property
the current request. If not set, the request application component will be used.
$response public_oe property
the response to be sent. If not set, the response application component will be used.
the user object that implements the RateLimitInterface.
If not set, it will take the value of Yii::$app->user->getIdentity(false).