From 97f4144d676e370f298992543b4241b326bc0fb6 Mon Sep 17 00:00:00 2001 From: fr3on Date: Sun, 5 Apr 2026 18:36:24 +0200 Subject: [PATCH] fix(middleware): add withMemory static factory to RateLimiter and update docs --- .github/docs/middleware.md | 2 +- src/Middleware/RateLimiter.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/docs/middleware.md b/.github/docs/middleware.md index dfd36f8..7b806f3 100644 --- a/.github/docs/middleware.md +++ b/.github/docs/middleware.md @@ -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)); ``` --- diff --git a/src/Middleware/RateLimiter.php b/src/Middleware/RateLimiter.php index c6f864b..2f406c9 100644 --- a/src/Middleware/RateLimiter.php +++ b/src/Middleware/RateLimiter.php @@ -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);