vendor/symfony/rate-limiter/LimiterInterface.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\RateLimiter;
  11. use Symfony\Component\RateLimiter\Exception\MaxWaitDurationExceededException;
  12. use Symfony\Component\RateLimiter\Exception\ReserveNotSupportedException;
  13. /**
  14. * @author Wouter de Jong <wouter@wouterj.nl>
  15. *
  16. * @experimental in 5.3
  17. */
  18. interface LimiterInterface
  19. {
  20. /**
  21. * Waits until the required number of tokens is available.
  22. *
  23. * The reserved tokens will be taken into account when calculating
  24. * future token consumptions. Do not use this method if you intend
  25. * to skip this process.
  26. *
  27. * @param int $tokens the number of tokens required
  28. * @param float $maxTime maximum accepted waiting time in seconds
  29. *
  30. * @throws MaxWaitDurationExceededException if $maxTime is set and the process needs to wait longer than its value (in seconds)
  31. * @throws ReserveNotSupportedException if this limiter implementation doesn't support reserving tokens
  32. * @throws \InvalidArgumentException if $tokens is larger than the maximum burst size
  33. */
  34. public function reserve(int $tokens = 1, float $maxTime = null): Reservation;
  35. /**
  36. * Use this method if you intend to drop if the required number
  37. * of tokens is unavailable.
  38. *
  39. * @param int $tokens the number of tokens required
  40. */
  41. public function consume(int $tokens = 1): RateLimit;
  42. /**
  43. * Resets the limit.
  44. */
  45. public function reset(): void;
  46. }