SlidingWindow
class SlidingWindow extends AdmissionPolicy
Constants
| MAX_INTEGER |
The largest integer represented exactly by every first-party store. |
| private MAX_ATTEMPTS |
|
Methods
Create a new sliding-window limit.
Apply the policy without a named limiter scope.
Set the callback that determines whether the operation should be consumed.
Set the callback that generates a response when the limit is exceeded.
Create a copy with the given shared policy values.
Convert a caller key to its canonical string value.
Validate a positive shared integer.
Multiply positive rate limit values without losing integer precision.
Create a new per-second sliding-window limit.
Create a new per-minute sliding-window limit.
Create a new sliding-window limit using minutes as the window.
Create a new per-hour sliding-window limit.
Create a new per-day sliding-window limit.
Details
at line 19
__construct(int $maxAttempts = 60, int $windowSeconds = 60, string $key = '', int $cost = 1, bool $global = false, Closure|null $afterCallback = null, Closure|null $responseCallback = null)
Create a new sliding-window limit.
in
AdmissionPolicy at line 37
AdmissionPolicy
by(Stringable|UnitEnum|string|int|null $key)
Set the key of the rate limit.
in
AdmissionPolicy at line 51
AdmissionPolicy
cost(int $cost)
Set the capacity consumed by each operation.
in
AdmissionPolicy at line 70
AdmissionPolicy
globally(bool $global = true)
Apply the policy without a named limiter scope.
in
AdmissionPolicy at line 84
AdmissionPolicy
after(callable $callback)
Set the callback that determines whether the operation should be consumed.
in
AdmissionPolicy at line 98
AdmissionPolicy
response(callable $callback)
Set the callback that generates a response when the limit is exceeded.
at line 93
protected AdmissionPolicy
newInstance(string $key, int $cost, bool $global, Closure|null $afterCallback, Closure|null $responseCallback)
Create a copy with the given shared policy values.
in
AdmissionPolicy at line 123
protected string
normalizeKey(Stringable|UnitEnum|string|int|null $key)
Convert a caller key to its canonical string value.
in
AdmissionPolicy at line 135
static protected void
ensurePositive(string $name, int $value)
Validate a positive shared integer.
in
AdmissionPolicy at line 149
static protected int
multiply(int $value, int $multiplier, string $name)
Multiply positive rate limit values without losing integer precision.
at line 47
static SlidingWindow
perSecond(int $maxAttempts, int $windowSeconds = 1)
Create a new per-second sliding-window limit.
at line 55
static SlidingWindow
perMinute(int $maxAttempts, int $windowMinutes = 1)
Create a new per-minute sliding-window limit.
at line 65
static SlidingWindow
perMinutes(int $windowMinutes, int $maxAttempts)
Create a new sliding-window limit using minutes as the window.
at line 73
static SlidingWindow
perHour(int $maxAttempts, int $windowHours = 1)
Create a new per-hour sliding-window limit.
at line 83
static SlidingWindow
perDay(int $maxAttempts, int $windowDays = 1)
Create a new per-day sliding-window limit.