-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathRateLimit.php
More file actions
91 lines (75 loc) · 2.29 KB
/
RateLimit.php
File metadata and controls
91 lines (75 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Noxlogic\RateLimitBundle\Attribute;
#[\Attribute(\Attribute::IS_REPEATABLE |\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
final class RateLimit
{
/**
* @var array HTTP Methods protected by this attribute. Defaults to all method
*/
public array $methods = [];
public function __construct(
$methods = [],
/**
* @var int Number of calls per period
*/
public int $limit = -1,
/**
* @var int Number of seconds of the time period in which the calls can be made
*/
public int $period = 3600,
/**
* @var mixed Generic payload
*/
public mixed $payload = null,
/**
* @var bool|null Defines if the rate limiter blocks the request when a technical problem occurs (default).
* For example, when the Redis database which is used as a rate limit storage is down.
* If set to `false`, the request is allowed to proceed even if the rate limiter cannot determine if the rate limit has been exceeded.
* `null` means that the globally-configured default should be used
*/
public ?bool $failOpen = null
) {
// @RateLimit annotation used to support single method passed as string, keep that for retrocompatibility
if (!is_array($methods)) {
$this->methods = [$methods];
} else {
$this->methods = $methods;
}
}
public function getLimit(): int
{
return $this->limit;
}
public function setLimit(int $limit): void
{
$this->limit = $limit;
}
public function getMethods(): array
{
return $this->methods;
}
public function setMethods($methods): void
{
$this->methods = (array) $methods;
}
public function getPeriod(): int
{
return $this->period;
}
public function setPeriod(int $period): void
{
$this->period = $period;
}
public function getPayload(): mixed
{
return $this->payload;
}
public function setPayload(mixed $payload): void
{
$this->payload = $payload;
}
public function setFailOpen(bool $failOpen): void
{
$this->failOpen = $failOpen;
}
}