1 | <?php |
||
34 | abstract class AbstractScanner { |
||
35 | |||
36 | /** |
||
37 | * Scan result |
||
38 | * |
||
39 | * @var Status |
||
40 | */ |
||
41 | protected $status; |
||
42 | |||
43 | /** |
||
44 | * If scanning was done part by part |
||
45 | * the first detected infected part is stored here |
||
46 | * |
||
47 | * @var Status |
||
48 | */ |
||
49 | protected $infectedStatus; |
||
50 | |||
51 | /** |
||
52 | * @var int |
||
53 | */ |
||
54 | protected $byteCount; |
||
55 | |||
56 | /** |
||
57 | * @var resource |
||
58 | */ |
||
59 | protected $writeHandle; |
||
60 | |||
61 | /** |
||
62 | * @var AppConfig |
||
63 | */ |
||
64 | protected $appConfig; |
||
65 | |||
66 | /** |
||
67 | * @var ILogger |
||
68 | */ |
||
69 | protected $logger; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $lastChunk; |
||
75 | |||
76 | /** |
||
77 | * @var bool |
||
78 | */ |
||
79 | protected $isLogUsed = false; |
||
80 | |||
81 | /** |
||
82 | * @var bool |
||
83 | */ |
||
84 | protected $isAborted = false; |
||
85 | |||
86 | /** |
||
87 | * Close used resources |
||
88 | */ |
||
89 | abstract protected function shutdownScanner(); |
||
90 | |||
91 | /** |
||
92 | * AbstractScanner constructor. |
||
93 | * |
||
94 | * @param AppConfig $config |
||
95 | * @param ILogger $logger |
||
96 | */ |
||
97 | 12 | public function __construct(AppConfig $config, ILogger $logger) { |
|
101 | |||
102 | /** |
||
103 | * @return Status |
||
104 | */ |
||
105 | 7 | public function getStatus() { |
|
114 | |||
115 | /** |
||
116 | * Synchronous scan |
||
117 | * |
||
118 | * @param IScannable $item |
||
119 | * |
||
120 | * @return Status |
||
121 | */ |
||
122 | 2 | public function scan(IScannable $item) { |
|
132 | |||
133 | /** |
||
134 | * Async scan - new portion of data is available |
||
135 | * |
||
136 | * @param string $data |
||
137 | */ |
||
138 | 5 | public function onAsyncData($data) { |
|
141 | |||
142 | /** |
||
143 | * Async scan - resource is closed |
||
144 | * |
||
145 | * @return Status |
||
146 | */ |
||
147 | 5 | public function completeAsyncScan() { |
|
151 | |||
152 | /** |
||
153 | * Get write handle here. |
||
154 | * Do NOT open connection in constructor because this method |
||
155 | * is used for reconnection |
||
156 | */ |
||
157 | 9 | public function initScanner() { |
|
166 | |||
167 | /** |
||
168 | * @param string $chunk |
||
169 | */ |
||
170 | 7 | protected function writeChunk($chunk) { |
|
175 | |||
176 | /** |
||
177 | * @param string $data |
||
178 | */ |
||
179 | 7 | protected final function fwrite($data) { |
|
210 | |||
211 | /** |
||
212 | * @return bool |
||
213 | */ |
||
214 | 3 | protected function retry() { |
|
221 | |||
222 | /** |
||
223 | * @param string $data |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | 7 | protected function writeRaw($data) { |
|
237 | |||
238 | /** |
||
239 | * Get a resource to write data into |
||
240 | * |
||
241 | * @return resource |
||
242 | */ |
||
243 | 9 | protected function getWriteHandle() { |
|
246 | |||
247 | /** |
||
248 | * Prepare chunk (if needed) |
||
249 | * |
||
250 | * @param string $data |
||
251 | * |
||
252 | * @return string |
||
253 | */ |
||
254 | 3 | protected function prepareChunk($data) { |
|
257 | } |
||
258 |