1 | <?php |
||
8 | class RateLimiter |
||
9 | { |
||
10 | /** |
||
11 | * The cache store implementation. |
||
12 | * |
||
13 | * @var \Illuminate\Contracts\Cache\Repository |
||
14 | */ |
||
15 | protected $cache; |
||
16 | |||
17 | /** |
||
18 | * Create a new rate limiter instance. |
||
19 | * |
||
20 | * @param \Illuminate\Contracts\Cache\Repository $cache |
||
21 | * |
||
22 | * @return void |
||
|
|||
23 | */ |
||
24 | public function __construct(Cache $cache) |
||
28 | |||
29 | /** |
||
30 | * Determine if the given key has been "accessed" too many times. |
||
31 | * |
||
32 | * @param string $key |
||
33 | * @param int $maxAttempts |
||
34 | * @param float|int $decayMinutes |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1) |
||
54 | |||
55 | /** |
||
56 | * Add the lockout key to the cache. |
||
57 | * |
||
58 | * @param string $key |
||
59 | * @param int $decayMinutes |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | protected function lockout($key, $decayMinutes) |
||
69 | |||
70 | /** |
||
71 | * Increment the counter for a given key for a given decay time. |
||
72 | * |
||
73 | * @param string $key |
||
74 | * @param float|int $decayMinutes |
||
75 | * |
||
76 | * @return int |
||
77 | */ |
||
78 | public function hit($key, $decayMinutes = 1) |
||
84 | |||
85 | /** |
||
86 | * Get the number of attempts for the given key. |
||
87 | * |
||
88 | * @param string $key |
||
89 | * |
||
90 | * @return mixed |
||
91 | */ |
||
92 | public function attempts($key) |
||
96 | |||
97 | /** |
||
98 | * Reset the number of attempts for the given key. |
||
99 | * |
||
100 | * @param string $key |
||
101 | * |
||
102 | * @return mixed |
||
103 | */ |
||
104 | public function resetAttempts($key) |
||
108 | |||
109 | /** |
||
110 | * Get the number of retries left for the given key. |
||
111 | * |
||
112 | * @param string $key |
||
113 | * @param int $maxAttempts |
||
114 | * |
||
115 | * @return int |
||
116 | */ |
||
117 | public function retriesLeft($key, $maxAttempts) |
||
123 | |||
124 | /** |
||
125 | * Clear the hits and lockout for the given key. |
||
126 | * |
||
127 | * @param string $key |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | public function clear($key) |
||
137 | |||
138 | /** |
||
139 | * Get the number of seconds until the "key" is accessible again. |
||
140 | * |
||
141 | * @param string $key |
||
142 | * |
||
143 | * @return int |
||
144 | */ |
||
145 | public function availableIn($key) |
||
149 | } |
||
150 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.