1 | <?php |
||
32 | abstract class ScannerBase implements IScanner { |
||
33 | |||
34 | /** |
||
35 | * Scan result |
||
36 | * |
||
37 | * @var Status |
||
38 | */ |
||
39 | protected $status; |
||
40 | |||
41 | /** |
||
42 | * If scanning was done part by part |
||
43 | * the first detected infected part is stored here |
||
44 | * |
||
45 | * @var Status |
||
46 | */ |
||
47 | protected $infectedStatus; |
||
48 | |||
49 | /** @var int */ |
||
50 | protected $byteCount; |
||
51 | |||
52 | /** @var resource */ |
||
53 | protected $writeHandle; |
||
54 | |||
55 | /** @var AppConfig */ |
||
56 | protected $appConfig; |
||
57 | |||
58 | /** @var ILogger */ |
||
59 | protected $logger; |
||
60 | |||
61 | /** @var StatusFactory */ |
||
62 | protected $statusFactory; |
||
63 | |||
64 | /** @var string */ |
||
65 | protected $lastChunk; |
||
66 | |||
67 | /** @var bool */ |
||
68 | protected $isLogUsed = false; |
||
69 | |||
70 | /** @var bool */ |
||
71 | protected $isAborted = false; |
||
72 | |||
73 | /** |
||
74 | * ScannerBase constructor. |
||
75 | * |
||
76 | * @param AppConfig $config |
||
77 | * @param ILogger $logger |
||
78 | * @param StatusFactory $statusFactory |
||
79 | */ |
||
80 | 2 | public function __construct(AppConfig $config, ILogger $logger, StatusFactory $statusFactory) { |
|
85 | |||
86 | /** |
||
87 | * Close used resources |
||
88 | */ |
||
89 | abstract protected function shutdownScanner(); |
||
90 | |||
91 | |||
92 | public function getStatus() { |
||
101 | |||
102 | /** |
||
103 | * Synchronous scan |
||
104 | * |
||
105 | * @param Item $item |
||
106 | * @return Status |
||
107 | */ |
||
108 | public function scan(Item $item): Status { |
||
119 | |||
120 | public function scanString(string $data): Status { |
||
129 | |||
130 | /** |
||
131 | * Async scan - new portion of data is available |
||
132 | * |
||
133 | * @param string $data |
||
134 | */ |
||
135 | public function onAsyncData($data) { |
||
138 | |||
139 | /** |
||
140 | * Async scan - resource is closed |
||
141 | * |
||
142 | * @return Status |
||
143 | */ |
||
144 | public function completeAsyncScan(): Status { |
||
148 | |||
149 | /** |
||
150 | * Open write handle. etc |
||
151 | */ |
||
152 | public function initScanner() { |
||
159 | |||
160 | /** |
||
161 | * @param string $chunk |
||
162 | */ |
||
163 | protected function writeChunk($chunk) { |
||
168 | |||
169 | /** |
||
170 | * @param string $data |
||
171 | */ |
||
172 | final protected function fwrite($data) { |
||
203 | |||
204 | /** |
||
205 | * @return bool |
||
206 | */ |
||
207 | protected function retry() { |
||
214 | |||
215 | /** |
||
216 | * @param $data |
||
217 | * @return bool |
||
218 | */ |
||
219 | protected function writeRaw($data) { |
||
229 | |||
230 | /** |
||
231 | * Get a resource to write data into |
||
232 | * |
||
233 | * @return resource |
||
234 | */ |
||
235 | protected function getWriteHandle() { |
||
238 | |||
239 | /** |
||
240 | * Prepare chunk (if required) |
||
241 | * |
||
242 | * @param string $data |
||
243 | * @return string |
||
244 | */ |
||
245 | protected function prepareChunk($data) { |
||
248 | } |
||
249 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: