Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/docs/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Adds `X-Content-Type-Options`, `X-Frame-Options`, `Referrer-Policy`, and `Permis
```php
use Quill\Middleware\RateLimiter;

$app->use(new RateLimiter(maxRequests: 100, windowSeconds: 60));
$app->use(RateLimiter::withMemory(limit: 100, window: 60));
```

---
Expand Down
8 changes: 8 additions & 0 deletions src/Middleware/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public function __construct(
$this->keyResolver = $keyResolver;
}

/**
* Named factory for in-memory storage (most common).
*/
public static function withMemory(int $limit = 60, int $window = 60): self
{
return new self(new InMemoryRateLimitStorage(), $limit, $window);
}

public function __invoke(Request $request, callable $next): mixed
{
return $this->handle($request, $next);
Expand Down
Loading