1 | <?php |
||
8 | class RateLimited |
||
9 | { |
||
10 | /** @var bool|\Closure */ |
||
11 | protected $enabled = true; |
||
12 | |||
13 | /** @var string */ |
||
14 | protected $connectionName = ''; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $key; |
||
18 | |||
19 | /** @var int */ |
||
20 | protected $timeSpanInSeconds = 1; |
||
21 | |||
22 | /** @var int */ |
||
23 | protected $allowedNumberOfJobsInTimeSpan = 5; |
||
24 | |||
25 | /** @var int */ |
||
26 | protected $releaseInSeconds = 5; |
||
27 | |||
28 | /** @var callable */ |
||
29 | protected $releaseAfterCallback = null; |
||
30 | |||
31 | public function __construct() |
||
37 | |||
38 | /** |
||
39 | * @param bool|\Closure $enabled |
||
40 | * |
||
41 | * @return $this |
||
42 | */ |
||
43 | public function enabled($enabled = true) |
||
49 | |||
50 | public function connectionName(string $connectionName) |
||
56 | |||
57 | public function key(string $key) |
||
63 | |||
64 | public function timespanInSeconds(int $timespanInSeconds) |
||
70 | |||
71 | public function allow(int $allowedNumberOfJobsInTimeSpan) |
||
77 | |||
78 | public function everySecond(int $timespanInSeconds = 1) |
||
84 | |||
85 | public function everySeconds(int $timespanInSeconds) |
||
89 | |||
90 | public function everyMinute(int $timespanInMinutes = 1) |
||
94 | |||
95 | public function everyMinutes(int $timespanInMinutes) |
||
99 | |||
100 | public function releaseAfterOneSecond() |
||
104 | |||
105 | public function releaseAfterSeconds(int $releaseInSeconds) |
||
111 | |||
112 | public function releaseAfterOneMinute() |
||
116 | |||
117 | public function releaseAfterMinutes(int $releaseInSeconds) |
||
121 | |||
122 | public function releaseAfter(callable $releaseAfter) |
||
128 | |||
129 | protected function releaseDuration($job) :int |
||
137 | |||
138 | public function handle($job, $next) |
||
159 | } |
||
160 |