1 | <?php |
||
31 | abstract class AbstractScanner { |
||
32 | |||
33 | /** |
||
34 | * Scan result |
||
35 | * @var Status |
||
36 | */ |
||
37 | protected $status; |
||
38 | |||
39 | /** |
||
40 | * If scanning was done part by part |
||
41 | * the first detected infected part is stored here |
||
42 | * @var Status |
||
43 | */ |
||
44 | protected $infectedStatus; |
||
45 | |||
46 | /** @var int */ |
||
47 | protected $byteCount; |
||
48 | |||
49 | /** @var resource */ |
||
50 | protected $writeHandle; |
||
51 | |||
52 | /** @var AppConfig */ |
||
53 | protected $appConfig; |
||
54 | |||
55 | /** @var ILogger */ |
||
56 | protected $logger; |
||
57 | |||
58 | /** @var string */ |
||
59 | protected $lastChunk; |
||
60 | |||
61 | /** @var bool */ |
||
62 | protected $isLogUsed = false; |
||
63 | |||
64 | /** @var bool */ |
||
65 | protected $isAborted = false; |
||
66 | |||
67 | /** |
||
68 | * Close used resources |
||
69 | */ |
||
70 | abstract protected function shutdownScanner(); |
||
71 | |||
72 | public function __construct(AppConfig $config, ILogger $logger){ |
||
76 | |||
77 | public function getStatus(){ |
||
86 | |||
87 | /** |
||
88 | * Synchronous scan |
||
89 | * @param IScannable $item |
||
90 | * @return Status |
||
91 | */ |
||
92 | public function scan(IScannable $item) { |
||
102 | |||
103 | /** |
||
104 | * Async scan - new portion of data is available |
||
105 | * @param string $data |
||
106 | */ |
||
107 | public function onAsyncData($data){ |
||
110 | |||
111 | /** |
||
112 | * Async scan - resource is closed |
||
113 | * @return Status |
||
114 | */ |
||
115 | public function completeAsyncScan(){ |
||
119 | |||
120 | /** |
||
121 | * Open write handle. etc |
||
122 | */ |
||
123 | public function initScanner(){ |
||
130 | |||
131 | /** |
||
132 | * @param string $chunk |
||
133 | */ |
||
134 | protected function writeChunk($chunk){ |
||
139 | |||
140 | /** |
||
141 | * @param string $data |
||
142 | */ |
||
143 | protected final function fwrite($data){ |
||
174 | |||
175 | /** |
||
176 | * @return bool |
||
177 | */ |
||
178 | protected function retry(){ |
||
185 | |||
186 | /** |
||
187 | * @param $data |
||
188 | * @return bool |
||
189 | */ |
||
190 | protected function writeRaw($data){ |
||
200 | |||
201 | /** |
||
202 | * Get a resource to write data into |
||
203 | * @return resource |
||
204 | */ |
||
205 | protected function getWriteHandle(){ |
||
208 | |||
209 | /** |
||
210 | * Prepare chunk (if required) |
||
211 | * @param string $data |
||
212 | * @return string |
||
213 | */ |
||
214 | protected function prepareChunk($data){ |
||
217 | } |
||
218 |