1 | <?php |
||
32 | abstract class ScannerBase { |
||
33 | |||
34 | /** |
||
35 | * Scan result |
||
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 | * @var Status |
||
44 | */ |
||
45 | protected $infectedStatus; |
||
46 | |||
47 | /** @var int */ |
||
48 | protected $byteCount; |
||
49 | |||
50 | /** @var resource */ |
||
51 | protected $writeHandle; |
||
52 | |||
53 | /** @var AppConfig */ |
||
54 | protected $appConfig; |
||
55 | |||
56 | /** @var ILogger */ |
||
57 | protected $logger; |
||
58 | |||
59 | /** @var StatusFactory */ |
||
60 | protected $statusFactory; |
||
61 | |||
62 | /** @var string */ |
||
63 | protected $lastChunk; |
||
64 | |||
65 | /** @var bool */ |
||
66 | protected $isLogUsed = false; |
||
67 | |||
68 | 2 | /** @var bool */ |
|
69 | 2 | protected $isAborted = false; |
|
70 | |||
71 | /** |
||
72 | 2 | * ScannerBase constructor. |
|
73 | 2 | * |
|
74 | * @param AppConfig $config |
||
75 | * @param ILogger $logger |
||
76 | * @param StatusFactory $statusFactory |
||
77 | */ |
||
78 | public function __construct(AppConfig $config, ILogger $logger, StatusFactory $statusFactory) { |
||
83 | 2 | ||
84 | 2 | /** |
|
85 | * Close used resources |
||
86 | 2 | */ |
|
87 | 2 | abstract protected function shutdownScanner(); |
|
88 | |||
89 | |||
90 | 2 | public function getStatus(){ |
|
99 | |||
100 | /** |
||
101 | * Synchronous scan |
||
102 | * @param IScannable $item |
||
103 | * @return Status |
||
104 | */ |
||
105 | public function scan(IScannable $item) { |
||
115 | 2 | ||
116 | 2 | /** |
|
117 | * Async scan - new portion of data is available |
||
118 | * @param string $data |
||
119 | 2 | */ |
|
120 | 2 | public function onAsyncData($data){ |
|
123 | |||
124 | /** |
||
125 | 2 | * Async scan - resource is closed |
|
126 | 2 | * @return Status |
|
127 | 2 | */ |
|
128 | public function completeAsyncScan(){ |
||
132 | |||
133 | /** |
||
134 | 2 | * Open write handle. etc |
|
135 | 2 | */ |
|
136 | public function initScanner(){ |
||
143 | 2 | ||
144 | 2 | /** |
|
145 | * @param string $chunk |
||
146 | 2 | */ |
|
147 | 2 | protected function writeChunk($chunk){ |
|
152 | 2 | ||
153 | /** |
||
154 | * @param string $data |
||
155 | */ |
||
156 | final protected function fwrite($data){ |
||
187 | 2 | ||
188 | /** |
||
189 | * @return bool |
||
190 | */ |
||
191 | protected function retry(){ |
||
198 | |||
199 | /** |
||
200 | * @param $data |
||
201 | * @return bool |
||
202 | */ |
||
203 | protected function writeRaw($data){ |
||
213 | |||
214 | /** |
||
215 | * Get a resource to write data into |
||
216 | * @return resource |
||
217 | */ |
||
218 | protected function getWriteHandle(){ |
||
221 | |||
222 | /** |
||
223 | * Prepare chunk (if required) |
||
224 | * @param string $data |
||
225 | * @return string |
||
226 | */ |
||
227 | protected function prepareChunk($data){ |
||
230 | } |
||
231 |
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: