Spec-Zone.ru › Laravel 11

ThrottleRequests

класс ThrottleRequests (View source)

Свойства

InteractsWithTime

Свойства

protected RateLimiter $limiter

Экземпляр лимитера.

static protected bool $shouldHashKeys

Указывает, должны ли ключи лимитера быть хэшированы.

Методы

int secondsUntil(DateTimeInterface|DateInterval|int $delay)

Получить количество секунд до заданного DateTime.

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

Получить UNIX-временную метку «доступно в».

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

Если заданное значение является интервалом, преобразовать его в экземпляр DateTime.

from InteractsWithTime
int currentTime()

Получить текущее системное время в виде UNIX-временной метки.

from InteractsWithTime
string runTimeForHumans(float $startTime, float $endTime = null)

Задано начальное время, отформатировать общее время выполнения для удобного чтения человеком.

from InteractsWithTime
void __construct(RateLimiter $limiter)

Создать новый ограничитель запросов.

static string using(string $name)

Указать используемый именованный ограничитель запросов для промежуточного ПО.

static string with(int $maxAttempts = 60, int $decayMinutes = 1, string $prefix = '')

Указать конфигурацию ограничителя запросов для промежуточного ПО.

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

Обработать входящий запрос.

Response handleRequestUsingNamedLimiter(Request $request, Closure $next, string $limiterName, Closure $limiter)

Обработать входящий запрос.

Response handleRequest(Request $request, Closure $next, array $limits)

Обработать входящий запрос.

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

Определить количество попыток, если пользователь аутентифицирован или нет.

string resolveRequestSignature(Request $request)

Определить подпись запроса.

ThrottleRequestsException|HttpResponseException buildException(Request $request, string $key, int $maxAttempts, callable|null $responseCallback = null)

Создать исключение «слишком много попыток».

int getTimeUntilNextRetry(string $key)

Получить количество секунд до следующей попытки.

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

Добавить информацию заголовков лимита к заданному ответу.

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

Получить информацию заголовков лимита.

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

Рассчитать количество оставшихся попыток.

static void shouldHashKeys(bool $shouldHashKeys = true)

Указать, нужно ли хешировать ключи ограничителя запросов.

Details

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

Получить количество секунд до заданного DateTime.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

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

Получить UNIX-временную метку «доступно в».

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

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

Если заданное значение является интервалом, преобразовать его в экземпляр DateTime.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

DateTimeInterface|int

protected int currentTime()

Получить текущее системное время в виде UNIX-временной метки.

Return Value

int

protected string runTimeForHumans(float $startTime, float $endTime = null)

Учитывая начальное время, отформатируйте общее время выполнения для удобного чтения человеком.

Parameters

float $startTime
float $endTime

Return Value

string

void __construct(RateLimiter $limiter)

Создать новый ограничитель запросов.

Parameters

RateLimiter $limiter

Return Value

void

static string using(string $name)

Укажите используемый ограничитель запросов по имени для middleware.

Parameters

string $name

Return Value

string

static string with(int $maxAttempts = 60, int $decayMinutes = 1, string $prefix = '')

Укажите конфигурацию ограничителя запросов для middleware.

Parameters

int $maxAttempts
int $decayMinutes
string $prefix

Return Value

string

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

Обработать входящий запрос.

Parameters

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

Return Value

Response

Exceptions

ThrottleRequestsException
MissingRateLimiterException

protected Response handleRequestUsingNamedLimiter(Request $request, Closure $next, string $limiterName, Closure $limiter)

Обработать входящий запрос.

Parameters

Request $request
Closure $next
string $limiterName
Closure $limiter

Return Value

Response

Exceptions

ThrottleRequestsException

protected Response handleRequest(Request $request, Closure $next, array $limits)

Обработать входящий запрос.

Parameters

Request $request
Closure $next
array $limits

Return Value

Response

Exceptions

ThrottleRequestsException

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

Определите количество попыток, если пользователь аутентифицирован или нет.

Parameters

Request $request
int|string $maxAttempts

Return Value

int

Exceptions

MissingRateLimiterException

protected string resolveRequestSignature(Request $request)

Определить подпись запроса.

Parameters

Request $request

Return Value

string

Exceptions

RuntimeException

protected ThrottleRequestsException|HttpResponseException buildException(Request $request, string $key, int $maxAttempts, callable|null $responseCallback = null)

Создать исключение «слишком много попыток».

Parameters

Request $request
string $key
int $maxAttempts
callable|null $responseCallback

Return Value

ThrottleRequestsException|HttpResponseException

protected int getTimeUntilNextRetry(string $key)

Получить количество секунд до следующей попытки.

Parameters

string $key

Return Value

int

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

Добавить информацию о лимите в заголовки данного ответа.

Parameters

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

Return Value

Response

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

Получить информацию о заголовках лимитов.

Параметры

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

Возвращаемое значение

array

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

Вычислить количество оставшихся попыток.

Параметры

string $key
int $maxAttempts
int|null $retryAfter

Возвращаемое значение

int

static void shouldHashKeys(bool $shouldHashKeys = true)

Указать, нужно ли хешировать ключи лимита скорости.

Параметры

bool $shouldHashKeys

Возвращаемое значение

void

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

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API