RateLimitInterface.php 1.71 KB
Newer Older
Qiang Xue committed
1 2 3 4 5 6 7
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

8
namespace yii\filters;
Qiang Xue committed
9 10 11 12 13 14 15 16 17

/**
 * RateLimitInterface is the interface that may be implemented by an identity object to enforce rate limiting.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
interface RateLimitInterface
{
18 19
    /**
     * Returns the maximum number of allowed requests and the window size.
20 21
     * @param \yii\web\Request $request the current request
     * @param \yii\base\Action $action the action to be executed
22
     * @return array an array of two elements. The first element is the maximum number of allowed requests,
23
     * and the second element is the size of the window in seconds.
24
     */
25
    public function getRateLimit($request, $action);
26 27
    /**
     * Loads the number of allowed requests and the corresponding timestamp from a persistent storage.
28 29
     * @param \yii\web\Request $request the current request
     * @param \yii\base\Action $action the action to be executed
30
     * @return array an array of two elements. The first element is the number of allowed requests,
31
     * and the second element is the corresponding UNIX timestamp.
32
     */
33
    public function loadAllowance($request, $action);
34 35
    /**
     * Saves the number of allowed requests and the corresponding timestamp to a persistent storage.
36 37
     * @param \yii\web\Request $request the current request
     * @param \yii\base\Action $action the action to be executed
38 39 40
     * @param integer $allowance the number of allowed requests remaining.
     * @param integer $timestamp the current timestamp.
     */
41
    public function saveAllowance($request, $action, $allowance, $timestamp);
Qiang Xue committed
42
}