class Limit

Properties

mixed $key

The rate limit signature key.

int $maxAttempts

The maximum number of attempts allowed within the given number of seconds.

int $decaySeconds

The number of seconds until the rate limit is reset.

null|callable $afterCallback

The after callback used to determine if the limiter should be hit.

null|callable $responseCallback

The response generator callback.

Methods

__construct(mixed $key = '', int $maxAttempts = 60, int $decaySeconds = 60)

Create a new limit instance.

static Limit
perSecond(int $maxAttempts, int $decaySeconds = 1)

Create a new rate limit.

static Limit
perMinute(int $maxAttempts, int $decayMinutes = 1)

Create a new rate limit.

static Limit
perMinutes(int $decayMinutes, int $maxAttempts)

Create a new rate limit using minutes as decay time.

static Limit
perHour(int $maxAttempts, int $decayHours = 1)

Create a new rate limit using hours as decay time.

static Limit
perDay(int $maxAttempts, int $decayDays = 1)

Create a new rate limit using days as decay time.

static Unlimited
none()

Create a new unlimited rate limit.

by(mixed $key)

Set the key of the rate limit.

after(callable $callback)

Set the callback to determine if the limiter should be hit.

response(callable $callback)

Set the callback that should generate the response when the limit is exceeded.

string
fallbackKey()

Get a potential fallback key for the limit.

Details

at line 41
__construct(mixed $key = '', int $maxAttempts = 60, int $decaySeconds = 60)

Create a new limit instance.

Parameters

mixed $key
int $maxAttempts
int $decaySeconds

at line 51
static Limit perSecond(int $maxAttempts, int $decaySeconds = 1)

Create a new rate limit.

Parameters

int $maxAttempts
int $decaySeconds

Return Value

Limit

at line 59
static Limit perMinute(int $maxAttempts, int $decayMinutes = 1)

Create a new rate limit.

Parameters

int $maxAttempts
int $decayMinutes

Return Value

Limit

at line 67
static Limit perMinutes(int $decayMinutes, int $maxAttempts)

Create a new rate limit using minutes as decay time.

Parameters

int $decayMinutes
int $maxAttempts

Return Value

Limit

at line 75
static Limit perHour(int $maxAttempts, int $decayHours = 1)

Create a new rate limit using hours as decay time.

Parameters

int $maxAttempts
int $decayHours

Return Value

Limit

at line 83
static Limit perDay(int $maxAttempts, int $decayDays = 1)

Create a new rate limit using days as decay time.

Parameters

int $maxAttempts
int $decayDays

Return Value

Limit

at line 91
static Unlimited none()

Create a new unlimited rate limit.

Return Value

Unlimited

at line 99
Limit by(mixed $key)

Set the key of the rate limit.

Parameters

mixed $key

Return Value

Limit

at line 109
Limit after(callable $callback)

Set the callback to determine if the limiter should be hit.

Parameters

callable $callback

Return Value

Limit

at line 119
Limit response(callable $callback)

Set the callback that should generate the response when the limit is exceeded.

Parameters

callable $callback

Return Value

Limit

at line 129
string fallbackKey()

Get a potential fallback key for the limit.

Return Value

string