| @@ 17-27 (lines=11) @@ | ||
| 14 | $this->rateLimiter = $rateLimiter; |
|
| 15 | } |
|
| 16 | ||
| 17 | public static function perSecond(int $limit, Store $store = null): RateLimiterMiddleware |
|
| 18 | { |
|
| 19 | $rateLimiter = new RateLimiter( |
|
| 20 | $limit, |
|
| 21 | RateLimiter::TIME_FRAME_SECOND, |
|
| 22 | $store ?? new InMemoryStore(), |
|
| 23 | new SleepDeferrer() |
|
| 24 | ); |
|
| 25 | ||
| 26 | return new static($rateLimiter); |
|
| 27 | } |
|
| 28 | ||
| 29 | public static function perMinute(int $limit, Store $store = null): RateLimiterMiddleware |
|
| 30 | { |
|
| @@ 29-39 (lines=11) @@ | ||
| 26 | return new static($rateLimiter); |
|
| 27 | } |
|
| 28 | ||
| 29 | public static function perMinute(int $limit, Store $store = null): RateLimiterMiddleware |
|
| 30 | { |
|
| 31 | $rateLimiter = new RateLimiter( |
|
| 32 | $limit, |
|
| 33 | RateLimiter::TIME_FRAME_MINUTE, |
|
| 34 | $store ?? new InMemoryStore(), |
|
| 35 | new SleepDeferrer() |
|
| 36 | ); |
|
| 37 | ||
| 38 | return new static($rateLimiter); |
|
| 39 | } |
|
| 40 | ||
| 41 | public function __invoke(callable $handler) |
|
| 42 | { |
|