From c7577ea492cc760d63b3f93840e734e19855458c Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Wed, 17 Sep 2025 06:41:48 -0500 Subject: [PATCH] minor syntax tweaks --- README.md | 17 +---------------- auth/Auth.php | 6 +++--- auth/AuthMiddleware.php | 10 +++------- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 7b24a99..8642d1d 100644 --- a/README.md +++ b/README.md @@ -206,21 +206,6 @@ rateLimit(int $maxAttempts = 60, int $decayMinutes = 1): callable verifyCsrf(): callable ``` -## Features - -- **High Performance**: Tree-based router with O(1) lookup complexity -- **Minimal Overhead**: Lightweight design with essential features only -- **Method Chaining**: Fluent API for response building -- **Middleware Support**: Pre/post request processing -- **Route Groups**: Organize routes with shared prefixes and middleware -- **Input Validation**: Comprehensive validation with built-in rules -- **Authentication**: Session-based auth with remember tokens -- **Error Handling**: Custom error pages with debug support -- **CSRF Protection**: Built-in CSRF token generation and validation -- **Flash Messages**: One-time notifications between requests -- **Rate Limiting**: Configurable rate limiting per user/IP -- **Content Negotiation**: Automatic JSON/HTML response selection - ## Documentation - **[EXAMPLES.md](EXAMPLES.md)** - Comprehensive examples and usage patterns @@ -231,4 +216,4 @@ verifyCsrf(): callable - PHP 8.1+ (uses enums and modern syntax) - No external dependencies -- Works with any PHP web server \ No newline at end of file +- Works with any PHP web server diff --git a/auth/Auth.php b/auth/Auth.php index 2f9d486..984e42a 100644 --- a/auth/Auth.php +++ b/auth/Auth.php @@ -12,9 +12,9 @@ class Auth private ?User $user = null; private array $config; - const SESSION_KEY = 'auth_user_data'; - const REMEMBER_COOKIE = 'remember_token'; - const REMEMBER_DURATION = 2592000; // 30 days in seconds + public const string SESSION_KEY = 'auth_user_data'; + public const string REMEMBER_COOKIE = 'remember_token'; + public const int REMEMBER_DURATION = 2592000; // 30 days in seconds public function __construct(Session $session, ?Cookies $cookie = null, array $config = []) { diff --git a/auth/AuthMiddleware.php b/auth/AuthMiddleware.php index 17e3aec..5a99a76 100644 --- a/auth/AuthMiddleware.php +++ b/auth/AuthMiddleware.php @@ -111,20 +111,16 @@ class AuthMiddleware public function rateLimit(int $maxAttempts = 60, int $decayMinutes = 1): callable { return function(Context $context, callable $next) use ($maxAttempts, $decayMinutes) { - if ($this->auth->guest()) { - $identifier = $context->request->ip(); - } else { - $identifier = 'user:' . $this->auth->id(); - } + $identifier = $this->auth->guest() ? $context->request->ip() : 'user:' . $this->auth->id(); $key = 'rate_limit:' . $identifier . ':' . $context->request->path; $attempts = $context->session->get($key, 0); - $resetTime = $context->session->get($key . ':reset', 0); + $resetTime = $context->session->get("$key:reset", 0); // Reset counter if decay time has passed if (time() > $resetTime) { $attempts = 0; - $context->session->set($key . ':reset', time() + ($decayMinutes * 60)); + $context->session->set("$key:reset", time() + $decayMinutes * 60); } if ($attempts >= $maxAttempts) {