2
0

minor syntax tweaks

This commit is contained in:
Sky Johnson 2025-09-17 06:41:48 -05:00
parent 0f89376fa8
commit c7577ea492
3 changed files with 7 additions and 26 deletions

View File

@ -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
- Works with any PHP web server

View File

@ -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 = [])
{

View File

@ -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) {