RateLimiter
in package
FinalYes
Table of Contents
Constants
- CACHE_TAG : mixed = 'rate_limit'
Properties
- $key : string
- $maxAttempts : int
- $windowSeconds : int
Methods
- __construct() : mixed
- attempt() : bool
- Check-and-record: records a hit unless already over budget. Returns true when the request is allowed, false when blocked.
- attempts() : int
- Number of hits still inside the window.
- clear() : void
- Forget every hit for this key.
- hit() : void
- Record a single hit. For check-up-front / record-on-failure flows where the check and the record happen at different points (see Mage_Sales_Helper_Guest).
- remaining() : int
- Hits left before the next one blocks.
- tooManyAttempts() : bool
- True when the key is at or over its budget. Pure read, records nothing.
- cacheId() : string
- loadHits() : array<int, int>
Constants
CACHE_TAG
public
mixed
CACHE_TAG
= 'rate_limit'
Properties
$key read-only
private
string
$key
$maxAttempts read-only
private
int
$maxAttempts
$windowSeconds read-only
private
int
$windowSeconds
Methods
__construct()
public
__construct(string $key, int $maxAttempts, int $windowSeconds) : mixed
Parameters
- $key : string
- $maxAttempts : int
- $windowSeconds : int
attempt()
Check-and-record: records a hit unless already over budget. Returns true when the request is allowed, false when blocked.
public
attempt() : bool
Return values
boolattempts()
Number of hits still inside the window.
public
attempts() : int
Return values
intclear()
Forget every hit for this key.
public
clear() : void
hit()
Record a single hit. For check-up-front / record-on-failure flows where the check and the record happen at different points (see Mage_Sales_Helper_Guest).
public
hit() : void
remaining()
Hits left before the next one blocks.
public
remaining() : int
Return values
inttooManyAttempts()
True when the key is at or over its budget. Pure read, records nothing.
public
tooManyAttempts() : bool
Return values
boolcacheId()
private
cacheId() : string
Return values
stringloadHits()
private
loadHits() : array<int, int>