ThrottleRequestsWithRedis
класс ThrottleRequestsWithRedis расширяет ThrottleRequests (View source)
Traits
| InteractsWithTime |
Properties
| protected RateLimiter | $limiter | Экземпляр ограничителя скорости. | from ThrottleRequests |
| static protected bool | $shouldHashKeys | Указывает, следует ли хешировать ключи ограничителя скорости. | from ThrottleRequests |
| protected Factory | $redis | Реализация фабрики Redis. | |
| array | $decaysAt | Метка времени окончания текущего периода по ключу. | |
| array | $remaining | Количество оставшихся слотов по ключу. |
Methods
| int | secondsUntil(DateTimeInterface|DateInterval|int $delay)
Получить количество секунд до заданной даты и времени. | 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, Factory $redis)
Создать новый ограничитель запросов. | |
| static string | using(string $name)
Указать именованный ограничитель скорости для использования в промежуточном ПО. | from ThrottleRequests |
| static string | with(int $maxAttempts = 60, int $decayMinutes = 1, string $prefix = '')
Указать конфигурацию ограничителя скорости для промежуточного ПО. | from ThrottleRequests |
| Response | handle(Request $request, Closure $next, int|string $maxAttempts = 60, float|int $decayMinutes = 1, string $prefix = '')
Обработать входящий запрос. | from ThrottleRequests |
| Response | handleRequestUsingNamedLimiter(Request $request, Closure $next, string $limiterName, Closure $limiter)
Обработать входящий запрос. | from ThrottleRequests |
| Response | handleRequest(Request $request, Closure $next, array $limits)
Обработать входящий запрос. | |
| int | resolveMaxAttempts(Request $request, int|string $maxAttempts)
Определить количество попыток, если пользователь аутентифицирован или нет. | from ThrottleRequests |
| string | resolveRequestSignature(Request $request)
Определить сигнатуру запроса. | from ThrottleRequests |
| ThrottleRequestsException|HttpResponseException | buildException(Request $request, string $key, int $maxAttempts, callable|null $responseCallback = null)
Создать исключение "слишком много попыток". | from ThrottleRequests |
| int | getTimeUntilNextRetry(string $key)
Получить количество секунд до снятия блокировки. | |
| Response | addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)
Добавить информацию о заголовке лимита в заданный ответ. | from ThrottleRequests |
| array | getHeaders(int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null, Response|null $response = null)
Получить информацию о заголовках лимита. | from ThrottleRequests |
| int | calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)
Вычислить количество оставшихся попыток. | |
| static void | shouldHashKeys(bool $shouldHashKeys = true)
Указать, следует ли хешировать ключи ограничителя скорости. | from ThrottleRequests |
| mixed | tooManyAttempts(string $key, int $maxAttempts, int $decaySeconds)
Определить, был ли заданный ключ "доступен" слишком много раз. | |
| Connection | getRedisConnection()
Получить подключение Redis, которое следует использовать для ограничения. |
Details
protected int secondsUntil(DateTimeInterface|DateInterval|int $delay)
Получить количество секунд до заданной даты и времени.
protected int availableAt(DateTimeInterface|DateInterval|int $delay = 0)
Получить отметку времени (UNIX timestamp) доступности.
protected DateTimeInterface|int parseDateInterval(DateTimeInterface|DateInterval|int $delay)
Если заданное значение является интервалом, преобразовать его в экземпляр DateTime.
protected int currentTime()
Получить текущее системное время как UNIX timestamp.
protected string runTimeForHumans(float $startTime, float $endTime = null)
Дано начальное время, отформатировать общее время выполнения для чтения человеком.
void __construct(RateLimiter $limiter, Factory $redis)
Создать новый ограничитель запросов.
static string using(string $name)
Указать используемый ограничитель запросов по имени.
static string with(int $maxAttempts = 60, int $decayMinutes = 1, string $prefix = '')
Указать конфигурацию ограничителя запросов для middleware.
Response handle(Request $request, Closure $next, int|string $maxAttempts = 60, float|int $decayMinutes = 1, string $prefix = '')
Обработать входящий запрос.
protected Response handleRequestUsingNamedLimiter(Request $request, Closure $next, string $limiterName, Closure $limiter)
Обработать входящий запрос.
protected Response handleRequest(Request $request, Closure $next, array $limits)
Обработать входящий запрос.
protected int resolveMaxAttempts(Request $request, int|string $maxAttempts)
Определить количество попыток, если пользователь авторизован или нет.
protected string resolveRequestSignature(Request $request)
Разрешить подпись запроса.
protected ThrottleRequestsException|HttpResponseException buildException(Request $request, string $key, int $maxAttempts, callable|null $responseCallback = null)
Создать исключение «слишком много попыток».
protected int getTimeUntilNextRetry(string $key)
Получить количество секунд до снятия блокировки.
protected Response addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)
Добавить информацию заголовков лимита в заданный ответ.
protected array getHeaders(int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null, Response|null $response = null)
Получить информацию заголовков лимита.
protected int calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)
Рассчитать количество оставшихся попыток.
static void shouldHashKeys(bool $shouldHashKeys = true)
Указать, должны ли ключи ограничителя скорости быть хэшированы.
protected mixed tooManyAttempts(string $key, int $maxAttempts, int $decaySeconds)
Определить, было ли заданный ключ «обращен» слишком много раз.
protected Connection getRedisConnection()
Получить соединение Redis, которое следует использовать для ограничения скорости.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/11.x/Illuminate/Routing/Middleware/ThrottleRequestsWithRedis.html