RateLimitInterface.php 1.58 KB
Newer Older
Qiang Xue committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\rest;

/**
 * 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
     * @param array $params the additional parameters associated with the rate limit.
21
     * @return array an array of two elements. The first element is the maximum number of allowed requests,
22
     * and the second element is the size of the window in seconds.
23 24 25 26
     */
    public function getRateLimit($params = []);
    /**
     * Loads the number of allowed requests and the corresponding timestamp from a persistent storage.
27
     * @param array $params the additional parameters associated with the rate limit.
28
     * @return array an array of two elements. The first element is the number of allowed requests,
29
     * and the second element is the corresponding UNIX timestamp.
30 31 32 33 34 35
     */
    public function loadAllowance($params = []);
    /**
     * Saves the number of allowed requests and the corresponding timestamp to a persistent storage.
     * @param integer $allowance the number of allowed requests remaining.
     * @param integer $timestamp the current timestamp.
36
     * @param array $params the additional parameters associated with the rate limit.
37 38
     */
    public function saveAllowance($allowance, $timestamp, $params = []);
Qiang Xue committed
39
}