ThrottleRequestsWithRedis
class ThrottleRequestsWithRedis extends ThrottleRequests
Traits
Properties
| protected RateLimiter | $limiter | The rate limiter instance. |
from ThrottleRequests |
| static protected bool | $shouldHashKeys | Indicates if the rate limiter keys should be hashed. |
from ThrottleRequests |
| protected Factory | $redis | The Redis factory implementation. |
|
| array | $decaysAt | The timestamp of the end of the current duration by key. |
|
| array | $remaining | The number of remaining slots by key. |
Methods
Get the number of seconds until the given DateTime.
Get the "available at" UNIX timestamp.
If the given value is an interval, convert it to a DateTime instance.
Given a start time, format the total run time for human readability.
Specify the named rate limiter to use for the middleware.
Specify the rate limiter configuration for the middleware.
Handle an incoming request.
Handle an incoming request using a named limiter.
Resolve the number of attempts if the user is authenticated or not.
Create a 'too many attempts' exception.
Get the number of seconds until the next retry.
Add the limit header information to the given response.
Get the limit headers information.
Calculate the number of remaining attempts.
Specify whether rate limiter keys should be hashed.
Determine if the given key has been "accessed" too many times.
Get the Redis connection that should be used for throttling.
Details
in
InteractsWithTime at line 17
protected int
secondsUntil(DateInterval|DateTimeInterface|int $delay)
Get the number of seconds until the given DateTime.
in
InteractsWithTime at line 29
protected int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)
Get the "available at" UNIX timestamp.
in
InteractsWithTime at line 41
protected DateTimeInterface|int
parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)
If the given value is an interval, convert it to a DateTime instance.
in
InteractsWithTime at line 57
protected int
currentTime()
Get the current system time as a UNIX timestamp.
in
InteractsWithTime at line 65
protected string
runTimeForHumans(float $startTime, float|null $endTime = null)
Given a start time, format the total run time for human readability.
at line 35
__construct(RateLimiter $limiter, Factory $redis)
Create a new request throttler.
in
ThrottleRequests at line 47
static string
using(UnitEnum|string $name)
Specify the named rate limiter to use for the middleware.
in
ThrottleRequests at line 57
static string
with(int $maxAttempts = 60, int $decayMinutes = 1, string $prefix = '')
Specify the rate limiter configuration for the middleware.
in
ThrottleRequests at line 68
Response
handle(Request $request, Closure $next, int|string $maxAttempts = 60, float|int|string $decayMinutes = 1, string $prefix = '')
Handle an incoming request.
in
ThrottleRequests at line 96
protected Response
handleRequestUsingNamedLimiter(Request $request, Closure $next, string $limiterName, Closure $limiter)
Handle an incoming request using a named limiter.
at line 47
protected Response
handleRequest(Request $request, Closure $next, array $limits)
Handle an incoming request.
in
ThrottleRequests at line 167
protected int
resolveMaxAttempts(Request $request, int|string $maxAttempts)
Resolve the number of attempts if the user is authenticated or not.
in
ThrottleRequests at line 194
protected string
resolveRequestSignature(Request $request)
Resolve request signature.
in
ThrottleRequests at line 209
protected ThrottleRequestsException|HttpResponseException
buildException(Request $request, string $key, int $maxAttempts, callable|null $responseCallback = null)
Create a 'too many attempts' exception.
at line 98
protected int
getTimeUntilNextRetry(string $key)
Get the number of seconds until the next retry.
in
ThrottleRequests at line 235
protected Response
addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)
Add the limit header information to the given response.
in
ThrottleRequests at line 247
protected array
getHeaders(int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null, Response|null $response = null)
Get the limit headers information.
at line 90
protected int
calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)
Calculate the number of remaining attempts.
in
ThrottleRequests at line 290
static void
shouldHashKeys(bool $shouldHashKeys = true)
Specify whether rate limiter keys should be hashed.
Boot-only. The flag persists in a static property for the worker lifetime and applies to every subsequent request.
in
ThrottleRequests at line 298
static void
flushState()
Flush all static state.
at line 71
protected bool
tooManyAttempts(string $key, int $maxAttempts, int $decaySeconds)
Determine if the given key has been "accessed" too many times.
at line 106
protected RedisProxy
getRedisConnection()
Get the Redis connection that should be used for throttling.