-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathRateLimit.php
More file actions
95 lines (81 loc) · 2.24 KB
/
Copy pathRateLimit.php
File metadata and controls
95 lines (81 loc) · 2.24 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
92
93
94
95
<?php
namespace Noxlogic\RateLimitBundle\Attribute;
use Symfony\Component\HttpFoundation\Request;
#[\Attribute(\Attribute::IS_REPEATABLE |\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
final class RateLimit
{
public function __construct(
/**
* @var array<Request::METHOD_*> $methods HTTP Methods protected by this attribute. Defaults to all methods
* Passing strings is allowed for backward-compatibility but deprecated. Pass an array instead
*/
public array|string $methods = [],
/**
* @var int<-1, max> Number of calls per period
*/
public int $limit = -1,
/**
* @var positive-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
) {
// @RateLimit annotation used to support single method passed as string, keep that for retrocompatibility
if (!is_array($methods)) {
$this->methods = [$methods];
}
}
/**
* @return int<-1, max>
*/
public function getLimit(): int
{
return $this->limit;
}
/**
* @param int<-1, max> $limit
*/
public function setLimit(int $limit): void
{
$this->limit = $limit;
}
/**
* @return array<Request::METHOD_*>
*/
public function getMethods(): array
{
return $this->methods;
}
/**
* @param array<Request::METHOD_*> $methods Passing strings is allowed for backward-compatibility but deprecated. Pass an array instead
*/
public function setMethods(array|string $methods): void
{
$this->methods = (array) $methods;
}
/**
* @return positive-int
*/
public function getPeriod(): int
{
return $this->period;
}
/**
* @param positive-int $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;
}
}