| 1 | <?php |
||
| 20 | abstract class AbstractRateLimiter implements RateLimiterInterface |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var int |
||
| 24 | */ |
||
| 25 | protected $limit; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var int |
||
| 29 | */ |
||
| 30 | protected $window; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $key; |
||
| 36 | |||
| 37 | 24 | public function __construct(int $limit, int $window) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 8 | public function getLimit() : int |
|
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | 2 | public function getWindow() : int |
|
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | 14 | public function hit(string $key) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * {@inheritdoc} |
||
| 80 | */ |
||
| 81 | 10 | public function getRemainingAttempts(string $key) : int |
|
| 85 | |||
| 86 | /** |
||
| 87 | * {@inheritdoc} |
||
| 88 | */ |
||
| 89 | 10 | public function getResetAt(string $key) : int |
|
| 93 | |||
| 94 | 14 | protected function getCurrent(string $key) : int |
|
| 98 | |||
| 99 | abstract protected function get(string $key, int $default) : int; |
||
| 100 | |||
| 101 | abstract protected function init(string $key); |
||
| 102 | |||
| 103 | abstract protected function increment(string $key); |
||
| 104 | |||
| 105 | abstract protected function ttl(string $key) : int; |
||
| 106 | } |
||
| 107 |