1 | <?php |
||
31 | abstract class AbstractScanner { |
||
32 | |||
33 | /** |
||
34 | * Scan result |
||
35 | * |
||
36 | * @var Status |
||
37 | */ |
||
38 | protected $status; |
||
39 | |||
40 | /** |
||
41 | * If scanning was done part by part |
||
42 | * the first detected infected part is stored here |
||
43 | * |
||
44 | * @var Status |
||
45 | */ |
||
46 | protected $infectedStatus; |
||
47 | |||
48 | /** |
||
49 | * @var int |
||
50 | */ |
||
51 | protected $byteCount; |
||
52 | |||
53 | /** |
||
54 | * @var resource |
||
55 | */ |
||
56 | protected $writeHandle; |
||
57 | |||
58 | /** |
||
59 | * @var AppConfig |
||
60 | */ |
||
61 | protected $appConfig; |
||
62 | |||
63 | /** |
||
64 | * @var ILogger |
||
65 | */ |
||
66 | protected $logger; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $lastChunk; |
||
72 | |||
73 | /** |
||
74 | * @var bool |
||
75 | */ |
||
76 | protected $isLogUsed = false; |
||
77 | |||
78 | /** |
||
79 | * @var bool |
||
80 | */ |
||
81 | protected $isAborted = false; |
||
82 | |||
83 | /** |
||
84 | * Close used resources |
||
85 | */ |
||
86 | abstract protected function shutdownScanner(); |
||
87 | |||
88 | /** |
||
89 | * AbstractScanner constructor. |
||
90 | * |
||
91 | * @param AppConfig $config |
||
92 | * @param ILogger $logger |
||
93 | */ |
||
94 | 12 | public function __construct(AppConfig $config, ILogger $logger) { |
|
98 | |||
99 | /** |
||
100 | * @return Status |
||
101 | */ |
||
102 | 7 | public function getStatus() { |
|
111 | |||
112 | /** |
||
113 | * Synchronous scan |
||
114 | * |
||
115 | * @param IScannable $item |
||
116 | * |
||
117 | * @return Status |
||
118 | */ |
||
119 | 2 | public function scan(IScannable $item) { |
|
129 | |||
130 | /** |
||
131 | * Async scan - new portion of data is available |
||
132 | * |
||
133 | * @param string $data |
||
134 | */ |
||
135 | 5 | public function onAsyncData($data) { |
|
138 | |||
139 | /** |
||
140 | * Async scan - resource is closed |
||
141 | * |
||
142 | * @return Status |
||
143 | */ |
||
144 | 5 | public function completeAsyncScan() { |
|
148 | |||
149 | /** |
||
150 | * Get write handle here. |
||
151 | * Do NOT open connection in constructor because this method |
||
152 | * is used for reconnection |
||
153 | */ |
||
154 | 9 | public function initScanner() { |
|
163 | |||
164 | /** |
||
165 | * @param string $chunk |
||
166 | */ |
||
167 | 7 | protected function writeChunk($chunk) { |
|
172 | |||
173 | /** |
||
174 | * @param string $data |
||
175 | */ |
||
176 | 7 | protected final function fwrite($data) { |
|
207 | |||
208 | /** |
||
209 | * @return bool |
||
210 | */ |
||
211 | 3 | protected function retry() { |
|
218 | |||
219 | /** |
||
220 | * @param string $data |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | 7 | protected function writeRaw($data) { |
|
234 | |||
235 | /** |
||
236 | * Get a resource to write data into |
||
237 | * |
||
238 | * @return resource |
||
239 | */ |
||
240 | 9 | protected function getWriteHandle() { |
|
243 | |||
244 | /** |
||
245 | * Prepare chunk (if needed) |
||
246 | * |
||
247 | * @param string $data |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | 3 | protected function prepareChunk($data) { |
|
254 | } |
||
255 |