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.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\ActionFilter
Datei anzeigen 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

addRateLimitHeaders() public method

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 method

public beforeAction ( $action )

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

$enableRateLimitHeaders public_oe property

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

$errorMessage public_oe property

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

$request public_oe property

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

$response public_oe property

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

$user public_oe property

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