Files
api/services/nginx/app/classes/ratelimit.php
T
Jeppe B 2a6a86c9c3 Resolve backend Qodana critical and high findings (#314)
Resolve recommended-profile Critical and High findings, retain narrow analyzer exceptions, and update the edge-broker WebSocket dependency to a non-vulnerable release.
2026-07-17 05:44:16 +02:00

29 lines
764 B
PHP

<?php
namespace classes;
use interfaces\ratelimit_i;
use objects\ratelimit_o;
class ratelimit implements ratelimit_i
{
private int $limit; // The number of requests allowed in the time period
public function __construct(int $defaultLimit, int $defaultTime)
{
$this->limit = $defaultLimit;
unset($defaultTime); // The reset interval is managed by the rate-limit maintenance task.
}
public function enforceIP(string $ip): bool
{
global $response;
$ratelimit = (new ratelimit_o())->getOrCreateRateLimitByIp($ip);
if ($ratelimit->count->value() >= $this->limit) {
$response->rate_limit_exceeded();
}
$ratelimit->increment($ratelimit->id, 1);
return true;
}
}