ThrottleRequestsWithRedis
extends ThrottleRequests
in package
Table of Contents
- $decaysAt : int
- The timestamp of the end of the current duration.
- $remaining : int
- The number of remaining slots.
- $limiter : RateLimiter
- The rate limiter instance.
- $redis : Factory
- The Redis factory implementation.
- __construct() : void
- Create a new request throttler.
- handle() : mixed
- Handle an incoming request.
- addHeaders() : Response
- Add the limit header information to the given response.
- availableAt() : int
- Get the "available at" UNIX timestamp.
- buildException() : HttpException
- Create a 'too many attempts' exception.
- calculateRemainingAttempts() : int
- Calculate the number of remaining attempts.
- currentTime() : int
- Get the current system time as a UNIX timestamp.
- getHeaders() : array<string|int, mixed>
- Get the limit headers information.
- getTimeUntilNextRetry() : int
- Get the number of seconds until the lock is released.
- parseDateInterval() : DateTimeInterface|int
- If the given value is an interval, convert it to a DateTime instance.
- resolveMaxAttempts() : int
- Resolve the number of attempts if the user is authenticated or not.
- resolveRequestSignature() : string
- Resolve request signature.
- secondsUntil() : int
- Get the number of seconds until the given DateTime.
- tooManyAttempts() : mixed
- Determine if the given key has been "accessed" too many times.
Properties
$decaysAt
The timestamp of the end of the current duration.
public
int
$decaysAt
$remaining
The number of remaining slots.
public
int
$remaining
$limiter
The rate limiter instance.
protected
RateLimiter
$limiter
$redis
The Redis factory implementation.
protected
Factory
$redis
Methods
__construct()
Create a new request throttler.
public
__construct(Factory $redis) : void
Parameters
- $redis : Factory
Return values
void —handle()
Handle an incoming request.
public
handle(Request $request, Closure $next[, int|string $maxAttempts = 60 ][, float|int $decayMinutes = 1 ]) : mixed
Parameters
- $request : Request
- $next : Closure
- $maxAttempts : int|string = 60
- $decayMinutes : float|int = 1
Tags
Return values
mixed —addHeaders()
Add the limit header information to the given response.
protected
addHeaders(Response $response, int $maxAttempts, int $remainingAttempts[, int|null $retryAfter = null ]) : Response
Parameters
- $response : Response
- $maxAttempts : int
- $remainingAttempts : int
- $retryAfter : int|null = null
Return values
Response —availableAt()
Get the "available at" UNIX timestamp.
protected
availableAt(DateTimeInterface|DateInterval|int $delay) : int
Parameters
- $delay : DateTimeInterface|DateInterval|int
Return values
int —buildException()
Create a 'too many attempts' exception.
protected
buildException(string $key, int $maxAttempts) : HttpException
Parameters
- $key : string
- $maxAttempts : int
Return values
HttpException —calculateRemainingAttempts()
Calculate the number of remaining attempts.
protected
calculateRemainingAttempts(string $key, int $maxAttempts[, int|null $retryAfter = null ]) : int
Parameters
- $key : string
- $maxAttempts : int
- $retryAfter : int|null = null
Return values
int —currentTime()
Get the current system time as a UNIX timestamp.
protected
currentTime() : int
Return values
int —getHeaders()
Get the limit headers information.
protected
getHeaders(int $maxAttempts, int $remainingAttempts[, int|null $retryAfter = null ]) : array<string|int, mixed>
Parameters
- $maxAttempts : int
- $remainingAttempts : int
- $retryAfter : int|null = null
Return values
array<string|int, mixed> —getTimeUntilNextRetry()
Get the number of seconds until the lock is released.
protected
getTimeUntilNextRetry(string $key) : int
Parameters
- $key : string
Return values
int —parseDateInterval()
If the given value is an interval, convert it to a DateTime instance.
protected
parseDateInterval(DateTimeInterface|DateInterval|int $delay) : DateTimeInterface|int
Parameters
- $delay : DateTimeInterface|DateInterval|int
Return values
DateTimeInterface|int —resolveMaxAttempts()
Resolve the number of attempts if the user is authenticated or not.
protected
resolveMaxAttempts(Request $request, int|string $maxAttempts) : int
Parameters
- $request : Request
- $maxAttempts : int|string
Return values
int —resolveRequestSignature()
Resolve request signature.
protected
resolveRequestSignature(Request $request) : string
Parameters
- $request : Request
Tags
Return values
string —secondsUntil()
Get the number of seconds until the given DateTime.
protected
secondsUntil(DateTimeInterface|DateInterval|int $delay) : int
Parameters
- $delay : DateTimeInterface|DateInterval|int
Return values
int —tooManyAttempts()
Determine if the given key has been "accessed" too many times.
protected
tooManyAttempts(string $key, int $maxAttempts, int $decayMinutes) : mixed
Parameters
- $key : string
- $maxAttempts : int
- $decayMinutes : int