1 | <?php |
||
7 | class BlackListProcessor extends AbstractProcessor |
||
8 | { |
||
9 | /** |
||
10 | * @var \Sokil\FraudDetector\Storage\StorageInterface |
||
11 | */ |
||
12 | private $storage; |
||
13 | |||
14 | private $banOnRateExceed = false; |
||
15 | |||
16 | public function init() |
||
17 | { |
||
18 | $self = $this; |
||
19 | |||
20 | // rate exceed event handler |
||
21 | $this->detector->subscribe('checkFailed:requestRate', function() use($self) { |
||
22 | // ban on rate exceed |
||
23 | if($self->isBannedOnRateExceed()) { |
||
24 | $self->ban(); |
||
25 | } |
||
26 | }); |
||
27 | } |
||
28 | |||
29 | public function isPassed() |
||
33 | |||
34 | public function ban() |
||
35 | { |
||
36 | $this->storage->store($this->detector->getKey()); |
||
37 | return $this; |
||
38 | } |
||
39 | |||
40 | public function isBanned() |
||
44 | |||
45 | public function banOnRateExceed() |
||
46 | { |
||
47 | $this->banOnRateExceed = true; |
||
48 | return $this; |
||
49 | } |
||
50 | |||
51 | public function isBannedOnRateExceed() |
||
55 | |||
56 | public function setStorage(StorageInterface $storage) |
||
57 | { |
||
58 | $this->storage = $storage; |
||
61 | } |