ThrottleRequestsWithRedis

class ThrottleRequestsWithRedis extends ThrottleRequests (View source)

Traits

InteractsWithTime

Properties

protected RateLimiter $limiter The rate limiter instance. from ThrottleRequests
protected Factory $redis The Redis factory implementation.
int $decaysAt The timestamp of the end of the current duration.
int $remaining The number of remaining slots.

Methods

int secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

from InteractsWithTime
int availableAt(DateTimeInterface|DateInterval|int $delay = 0)

Get the "available at" UNIX timestamp.

from InteractsWithTime
DateTimeInterface|int parseDateInterval(DateTimeInterface|DateInterval|int $delay)

If the given value is an interval, convert it to a DateTime instance.

from InteractsWithTime
int currentTime()

Get the current system time as a UNIX timestamp.

from InteractsWithTime
void __construct(Factory $redis)

Create a new request throttler.

Response handle(Request $request, Closure $next, int|string $maxAttempts = 60, float|int $decayMinutes = 1)

Handle an incoming request.

int resolveMaxAttempts(Request $request, int|string $maxAttempts)

Resolve the number of attempts if the user is authenticated or not.

from ThrottleRequests
string resolveRequestSignature(Request $request)

Resolve request signature.

from ThrottleRequests
ThrottleRequestsException buildException(string $key, int $maxAttempts)

Create a 'too many attempts' exception.

from ThrottleRequests
int getTimeUntilNextRetry(string $key)

Get the number of seconds until the lock is released.

Response addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)

Add the limit header information to the given response.

from ThrottleRequests
array getHeaders(int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)

Get the limit headers information.

from ThrottleRequests
int calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)

Calculate the number of remaining attempts.

mixed tooManyAttempts(string $key, int $maxAttempts, int $decayMinutes)

Determine if the given key has been "accessed" too many times.

Details

protected int secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

protected int availableAt(DateTimeInterface|DateInterval|int $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

protected DateTimeInterface|int parseDateInterval(DateTimeInterface|DateInterval|int $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

DateTimeInterface|int

protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

void __construct(Factory $redis)

Create a new request throttler.

Parameters

Factory $redis

Return Value

void

Response handle(Request $request, Closure $next, int|string $maxAttempts = 60, float|int $decayMinutes = 1)

Handle an incoming request.

Parameters

Request $request
Closure $next
int|string $maxAttempts
float|int $decayMinutes

Return Value

Response

Exceptions

HttpException

protected int resolveMaxAttempts(Request $request, int|string $maxAttempts)

Resolve the number of attempts if the user is authenticated or not.

Parameters

Request $request
int|string $maxAttempts

Return Value

int

protected string resolveRequestSignature(Request $request)

Resolve request signature.

Parameters

Request $request

Return Value

string

Exceptions

RuntimeException

protected ThrottleRequestsException buildException(string $key, int $maxAttempts)

Create a 'too many attempts' exception.

Parameters

string $key
int $maxAttempts

Return Value

ThrottleRequestsException

protected int getTimeUntilNextRetry(string $key)

Get the number of seconds until the lock is released.

Parameters

string $key

Return Value

int

protected Response addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)

Add the limit header information to the given response.

Parameters

Response $response
int $maxAttempts
int $remainingAttempts
int|null $retryAfter

Return Value

Response

protected array getHeaders(int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)

Get the limit headers information.

Parameters

int $maxAttempts
int $remainingAttempts
int|null $retryAfter

Return Value

array

protected int calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)

Calculate the number of remaining attempts.

Parameters

string $key
int $maxAttempts
int|null $retryAfter

Return Value

int

protected mixed tooManyAttempts(string $key, int $maxAttempts, int $decayMinutes)

Determine if the given key has been "accessed" too many times.

Parameters

string $key
int $maxAttempts
int $decayMinutes

Return Value

mixed

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.7/Illuminate/Routing/Middleware/ThrottleRequestsWithRedis.html