| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- declare(strict_types=1);
- namespace App\Auth;
- /**
- * Process-local {@see ThrottleStore}. State is held in a private array;
- * lost when the worker (or process) exits. Used by unit tests and as the
- * default for environments that don't need cross-worker persistence.
- */
- final class InMemoryThrottleStore implements ThrottleStore
- {
- /**
- * @var array{
- * ip: array<string, array{count: int, lockedUntil: int}>,
- * username: array<string, array{count: int, lockedUntil: int}>
- * }
- */
- private array $state = ['ip' => [], 'username' => []];
- public function load(): array
- {
- return $this->state;
- }
- public function mutate(callable $fn): void
- {
- $this->state = $fn($this->state);
- }
- public function reset(): void
- {
- $this->state = ['ip' => [], 'username' => []];
- }
- }
|