PHP Класс 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.
Показать файл
Открыть проект
Примеры использования класса
Открытые свойства
Свойство |
Тип |
Описание |
|
$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). |
|
Открытые методы
Описание методов
beforeAction()
публичный Метод
checkRateLimit()
публичный Метод
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 |
Описание свойств
$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.
the user object that implements the RateLimitInterface.
If not set, it will take the value of Yii::$app->user->getIdentity(false).