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.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\ActionFilter
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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).

Открытые методы

Метод Описание
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.

Описание методов

addRateLimitHeaders() публичный Метод

Adds the rate limit headers to the response
public addRateLimitHeaders ( Response $response, integer $limit, integer $remaining, integer $reset )
$response yii\web\Response
$limit integer the maximum number of allowed requests during a period
$remaining integer the remaining number of allowed requests within the current period
$reset integer the number of seconds to wait before having maximum number of allowed requests again

beforeAction() публичный Метод

public beforeAction ( $action )

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

Описание свойств

$enableRateLimitHeaders публичное свойство

whether to include rate limit headers in the response
public $enableRateLimitHeaders

$errorMessage публичное свойство

the message to be displayed when rate limit exceeds
public $errorMessage

$request публичное свойство

the current request. If not set, the request application component will be used.
public $request

$response публичное свойство

the response to be sent. If not set, the response application component will be used.
public $response

$user публичное свойство

the user object that implements the RateLimitInterface. If not set, it will take the value of Yii::$app->user->getIdentity(false).
public $user