1 | <?php |
||
11 | class ThrottleRequests |
||
12 | { |
||
13 | /** |
||
14 | * The rate limiter instance. |
||
15 | * |
||
16 | * @var \Autumn\Api\Classes\RateLimiter |
||
17 | */ |
||
18 | protected $limiter; |
||
19 | |||
20 | /** |
||
21 | * Create a new request throttler. |
||
22 | * |
||
23 | * @param \Autumn\Api\Classes\RateLimiter $limiter |
||
24 | * |
||
25 | * @return void |
||
|
|||
26 | */ |
||
27 | public function __construct(RateLimiter $limiter) |
||
31 | |||
32 | /** |
||
33 | * Handle an incoming request. |
||
34 | * |
||
35 | * @param \Illuminate\Http\Request $request |
||
36 | * @param \Closure $next |
||
37 | * @param int $maxAttempts |
||
38 | * @param float|int $decayMinutes |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes = 1) |
||
59 | |||
60 | /** |
||
61 | * Resolve request signature. |
||
62 | * |
||
63 | * @param \Illuminate\Http\Request $request |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function resolveRequestSignature($request) |
||
77 | |||
78 | /** |
||
79 | * Create a 'too many attempts' response. |
||
80 | * |
||
81 | * @param string $key |
||
82 | * @param int $maxAttempts |
||
83 | * |
||
84 | * @return \Symfony\Component\HttpFoundation\Response |
||
85 | */ |
||
86 | protected function buildResponse($key, $maxAttempts) |
||
98 | |||
99 | /** |
||
100 | * Add the limit header information to the given response. |
||
101 | * |
||
102 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
103 | * @param int $maxAttempts |
||
104 | * @param int $remainingAttempts |
||
105 | * @param int|null $retryAfter |
||
106 | * |
||
107 | * @return \Symfony\Component\HttpFoundation\Response |
||
108 | */ |
||
109 | protected function addHeaders(Response $response, $maxAttempts, $remainingAttempts, $retryAfter = null) |
||
125 | |||
126 | /** |
||
127 | * Calculate the number of remaining attempts. |
||
128 | * |
||
129 | * @param string $key |
||
130 | * @param int $maxAttempts |
||
131 | * @param int|null $retryAfter |
||
132 | * |
||
133 | * @return int |
||
134 | */ |
||
135 | protected function calculateRemainingAttempts($key, $maxAttempts, $retryAfter = null) |
||
143 | } |
||
144 |
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.