RateLimitInterface.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\filters;
  8. /**
  9. * RateLimitInterface is the interface that may be implemented by an identity object to enforce rate limiting.
  10. *
  11. * @author Qiang Xue <qiang.xue@gmail.com>
  12. * @since 2.0
  13. */
  14. interface RateLimitInterface
  15. {
  16. /**
  17. * Returns the maximum number of allowed requests and the window size.
  18. * @param \yii\web\Request $request the current request
  19. * @param \yii\base\Action $action the action to be executed
  20. * @return array an array of two elements. The first element is the maximum number of allowed requests,
  21. * and the second element is the size of the window in seconds.
  22. */
  23. public function getRateLimit($request, $action);
  24. /**
  25. * Loads the number of allowed requests and the corresponding timestamp from a persistent storage.
  26. * @param \yii\web\Request $request the current request
  27. * @param \yii\base\Action $action the action to be executed
  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. public function loadAllowance($request, $action);
  32. /**
  33. * Saves the number of allowed requests and the corresponding timestamp to a persistent storage.
  34. * @param \yii\web\Request $request the current request
  35. * @param \yii\base\Action $action the action to be executed
  36. * @param int $allowance the number of allowed requests remaining.
  37. * @param int $timestamp the current timestamp.
  38. */
  39. public function saveAllowance($request, $action, $allowance, $timestamp);
  40. }