| @@ 14-25 (lines=12) @@ | ||
| 11 | /** @var array */ |
|
| 12 | private $cache = []; |
|
| 13 | ||
| 14 | public function limit(string $identifier, Rate $rate): void |
|
| 15 | { |
|
| 16 | $key = $this->key($identifier, $rate->getInterval()); |
|
| 17 | ||
| 18 | $current = $this->getCurrent($key); |
|
| 19 | ||
| 20 | if ($current >= $rate->getOperations()) { |
|
| 21 | throw LimitExceeded::for($identifier, $rate); |
|
| 22 | } |
|
| 23 | ||
| 24 | $this->updateCounter($key, $rate->getInterval()); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function limitSilently(string $identifier, Rate $rate): Status |
|
| 28 | { |
|
| @@ 24-35 (lines=12) @@ | ||
| 21 | $this->keyPrefix = $keyPrefix; |
|
| 22 | } |
|
| 23 | ||
| 24 | public function limit(string $identifier, Rate $rate): void |
|
| 25 | { |
|
| 26 | $key = $this->key($identifier, $rate->getInterval()); |
|
| 27 | ||
| 28 | $current = $this->getCurrent($key); |
|
| 29 | ||
| 30 | if ($current >= $rate->getOperations()) { |
|
| 31 | throw LimitExceeded::for($identifier, $rate); |
|
| 32 | } |
|
| 33 | ||
| 34 | $this->updateCounter($key, $rate->getInterval()); |
|
| 35 | } |
|
| 36 | ||
| 37 | public function limitSilently(string $identifier, Rate $rate): Status |
|
| 38 | { |
|